From 6a2e121356b9fbfca5fce89cde48548b46d2000d Mon Sep 17 00:00:00 2001 From: Jitendra Yejare Date: Thu, 15 Dec 2022 18:38:45 +0530 Subject: [PATCH] Cherrypicking based on branch labels added to the parent PR (#788) --- .github/workflows/auto_cherry_pick.yml | 80 ++++++++++++-------------- 1 file changed, 38 insertions(+), 42 deletions(-) diff --git a/.github/workflows/auto_cherry_pick.yml b/.github/workflows/auto_cherry_pick.yml index cdb3ecbe7..2eddfdda0 100644 --- a/.github/workflows/auto_cherry_pick.yml +++ b/.github/workflows/auto_cherry_pick.yml @@ -6,69 +6,65 @@ on: types: - closed +# Github & Parent PR Env vars +env: + assignee: ${{ github.event.pull_request.assignee.login }} + title: ${{ github.event.pull_request.title }} + number: ${{ github.event.number }} + jobs: - previous-branch: - if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'CherryPick') - name: Calculate previous branch name - runs-on: ubuntu-latest - outputs: - previous_branch: ${{ steps.set-branch.outputs.previous_branch }} - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - id: set-branch - run: echo "previous_branch=$(if [ $GITHUB_BASE_REF == 'master' ]; then echo $(git branch -rl 'origin/6.*.z' --format='%(refname:lstrip=-1)' | sort --version-sort | tail -n1); else echo '6.'$(($(echo $GITHUB_BASE_REF | cut -d. -f2) - 1))'.z'; fi)" >> $GITHUB_OUTPUT + # Auto CherryPicking and Failure Recording auto-cherry-pick: - name: Auto Cherry Pick to previous branch if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'CherryPick') - needs: previous-branch + name: Auto Cherry Pick to labeled branches runs-on: ubuntu-latest - env: - TO_BRANCH: ${{ needs.previous-branch.outputs.previous_branch }} + strategy: + matrix: + label: ${{ github.event.pull_request.labels.*.name }} + steps: + ## Nailgun Repo Checkout - uses: actions/checkout@v3 + if: ${{ startsWith(matrix.label, '6.') && matrix.label != github.base_ref }} with: fetch-depth: 0 - - name: Cherry pick into ${{ env.TO_BRANCH }} + + ## CherryPicking and AutoMerging + - name: Cherrypicking to zStream branch + id: cherrypick + if: ${{ startsWith(matrix.label, '6.') && matrix.label != github.base_ref }} uses: jyejare/github-cherry-pick-action@main with: token: ${{ secrets.CHERRYPICK_PAT }} - branch: ${{ env.TO_BRANCH }} + branch: ${{ matrix.label }} labels: | Auto_Cherry_Picked - ${{ env.TO_BRANCH }} - assignees: "${{ github.event.pull_request.assignee.login }}" + ${{ matrix.label }} + assignees: ${{ env.assignee }} - create-issue: - runs-on: ubuntu-latest - if: ${{ always() && contains(join(needs.*.result, ','), 'failure') }} - needs: [previous-branch, auto-cherry-pick] - env: - TO_BRANCH: ${{ needs.previous-branch.outputs.previous_branch }} - steps: - - name: Create Issue on Failed Auto Cherrypick + ## Failure Logging to issues and GChat Group + - name: Create Github issue on cherrypick failure + id: create-issue + if: ${{ always() && steps.cherrypick.outcome == 'failure' }} uses: dacbd/create-issue-action@main with: token: ${{ secrets.CHERRYPICK_PAT }} - title: "[Failed-AutoCherryPick] - ${{ github.event.pull_request.title }}" + title: "[Failed-AutoCherryPick] - ${{ env.title }}" body: | #### Auto-Cherry-Pick WorkFlow Failure: - - To Branch: ${{ env.TO_BRANCH }} + - To Branch: ${{ matrix.label }} - [Failed Cherrypick Action](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) - - [Parent Pull Request](https://github.com/${{ github.repository }}/pull/${{ github.event.number }}) - labels: Failed_AutoCherryPick,${{ env.TO_BRANCH }} - assignees: "${{ github.event.pull_request.assignee.login }}" - - google-chat-notification: - runs-on: ubuntu-latest - if: ${{ always() && contains(join(needs.*.result, ','), 'failure') }} - needs: auto-cherry-pick - steps: - - name: Google Chat Notification - Airgun - uses: Co-qn/google-chat-notification@releases/v1 + - [Parent Pull Request](https://github.com/${{ github.repository }}/pull/${{ env.number }}) + labels: Failed_AutoCherryPick,${{ matrix.label }} + assignees: ${{ env.assignee }} + - name: Send Google Chat notification on cherrypick failure + id: google-chat-notification + if: ${{ always() && steps.cherrypick.outcome == 'failure' }} + uses: omkarkhatavkar/google-chat-notification@master with: - name: "${{ github.event.pull_request.title }}" + name: ${{ env.title }} url: ${{ secrets.GCHAT_REVIEWERS_WEBHOOK }} + issue_url: ${{ steps.create-issue.outputs.html_url }} + author: ${{ env.assignee }} status: failure