Skip to content

Commit

Permalink
Cherrypicking based on branch labels added to the parent PR (#788)
Browse files Browse the repository at this point in the history
  • Loading branch information
jyejare authored Dec 15, 2022
1 parent 68debea commit 6a2e121
Showing 1 changed file with 38 additions and 42 deletions.
80 changes: 38 additions & 42 deletions .github/workflows/auto_cherry_pick.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 6a2e121

Please sign in to comment.