Skip to content

Commit

Permalink
Release automation: try cherry-picking automation
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Jun 21, 2024
1 parent cd965c7 commit 37d701f
Showing 1 changed file with 95 additions and 0 deletions.
95 changes: 95 additions & 0 deletions .github/workflows/cherry-pick-wp-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
name: Auto Cherry-Pick

on:
pull_request:
types: [closed, labeled]
branches:
- try/cherry-pick-automation-trunk # To be replaced with "trunk".

jobs:
cherry-pick:
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Set up Git
run: |
git config --global user.name "Gutenberg Repository Automation"
git config --global user.email "gutenberg@wordpress.org"
- name: Determine if label should trigger cherry-pick
id: label-check
run: |
LABELS=$(jq -r '.pull_request.labels[].name' "$GITHUB_EVENT_PATH")
for LABEL in $LABELS; do
if [[ "$LABEL" =~ ^Backport\ to\ WP\ ([0-9]+\.[0-9]+)\ Beta/RC$ ]]; then
VERSION=${BASH_REMATCH[1]}
echo "::set-output name=cherry_pick::true"
echo "::set-output name=version::$VERSION"
exit 0
fi
done
echo "::set-output name=cherry_pick::false"
- name: Cherry-pick the commit
id: cherry-pick
if: steps.label-check.outputs.cherry_pick == 'true'
run: |
TARGET_BRANCH="wp/${{ steps.label-check.outputs.version }}"
COMMIT_SHA=$(jq -r '.pull_request.merge_commit_sha' "$GITHUB_EVENT_PATH")
git checkout $TARGET_BRANCH
git cherry-pick $COMMIT_SHA || echo "cherry-pick-failed" > result
if [ -f result ] && grep -q "cherry-pick-failed" result; then
echo "::set-output name=conflict::true"
git cherry-pick --abort
else
git push origin $TARGET_BRANCH
echo "::set-output name=conflict::false"
fi
- name: Remove cherry-pick label
if: steps.label-check.outputs.cherry_pick == 'true' && steps.cherry-pick.outputs.conflict == 'false'
uses: actions/github-script@v6
with:
script: |
const prNumber = ${{ github.event.pull_request.number }};
const label = `Backport to WP ${{ steps.label-check.outputs.version }} Beta/RC`;
await github.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
name: label
});
- name: Comment on the PR
if: steps.label-check.outputs.cherry_pick == 'true' && steps.cherry-pick.outputs.conflict == 'false'
uses: actions/github-script@v6
with:
script: |
const prNumber = ${{ github.event.pull_request.number }};
const commitSha = '${{ steps.cherry-pick.outputs.commit_sha }}';
const targetBranch = `wp/${{ steps.label-check.outputs.version }}`;
await github.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: `I just cherry-picked this PR to the ${targetBranch} branch to get it included in the next release: ${commitSha}`
});
- name: Comment on the PR about conflict
if: steps.label-check.outputs.cherry_pick == 'true' && steps.cherry-pick.outputs.conflict == 'true'
uses: actions/github-script@v6
with:
script: |
const prNumber = ${{ github.event.pull_request.number }};
const targetBranch = `wp/${{ steps.label-check.outputs.version }}`;
await github.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: `There was a conflict while trying to cherry-pick the commit to the ${targetBranch} branch. Please resolve the conflict manually and create a PR to the ${targetBranch} branch.`
});

1 comment on commit 37d701f

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 37d701f.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/9609634591
📝 Reported issues:

Please sign in to comment.