Skip to content

Auto Cherry-Pick: Fix race condition in workflow trigger#76083

Merged
ellatrix merged 1 commit intotrunkfrom
fix/cherry-pick-workflow-race-condition
Mar 4, 2026
Merged

Auto Cherry-Pick: Fix race condition in workflow trigger#76083
ellatrix merged 1 commit intotrunkfrom
fix/cherry-pick-workflow-race-condition

Conversation

@ellatrix
Copy link
Copy Markdown
Member

@ellatrix ellatrix commented Mar 3, 2026

Unifies some auto cherry pick workflow logic. We keep having problems when PRs are merged that the PR associated with the commit is not found yet, example: https://github.com/WordPress/gutenberg/actions/runs/22608569676/job/65506086536

Summary

  • Replace the push trigger with pull_request_target: [closed, labeled] to fix a race condition where the workflow couldn't find the PR for a merge commit
  • The push event lacks PR context, forcing an API lookup via listPullRequestsAssociatedWithCommit which has eventual consistency — it often returns no results when the workflow runs immediately after a merge (example)
  • The closed event fires on merge with the full PR payload, so the PR number, merge commit SHA, and labels are read directly from context.payload.pull_request — no API lookups needed

Test plan

  • Merge a PR with a Backport to WP X.Y Beta/RC label and verify the cherry-pick workflow runs successfully
  • Add a Backport to WP X.Y Beta/RC label to an already-merged PR and verify the cherry-pick workflow runs successfully
  • Close a PR without merging and verify the workflow is skipped (the merged == true condition)

🤖 Generated with Claude Code

…sed event

The workflow was using a `push` trigger which lacks PR context, forcing an
API lookup via `listPullRequestsAssociatedWithCommit`. This API has eventual
consistency, so it often returned no results when the workflow ran immediately
after a merge.

Replace the `push` trigger with `pull_request_target: [closed, labeled]`.
The `closed` event fires on merge with the full PR payload, eliminating the
need for any API lookups. The PR number, merge commit SHA, and labels are
all read directly from `context.payload.pull_request`.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@ellatrix ellatrix requested a review from desrosj as a code owner March 3, 2026 13:03
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 3, 2026

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: ellatrix <ellatrix@git.wordpress.org>
Co-authored-by: desrosj <desrosj@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@ellatrix ellatrix added the [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests. label Mar 3, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 3, 2026

Flaky tests detected in 783f353.
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/22624224343
📝 Reported issues:

Copy link
Copy Markdown
Member

@desrosj desrosj left a comment

Choose a reason for hiding this comment

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

Thanks @ellatrix! This seems good on review. I double checked the pr context, and it looks like the properties are all correct. But we'll have to test it on the next cherry-pick to be sure.

const pr = context.payload.pull_request;
const commit_sha = pr.merge_commit_sha;
const pr_number = pr.number;
console.log(`Commit SHA: ${commit_sha}`);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not for today because there are many instances throughout the file, but we should switch to using the GitHub @actions/core package's logging functions (core.warning(), core.error(), core.info()).

core.info() just prints output into the workflow log, but core.warning() an core.error() are surfaced in the Actions Summary UI, which can be helpful to surface information from the run that should be easier to spot. For example, using core.error() could be helpful when a conflict is encountered.

I made a note for myself to open a new ticket.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ok sounds good to do it systematically then :)

@ellatrix
Copy link
Copy Markdown
Member Author

ellatrix commented Mar 4, 2026

Thanks for double checking. Yes, we'll soon test it for newly merged PRs with the label

@ellatrix ellatrix merged commit 97b95b8 into trunk Mar 4, 2026
55 of 59 checks passed
@ellatrix ellatrix deleted the fix/cherry-pick-workflow-race-condition branch March 4, 2026 13:46
@github-actions github-actions bot added this to the Gutenberg 22.8 milestone Mar 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants