From 2ffa92c51f5f15d685a164f04009eedba5d2bcd7 Mon Sep 17 00:00:00 2001 From: Oscar Vestlie Date: Thu, 28 Sep 2023 18:17:05 -0700 Subject: [PATCH] Comment on cherry pick PR on failure (#527) b/301453749 (cherry picked from commit 73a4d2d4c203835322b5d39467880a7cee7dc88a) --- .github/workflows/label-cherry-pick.yaml | 29 ++++++++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/.github/workflows/label-cherry-pick.yaml b/.github/workflows/label-cherry-pick.yaml index ec196429966e4..8591425e71e76 100644 --- a/.github/workflows/label-cherry-pick.yaml +++ b/.github/workflows/label-cherry-pick.yaml @@ -71,29 +71,48 @@ jobs: git config --global user.email "github@google.com" - name: Cherry pick merge commit + id: cherry-pick + continue-on-error: true run: | git fetch origin ${{ matrix.target_branch }} set +e git cherry-pick -x $MERGE_COMMIT_SHA RES=$? set -e - if [ $RES -eq 0 ]; then - echo "CREATE_PR_AS_DRAFT=false" >> $GITHUB_ENV - else - echo "CREATE_PR_AS_DRAFT=true" >> $GITHUB_ENV + if [ $RES -ne 0 ]; then git add . git cherry-pick --continue fi + exit $RES - name: Create Pull Request + id: create-pr uses: peter-evans/create-pull-request@2b011faafdcbc9ceb11414d64d0573f37c774b04 # v4.2.3 with: token: ${{ secrets.CHERRY_PICK_TOKEN }} - draft: ${{ env.CREATE_PR_AS_DRAFT }} + draft: ${{ steps.cherry-pick.outcome == 'failure' }} base: ${{ matrix.target_branch }} branch: "${{ matrix.target_branch }}-${{ github.event.pull_request.number }}" committer: GitHub Release Automation reviewers: ${{ github.event.pull_request.user.login }} title: "Cherry pick PR #${{ github.event.pull_request.number }}: ${{ github.event.pull_request.title }}" body: | +<<<<<<< HEAD "Refer to the original PR: https://github.com/${{ github.repository }}/pull/${{ github.event.pull_request.number }}" +======= + Refer to the original PR: https://github.com/${{ github.repository }}/pull/${{ github.event.pull_request.number }} + + ${{ github.event.pull_request.body }} + - name: PR Comment + if: ${{ success() && steps.cherry-pick.outcome == 'failure' }} + uses: actions/github-script@v2 + with: + github-token: ${{ secrets.CHERRY_PICK_TOKEN }} + script: | + github.issues.createComment({ + issue_number: ${{ steps.create-pr.outputs.pull-request-number }}, + owner: context.repo.owner, + repo: context.repo.repo, + body: '[!IMPORTANT]\nThe cherry-pick failed! Check out the PR branch (${{ matrix.target_branch }}-${{ github.event.pull_request.number }}) and fix the conflicts before proceeding.' + }) +>>>>>>> 73a4d2d4c20 (Comment on cherry pick PR on failure (#527))