Skip to content

Commit

Permalink
Cherry pick worflow: improve message after conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Jun 25, 2024
1 parent e618232 commit 6e97410
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
23 changes: 22 additions & 1 deletion .github/workflows/cherry-pick-wp-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ jobs:
git cherry-pick $COMMIT_SHA || echo "cherry-pick-failed" > result
if [ -f result ] && grep -q "cherry-pick-failed" result; then
echo "conflict=true" >> $GITHUB_ENV
echo "commit_sha=$COMMIT_SHA" >> $GITHUB_ENV
git cherry-pick --abort
else
NEW_COMMIT_SHA=$(git rev-parse HEAD)
Expand Down Expand Up @@ -122,12 +123,32 @@ jobs:
with:
script: |
const prNumber = context.issue.number;
const commitSha = process.env.commit_sha;
const targetBranch = `wp/${process.env.version}`;
console.log(`prNumber: ${prNumber}`);
console.log(`targetBranch: ${targetBranch}`);
await github.rest.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.`
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.
PRs to ${targetBranch} are similar to PRs to trunk, but you should base your PR on the ${targetBranch} branch instead of trunk.
\`\`\`
# Checkout the ${targetBranch} branch instead of trunk.
git checkout ${targetBranch}
# Create a new branch for your PR.
git checkout -b my-branch
# Cherry-pick the commit.
git cherry-pick ${commitSha}
# Resolve the conflict...
git add .
git cherry-pick --continue
# Push the branch to the repository
git push origin my-branch
# Create a PR and set the base to the ${targetBranch} branch.
# See https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/changing-the-base-branch-of-a-pull-request.
\`\`\`
`
});
21 changes: 21 additions & 0 deletions .github/workflows/cherry-pick-wp-release/label-check.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const labels = context.payload.pull_request.labels.map(
( label ) => label.name
);
console.log( `Labels: ${ labels }` );
const regex = /^Backport to WP ([0-9]+\.[0-9]+) Beta\/RC$/;
let matched = false;
for ( const label of labels ) {
const match = label.match( regex );
if ( match ) {
const version = match[ 1 ];
console.log( `Matched label: ${ label }` );
console.log( `Extracted version: ${ version }` );
core.exportVariable( 'cherry_pick', 'true' );
core.exportVariable( 'version', version );
matched = true;
break;
}
}
if ( ! matched ) {
core.exportVariable( 'cherry_pick', 'false' );
}

0 comments on commit 6e97410

Please sign in to comment.