Skip to content

Commit

Permalink
cherry-pick PRs submitted by robots can be verified.
Browse files Browse the repository at this point in the history
Signed-off-by: tao.yang <[email protected]>
  • Loading branch information
ty-dc committed Jan 10, 2024
1 parent cb237c2 commit 97072f0
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 42 deletions.
108 changes: 66 additions & 42 deletions .github/workflows/auto-cherrypick.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ jobs:
fetch-depth: 0

- name: cherry pick
id: cherry-pick
env:
GITHUB_TOKEN: ${{ secrets.WELAN_PAT }}
JSON: ${{ toJSON(github) }}
Expand Down Expand Up @@ -78,15 +79,13 @@ jobs:
if [ -z "${PR_COMMITS}" ]; then
echo "error, failed to get pr commits"
fi
echo "number: ${PR_NUMBER}"
echo "action url: ${ACTION_URL}"
echo "PR_COMMITS: ${PR_COMMITS}"
echo "author: ${PR_AUTHOR}"
echo "url: ${PR_URL}"
echo "PR_LABEL: ${PR_LABEL}"
echo "PR_TITLE: ${PR_TITLE}"
#
#
echo "PR_TITLE=${PR_TITLE}" >> $GITHUB_ENV
echo "PR_LABEL=${PR_LABEL}" >> $GITHUB_ENV
echo "PR_URL=${PR_URL}" >> $GITHUB_ENV
echo "PR_COMMITS=${PR_COMMITS}" >> $GITHUB_ENV
echo "PR_AUTHOR=${PR_AUTHOR}" >> $GITHUB_ENV
echo "ACTION_URL=${ACTION_URL}" >> $GITHUB_ENV
echo "PR_NUMBER=${PR_NUMBER}" >> $GITHUB_ENV
echo "=============================== get dest branch from labels ======== "
WANT_MERGE_BRANCH_LIST=""
if ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.destBranch != '' }}; then
Expand All @@ -107,8 +106,9 @@ jobs:
echo "============ begin to cherry pick ============ "
FINAL_FAILURE=false
git branch
git config user.email "[email protected]"
git config user.name "robot"
git config user.email "[email protected]"
git config user.name "robot"
git config --list
gh label create ${{ env.CHERRYPICK_LABEL }} || true
for BRANCH in $WANT_MERGE_BRANCH_LIST ; do
echo "************** cherry for branch ${BRANCH}"
Expand All @@ -127,6 +127,7 @@ jobs:
continue
fi
git fetch origin ${BRANCH}:${BRANCH} || true
git pull origin ${BRANCH}:${BRANCH} || true
if ! git checkout ${BRANCH} ; then
echo "error, failed to checkout to branch $BRANCH"
gh issue create \
Expand All @@ -141,11 +142,13 @@ jobs:
continue
fi
PR_BRANCH=robot/cherrypick/pr${PR_NUMBER}/${BRANCH}
git checkout -b ${PR_BRANCH}
echo "PR_BRANCH=${PR_BRANCH}" >> $GITHUB_ENV
echo "BRANCH=${BRANCH}" >> $GITHUB_ENV
git branch --show-current
FAIL=false
UPDATE=false
ERROR_MESSAGE=""
echo "PR_COMMITS=PR_COMMITS"
for COMMIT in $PR_COMMITS; do
if ! ERROR_MESSAGE=`git cherry-pick -m 1 $COMMIT 2>&1` ; then
echo ">>>>>>>>>>>> fail when cherry pick $COMMIT to branch $BRANCH "
Expand All @@ -171,34 +174,55 @@ jobs:
echo "succeed to cherry pick $COMMIT to branch $BRANCH "
fi
done
if [ "$FAIL" == "true" ] ; then
echo "failed to cherry pick to branch $BRANCH "
FINAL_FAILURE=true
echo -e "commits $PR_COMMITS of ${PR_AUTHOR} conflict when merging to branch $BRANCH, please manually cherry pick it by yourself. \n PR <${PR_URL}> , action <${ACTION_URL}> \n\n \`\`\`\n${ERROR_MESSAGE}\n\`\`\` " | \
gh issue create \
--title "failed to cherry pick PR ${PR_NUMBER} from ${PR_AUTHOR}, to branch ${BRANCH}" \
--label "${{ env.CHERRYPICK_LABEL }}" \
--assignee "${PR_AUTHOR},${{ env.DEFAULT_REVIEWER }}" \
--body-file -
fi
if [ "$UPDATE" == "true" ] ; then
echo "succeeded to cherry pick to branch $BRANCH "
# create a pr
git commit -s --amend --no-edit
git push origin ${PR_BRANCH}:${PR_BRANCH} -f
gh pr create --title "${PR_TITLE}" \
--assignee "${PR_AUTHOR},${{ env.DEFAULT_REVIEWER }}" \
--label ${{ env.CHERRYPICK_LABEL }} \
--body "robot cherry pick PR <${PR_URL}> from ${PR_AUTHOR},to branch ${BRANCH}, action <${ACTION_URL}> , commits $PR_COMMITS " \
--base ${BRANCH}
else
echo "no changes happened for commits $PR_COMMITS, ignore create pr"
fi
echo "FAIL=${FAIL}" >> $GITHUB_ENV
echo "UPDATE=${UPDATE}" >> $GITHUB_ENV
echo "ERROR_MESSAGE<<EOF" >> $GITHUB_ENV
echo "$ERROR_MESSAGE" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
done
echo "=========== check result ============"
if [ "$FINAL_FAILURE" == "true" ] ; then
# if failed to create issue or pr, fails
echo "error, failuire happened"
else
echo "all done"
fi
- uses: crazy-max/ghaction-import-gpg@v5
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.GPG_PASSPHRASE }}
git_user_signingkey: true
git_commit_gpgsign: true

- name: commit signed for cherry-pick
run: |
git commit -s -S --amend --no-edit
- name: Create Pull Request
id: create_pr
if: ${{ env.FAIL != 'true' && env.UPDATE == 'true' }}
uses: peter-evans/[email protected]
with:
title: ${{ env.PR_TITLE }}
commit-message: ${{ env.PR_COMMITS }}
committer: ty-dc <[email protected]>
branch: ${{ env.PR_BRANCH }}
delete-branch: false
base: ${{ env.BRANCH }}
signoff: true
token: ${{ secrets.WELAN_PAT }} # ${{ secrets.GITHUB_TOKEN }} Unable to trigger bot to run CI ?
labels: ${{ env.CHERRYPICK_LABEL }}
body: "robot cherry pick PR <${{ env.PR_URL }}> from <${{ env.PR_AUTHOR }}>,to branch <${{ env.BRANCH }}>, action <${{ env.ACTION_URL }}> , commits ${{ env.PR_COMMITS }}"
reviewers: ${{ env.PR_AUTHOR }},${{ env.DEFAULT_REVIEWER }}

- name: Creat Issue
id: create_issue
if: ${{ env.FAIL == 'true' && env.UPDATE != 'true' }}
uses: dacbd/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
title: "failed to cherry pick PR ${{ env.PR_NUMBER }} from ${{ env.PR_AUTHOR }}, to branch ${{ env.BRANCH }}"
body: |
commits ${{ env.PR_COMMITS }} of ${{ env.PR_AUTHOR }} conflict when merging to branch ${{ env.BRANCH }}.
please manually cherry pick it by yourself.
PR <${{ env.PR_URL }}> , action <${{ env.ACTION_URL }}> .
error log:
<${{ env.ERROR_MESSAGE }}>
labels: ${{ env.CHERRYPICK_LABEL }}
assignees: ${{ env.PR_AUTHOR }},${{ env.DEFAULT_REVIEWER }}


8 changes: 8 additions & 0 deletions .github/workflows/call-release-chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,21 @@ jobs:
helm repo index ./charts --url ${{ env.URL }}/charts
mv ./charts/index.yaml ./index.yaml
- uses: crazy-max/ghaction-import-gpg@v5
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.GPG_PASSPHRASE }}
git_user_signingkey: true
git_commit_gpgsign: true

- name: Create Pull Request
uses: peter-evans/[email protected]
with:
title: "robot Update chart from ${{ needs.get_ref.outputs.ref }} to branch ${{ env.MERGE_BRANCH }} "
commit-message: "robot Update chart from ${{ needs.get_ref.outputs.ref }} to branch ${{ env.MERGE_BRANCH }} "
branch-suffix: timestamp
branch: robot/update_chart
committer: ty-dc <[email protected]>
delete-branch: true
base: ${{ env.MERGE_BRANCH }}
signoff: true
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/call-release-doc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,13 @@ jobs:
tar -xzvf site.tar.gz
rm -f site.tar.gz
- uses: crazy-max/ghaction-import-gpg@v5
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.GPG_PASSPHRASE }}
git_user_signingkey: true
git_commit_gpgsign: true

# Allow auto-merge on general
- name: Create Pull Request
id: create_pr
Expand All @@ -169,6 +176,7 @@ jobs:
title: "robot update website from ${{ needs.release_doc.outputs.ref }} to branch ${{ env.MERGE_BRANCH }} with tag ${{ needs.release_doc.outputs.doc_tag }}"
commit-message: "robot update website from ${{ needs.release_doc.outputs.ref }} to branch ${{ env.MERGE_BRANCH }} with tag ${{ needs.release_doc.outputs.doc_tag }}"
branch-suffix: timestamp
committer: ty-dc <[email protected]>
branch: robot/update_doc
delete-branch: true
base: ${{ env.MERGE_BRANCH }}
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/call-update-githubpages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ jobs:
helm repo index ./charts --url ${{ env.url }}/charts
mv ./charts/index.yaml ./index.yaml
- uses: crazy-max/ghaction-import-gpg@v5
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.GPG_PASSPHRASE }}
git_user_signingkey: true
git_commit_gpgsign: true

# ========= finally, create PR
# Allow auto-merge on general
- name: Create Pull Request
Expand All @@ -86,6 +93,7 @@ jobs:
commit-message: "robot update chart and website from ${{ needs.prepare_doc.outputs.ref }} to branch ${{ env.MERGE_BRANCH }} "
branch-suffix: timestamp
branch: robot/update_doc
committer: ty-dc <[email protected]>
delete-branch: true
base: ${{ env.MERGE_BRANCH }}
signoff: true
Expand Down

0 comments on commit 97072f0

Please sign in to comment.