-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
21 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,36 @@ | ||
name: Cherry Pick PR | ||
name: Cherry Pick | ||
|
||
on: | ||
issue_comment: | ||
types: [created] | ||
|
||
jobs: | ||
cherry_pick: | ||
if: ${{ github.event.comment.body.startsWith('/cherry-pick') }} | ||
cherry-pick: | ||
runs-on: ubuntu-latest | ||
if: | | ||
startsWith(github.event.comment.body, '/cherry-pick') | ||
steps: | ||
- name: Check out repository | ||
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Extract target branch from comment | ||
id: extract_branch | ||
- name: Set up Git | ||
run: | | ||
TARGET_BRANCH=$(echo '${{ github.event.comment.body }}' | cut -d' ' -f2 | tr -d '?') | ||
echo "TARGET_BRANCH=$TARGET_BRANCH" >> $GITHUB_ENV | ||
git config --global user.name "${{ github.actor }}" | ||
git config --global user.email "${{ github.actor }}@users.noreply.github.com" | ||
- name: Extract target branch | ||
id: extract | ||
run: echo "::set-output name=branch::$(echo "${{ github.event.comment.body }}" | cut -d' ' -f2)" | ||
|
||
- name: Cherry pick the commit | ||
uses: carloscastrojumo/[email protected] | ||
with: | ||
target-branch: ${{ env.TARGET_BRANCH }} | ||
pr-creator-token: ${{ secrets.GITHUB_TOKEN }} | ||
pr-title-suffix: '[Cherry-Pick]' | ||
id: cherry_pick_action | ||
|
||
- name: Output PR number | ||
run: echo "PR Number: ${{ steps.cherry_pick_action.outputs.pr-number }}" | ||
|
||
- name: Comment on PR with Result | ||
- name: Cherry-pick the PR | ||
env: | ||
GH_PAT: ${{ secrets.GH_PAT }} | ||
run: | | ||
gh pr comment ${{ github.event.issue.number }} --body "Cherry-pick to `${{ env.TARGET_BRANCH }}` was successful. PR Number: ${{ steps.cherry_pick_action.outputs.pr-number }}" | ||
TARGET_BRANCH=${{ steps.extract.outputs.branch }} | ||
git fetch origin ${{ github.event.pull_request.head.ref }} | ||
git checkout $TARGET_BRANCH | ||
git cherry-pick ${{ github.event.pull_request.head.sha }} || exit 0 | ||
- name: Push changes | ||
env: | ||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
GH_PAT: ${{ secrets.GH_PAT }} | ||
run: | | ||
git push https://${GH_PAT}@github.com/${{ github.repository }} $TARGET_BRANCH |