Repository navigation
ci(backport): skip a target whose backport already merged - #3616
Conversation
A second label event on a PR whose first backport already merged (for example backport-previous added shortly after backport merged) re-enters the backport job for the target that already has the change. The action's branch name for a backport is deterministic, so that leg's cherry-pick is empty rather than conflicting, and git still exits non-zero for an empty pick. Under this repository's draft_commit_conflicts setting the action reads that exit code as a conflict and tries to commit an empty working tree, which also fails and surfaces as a false backport-failed comment on the original PR for a branch the change has been on for a while. Add a guard step that looks up whether a merged pull request already exists on this target's deterministic backport branch, and skip the checkout and the backport action for that leg when one does. The guard changes nothing about the empty-cherry-pick behavior itself, which lives in the action and needs a fix there; it only keeps a known-stale re-run from reaching the action and misreporting. Extend the existing backport.yaml contract tests with the new guard's invariants: the merged (not merely closed) check on the deterministic branch name, both downstream steps gated on the guard's output, and step ordering. Signed-off-by: Aleksei Sviridkin <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe backport workflow now detects existing merged backports by deterministic branch name before checkout and creation. Contract tests cover pull request matching, merged status, guard ordering, skipped steps, and decision cases. ChangesBackport deduplication
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant BackportWorkflow
participant GitHubPRAPI
participant CheckoutStep
participant BackportAction
BackportWorkflow->>GitHubPRAPI: Query closed pull requests
GitHubPRAPI-->>BackportWorkflow: Return matching pull requests
BackportWorkflow->>BackportWorkflow: Check merged_at
alt No merged backport exists
BackportWorkflow->>CheckoutStep: Run checkout
BackportWorkflow->>BackportAction: Create backport
else Merged backport exists
BackportWorkflow-->>CheckoutStep: Skip checkout
BackportWorkflow-->>BackportAction: Skip backport creation
end
Possibly related issues
Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
What this PR does
Adds a guard step to the
backportjob in.github/workflows/backport.yamlthat looks up whether a merged pull request already exists on a target's deterministic backport branch (backport-<pr>-to-<target>) and skips the checkout and the backport-action step for that leg when one does.A second label event on a PR whose first backport already merged, for example
backport-previousadded shortly afterbackportmerged, re-enters this job for the already-delivered target, and cherry-picking the same commits onto a branch that already has them produces an empty pick, which git still reports with a non-zero exit code. Under thedraft_commit_conflictssetting this workflow already passes to the action, that non-zero exit is read as a real conflict, and the action's attempt to commit the (empty) working tree fails too, surfacing as a "Backport failed" comment on the original PR, for a branch the change has been on for a while. Relates to #3588, which has the full mechanism and a reproduction.The guard only treats a target as done when a PR on that branch actually merged, so a real retry after someone manually closed a conflicting, unmerged backport PR still runs normally; both cases are covered by the new tests.
This workflow triggers on
pull_request_target, which, likeworkflow_run, executes the workflow definition from the PR's base branch (the default branch for the PRs this fires on), not from the PR head, for the same fork-isolation reason. That means this guard only takes effect once this PR merges tomain; alabeledevent on an in-flight PR before that still runs whatever version ofbackport.yamlis currently onmain.The empty-cherry-pick-reported-as-conflict behavior itself lives in
korthout/backport-actionand stays out of scope here; issue #3588 links the upstream report.Screenshots
Not applicable, no UI change.
Downstream repositories
Release note
Summary by CodeRabbit
Bug Fixes
Tests