First and second commit #11
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
name: Github PR to Gerrit Change request | |
# yamllint disable-line rule:truthy | |
on: | |
pull_request: | |
types: [opened, synchronize, edited, reopened] | |
branches: | |
- master | |
- main | |
workflow_call: | |
inputs: | |
GERRIT_BRANCH: | |
description: "Branch that change is against" | |
required: true | |
type: string | |
GERRIT_CHANGE_ID: | |
description: "The ID for the change" | |
required: true | |
type: string | |
GERRIT_PROJECT: | |
description: "Project in Gerrit" | |
required: true | |
type: string | |
REVIEWERS_EMAIL: | |
# yamllint disable-line rule:line-length | |
description: "Comma Separated email list of reviewers" | |
required: false | |
default: "" | |
type: string | |
env: | |
TEST: "1.8.6" | |
concurrency: | |
group: ${{ github.run_id }} | |
cancel-in-progress: true | |
jobs: | |
actionlint: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Gerrit Checkout | |
# yamllint disable-line rule:line-length | |
uses: lfit/checkout-gerrit-change-action@54d751e8bd167bc91f7d665dabe33fae87aaaa63 # v0.9 | |
with: | |
gerrit-refspec: ${{ vars.GERRIT_REFSPEC }} | |
gerrit-project: ${{ vars.GERRIT_PROJECT }} | |
gerrit-url: ${{ vars.GERRIT_URL }} | |
delay: "0s" | |
submodules: "false" | |
- name: Download actionlint | |
id: get_actionlint | |
# yamllint disable-line rule:line-length | |
run: bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/main/scripts/download-actionlint.bash) | |
shell: bash | |
- name: Check workflow files | |
run: ${{ steps.get_actionlint.outputs.executable }} -color | |
shell: bash | |
gh2gerrit-push: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/setup-python@v4 | |
id: setup-python | |
with: | |
python-version: "3.11" | |
- name: Install git-review | |
run: | | |
python -m pip install --upgrade pip | |
pip install "git-review==2.3.1" | |
git review --version | |
- name: Clone Github repo with the PR | |
uses: actions/checkout@v4 | |
with: | |
ssh-user: ${{ vars.GERRIT_SSH_USER_G2G }} | |
ref: ${{ github.event.pull_request.head.sha }} | |
path: "${{ vars.GH_PROJECT }}-${{ vars.GERRIT_BRANCH }}" | |
repository: "${{ vars.ORGANIZATION }}/${{ vars.GH_PROJECT }}" | |
- name: View the last few commits in git log | |
run: | | |
set -x | |
cd "$GITHUB_WORKSPACE/${{ vars.GH_PROJECT }}-${{ vars.GERRIT_BRANCH }}" | |
git log --graph --all --decorate --pretty=oneline -n10 | |
- name: Install SSH Key | |
# if: ${{ !env.ACT }} | |
uses: shimataro/ssh-key-action@d4fffb50872869abe2d9a9098a6d9c5aa7d16be4 # v2.7.0 | |
with: | |
key: ${{ secrets.GERRIT_SSH_PRIVKEY_G2G }} | |
name: "id_rsa" | |
known_hosts: ${{ vars.GERRIT_KNOWN_HOSTS }} | |
config: | | |
Host ${{ vars.GERRIT_SERVER }} | |
User ${{ vars.GERRIT_SSH_USER_G2G }} | |
Port 29418 | |
PubkeyAcceptedKeyTypes +ssh-rsa | |
IdentityFile ~/.ssh/id_rsa | |
- name: Setup Gerrit remote | |
shell: bash | |
run: | | |
set -x | |
# TODO: Check for - or / in project path transition from GH to Gerrit | |
# GERRIT_PROJECT_PATH=${{ vars.GITHUB_PROJECT }} | |
cd "$GITHUB_WORKSPACE/${{ vars.GH_PROJECT }}-${{ vars.GERRIT_BRANCH }}" | |
git config --global gitreview.username ${{ vars.GERRIT_SSH_USER_G2G }} | |
git config --global user.name "gh2gerrit" | |
git config --global user.email "[email protected]" | |
# git remote add gerrit ssh://${{ vars.GERRIT_SSH_USER_G2G }}@${{ vars.GERRIT_SERVER }}:29418/${GH_PROJECT_PATH//\//-}.git | |
git remote add gerrit ssh://${{ vars.GERRIT_SSH_USER_G2G }}@${{ vars.GERRIT_SERVER }}:29418/${{ vars.GERRIT_PROJECT}}.git | |
git remote -v | |
# Workaround for git-review failing to copy the commit-msg hook to submodules | |
git config core.hooksPath "$(git rev-parse --show-toplevel)/.git/hooks" | |
git review -s -v | |
- name: Print the PR number | |
run: | | |
set -x | |
echo "PR Number: ${{ steps.pr.outputs.pull_request_number }}" | |
export PR_NUMBER="${{ github.event.pull_request.number || github.event.issue.number }}" | |
echo "PR_NUMBER=$PR_NUMBER" >> "$GITHUB_ENV" | |
# Set a temp PR to test with ACT | |
if [[ $PR_NUMBER == '' ]]; then | |
echo "PR_NUMBER=2" >> "$GITHUB_ENV" | |
fi | |
- name: Download the PR .patch and .diff locally | |
if: env.PR_NUMBER != '' | |
run: | | |
set -x | |
wget -q https://github.com/opendaylight/releng-sandbox/pull/${{ env.PR_NUMBER }}.patch | |
wget -q https://github.com/opendaylight/releng-sandbox/pull/${{ env.PR_NUMBER }}.diff | |
cat ${{ env.PR_NUMBER }}.patch | |
cat ${{ env.PR_NUMBER }}.diff | |
# TODO: Get number of commits in the patch file and set var in env PR_COMMIT_NUM | |
- name: Apply patch on local repo | |
if: env.PR_NUMBER != '' | |
run: | | |
set -x | |
cd $GITHUB_WORKSPACE/${{ vars.GH_PROJECT }}-${{ vars.GERRIT_BRANCH }} | |
git status | |
# git apply $GITHUB_WORKSPACE/${{ env.PR_NUMBER }}.patch | |
git am $GITHUB_WORKSPACE/${{ env.PR_NUMBER }}.patch | |
git log -n2 | |
# Create a commit-id from all the PR | |
echo "Create a commit from all the PR" | |
# Does not work | |
# git commit -s -S -v --amend --no-edit HEAD~1 | |
# Squash the commits into a single one | |
# https://stackoverflow.com/questions/5189560/how-do-i-squash-my-last-n-commits-together | |
# TODO: commits in PR should be derived | |
# Capture the last commit HEAD | |
git rev-parse HEAD > last-head-commit-id.txt | |
# Capture and check for signed-of-by and Change-Id | |
git reset --soft HEAD~2 | |
git log --format=%B --reverse HEAD..HEAD@{1} | grep -E "^(Change-Id)" > Change-ID.txt | |
git log --format=%B --reverse HEAD..HEAD@{1} | grep -E "^(Signed-of-by)" > signed-of-by.txt | |
git log --format=%B --reverse HEAD..HEAD@{1} > commit-msg.txt | |
# git merge --squash HEAD@{1} > commit-msg.txt | |
git commit -s -v --amend --no-edit -m "$(git log --format=%B --reverse HEAD..HEAD@{1})" | |
git log -n2 | |
# TODO: Get rid or merge commit in the patch | |
# TODO: process each commint one at a time in a loop: foreach or iterate | |
# https://stackoverflow.com/questions/26983700/git-run-shell-command-for-each-commit | |
- name: Submit the change to Gerrit repository | |
if: env.PR_NUMBER != '' | |
run: | | |
set -x | |
cd $GITHUB_WORKSPACE/${{ vars.GH_PROJECT }}-${{ vars.GERRIT_BRANCH }} | |
# If the reviewers email is unset/empty then use a default | |
reviewers_email=${REVIEWERS_EMAIL:-"${{ vars.GERRIT_SSH_USER_G2G}}@${{ vars.GERRIT_SERVER}}"} | |
# git review --yes -t "GH-PR-${{ env.PR_NUMBER }}" --reviewers "$reviewers_email" | |
echo "git review .... inprogress" | |
- name: Clean up resources and close the PR | |
if: env.PR_NUMBER != '' | |
run: | | |
echo "Cleaning up PR" |