Skip to content

Commit 6a2e121

Browse files
authored
Cherrypicking based on branch labels added to the parent PR (#788)
1 parent 68debea commit 6a2e121

File tree

1 file changed

+38
-42
lines changed

1 file changed

+38
-42
lines changed

.github/workflows/auto_cherry_pick.yml

+38-42
Original file line numberDiff line numberDiff line change
@@ -6,69 +6,65 @@ on:
66
types:
77
- closed
88

9+
# Github & Parent PR Env vars
10+
env:
11+
assignee: ${{ github.event.pull_request.assignee.login }}
12+
title: ${{ github.event.pull_request.title }}
13+
number: ${{ github.event.number }}
14+
915
jobs:
10-
previous-branch:
11-
if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'CherryPick')
12-
name: Calculate previous branch name
13-
runs-on: ubuntu-latest
14-
outputs:
15-
previous_branch: ${{ steps.set-branch.outputs.previous_branch }}
16-
steps:
17-
- uses: actions/checkout@v3
18-
with:
19-
fetch-depth: 0
20-
- id: set-branch
21-
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
2216

17+
# Auto CherryPicking and Failure Recording
2318
auto-cherry-pick:
24-
name: Auto Cherry Pick to previous branch
2519
if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'CherryPick')
26-
needs: previous-branch
20+
name: Auto Cherry Pick to labeled branches
2721
runs-on: ubuntu-latest
28-
env:
29-
TO_BRANCH: ${{ needs.previous-branch.outputs.previous_branch }}
22+
strategy:
23+
matrix:
24+
label: ${{ github.event.pull_request.labels.*.name }}
25+
3026
steps:
27+
## Nailgun Repo Checkout
3128
- uses: actions/checkout@v3
29+
if: ${{ startsWith(matrix.label, '6.') && matrix.label != github.base_ref }}
3230
with:
3331
fetch-depth: 0
34-
- name: Cherry pick into ${{ env.TO_BRANCH }}
32+
33+
## CherryPicking and AutoMerging
34+
- name: Cherrypicking to zStream branch
35+
id: cherrypick
36+
if: ${{ startsWith(matrix.label, '6.') && matrix.label != github.base_ref }}
3537
uses: jyejare/github-cherry-pick-action@main
3638
with:
3739
token: ${{ secrets.CHERRYPICK_PAT }}
38-
branch: ${{ env.TO_BRANCH }}
40+
branch: ${{ matrix.label }}
3941
labels: |
4042
Auto_Cherry_Picked
41-
${{ env.TO_BRANCH }}
42-
assignees: "${{ github.event.pull_request.assignee.login }}"
43+
${{ matrix.label }}
44+
assignees: ${{ env.assignee }}
4345

44-
create-issue:
45-
runs-on: ubuntu-latest
46-
if: ${{ always() && contains(join(needs.*.result, ','), 'failure') }}
47-
needs: [previous-branch, auto-cherry-pick]
48-
env:
49-
TO_BRANCH: ${{ needs.previous-branch.outputs.previous_branch }}
50-
steps:
51-
- name: Create Issue on Failed Auto Cherrypick
46+
## Failure Logging to issues and GChat Group
47+
- name: Create Github issue on cherrypick failure
48+
id: create-issue
49+
if: ${{ always() && steps.cherrypick.outcome == 'failure' }}
5250
uses: dacbd/create-issue-action@main
5351
with:
5452
token: ${{ secrets.CHERRYPICK_PAT }}
55-
title: "[Failed-AutoCherryPick] - ${{ github.event.pull_request.title }}"
53+
title: "[Failed-AutoCherryPick] - ${{ env.title }}"
5654
body: |
5755
#### Auto-Cherry-Pick WorkFlow Failure:
58-
- To Branch: ${{ env.TO_BRANCH }}
56+
- To Branch: ${{ matrix.label }}
5957
- [Failed Cherrypick Action](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
60-
- [Parent Pull Request](https://github.com/${{ github.repository }}/pull/${{ github.event.number }})
61-
labels: Failed_AutoCherryPick,${{ env.TO_BRANCH }}
62-
assignees: "${{ github.event.pull_request.assignee.login }}"
63-
64-
google-chat-notification:
65-
runs-on: ubuntu-latest
66-
if: ${{ always() && contains(join(needs.*.result, ','), 'failure') }}
67-
needs: auto-cherry-pick
68-
steps:
69-
- name: Google Chat Notification - Airgun
70-
uses: Co-qn/google-chat-notification@releases/v1
58+
- [Parent Pull Request](https://github.com/${{ github.repository }}/pull/${{ env.number }})
59+
labels: Failed_AutoCherryPick,${{ matrix.label }}
60+
assignees: ${{ env.assignee }}
61+
- name: Send Google Chat notification on cherrypick failure
62+
id: google-chat-notification
63+
if: ${{ always() && steps.cherrypick.outcome == 'failure' }}
64+
uses: omkarkhatavkar/google-chat-notification@master
7165
with:
72-
name: "${{ github.event.pull_request.title }}"
66+
name: ${{ env.title }}
7367
url: ${{ secrets.GCHAT_REVIEWERS_WEBHOOK }}
68+
issue_url: ${{ steps.create-issue.outputs.html_url }}
69+
author: ${{ env.assignee }}
7470
status: failure

0 commit comments

Comments
 (0)