Skip to content

Workflow file for this run

name: Cherry-Pick Commits to Master (does not push anything to master)
on:
pull_request:
branches:
- production
types: [closed]
jobs:
cherry-pick:
runs-on: ubuntu-latest
if: |
github.event.pull_request.merged == true &&
github.event.pull_request.head.ref != 'master' &&
github.event.pull_request.base.ref == 'production'
steps:
- name: Checkout master code
uses: actions/checkout@v2
with:
ref: 'master'
- name: Fetch latest production changes
run: git fetch origin production:production
- name: Cherry-pick production commit
id: cherry-pick
run: |
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
git config user.name "${GITHUB_ACTOR}"
git checkout -b cherry-pick-${{ github.run_id }}
MERGE_COMMIT_SHA=${{ github.event.pull_request.merge_commit_sha }}
echo "Merge commit SHA: $MERGE_COMMIT_SHA"
if git cherry-pick ${{ github.event.pull_request.merge_commit_sha }}; then
echo "::set-output name=result::cherry-pick-success"
echo "Cherry-pick successful. Details of the merge commit:"
git show --name-only $MERGE_COMMIT_SHA
echo "Additional repository state information:"
git status
git log --oneline -5
git branch -avv
else
echo "::set-output name=result::cherry-pick-failure"
echo "Failed to cherry-pick. Attempting to show details of the merge commit anyway:"
git show --name-only $MERGE_COMMIT_SHA || echo "Unable to show merge commit details."
fi
env:
GITHUB_TOKEN: ${{ secrets.CP_TEST_PAT }}
- name: Push Cherry-pick commit to a new branch
id: cherry-pick-push
if: steps.cherry-pick.outputs.result == 'cherry-pick-success'
run: |
echo "Preparing to push. Current branch and commit status:"
git status
git log --oneline -5
git branch -avv
echo "Pushing to origin..."
git push -u origin cherry-pick-${{ github.run_id }}
echo "::set-output name=result::cherry-pick-push-success"
env:
GITHUB_TOKEN: ${{ secrets.CP_TEST_PAT }}
- name: Create Pull Request new branch to master
if: steps.cherry-pick-push.outputs.result == 'cherry-pick-push-success'
id: create_pr
uses: peter-evans/create-pull-request@v3
with:
token: ${{ secrets.CP_TEST_PAT }}
branch: cherry-pick-${{ github.run_id }}
base: master
title: "Cherry-pick PR #${{ github.event.pull_request.number }} to master"
body: |
Automatically cherry-picked from production to master.
Original PR: #${{ github.event.pull_request.number }}
labels: |
cherry-pick-production-master-pr