Skip to content

ci(backport): skip a target whose backport already merged - #3616

Merged
Aleksei Sviridkin (lexfrei) merged 1 commit into
mainfrom
fix/backport-skip-already-merged
Aug 8, 2026
Merged

Aleksei Sviridkin (lexfrei) merged 1 commit into
mainfrom
fix/backport-skip-already-merged

Conversation

@lexfrei

@lexfrei Aleksei Sviridkin (lexfrei) commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

What this PR does

Adds a guard step to the backport job in .github/workflows/backport.yaml that 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-previous added shortly after backport merged, 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 the draft_commit_conflicts setting 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, like workflow_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 to main; a labeled event on an in-flight PR before that still runs whatever version of backport.yaml is currently on main.

The empty-cherry-pick-reported-as-conflict behavior itself lives in korthout/backport-action and stays out of scope here; issue #3588 links the upstream report.

Screenshots

Not applicable, no UI change.

Downstream repositories

Release note

ci(backport): skip re-running a backport whose target already has the merged change, instead of posting a false failure comment

Summary by CodeRabbit

  • Bug Fixes

    • Prevented duplicate backport pull requests by detecting matching merged backports before creating new ones.
    • Preserved the existing backport flow when no merged backport is found.
  • Tests

    • Added coverage for merged, closed, and empty pull request scenarios.
    • Verified that duplicate checks run before checkout and backport creation.

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]>
@github-actions github-actions Bot added area/release Issues or PRs related to release tooling (changelog, backport, release pipeline) size/L This PR changes 100-499 lines, ignoring generated files labels Aug 7, 2026
@coderabbitai

coderabbitai Bot commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: cce6e769-ae8d-479e-b686-3a449243a5c6

📥 Commits

Reviewing files that changed from the base of the PR and between 605030b and 353b8a1.

📒 Files selected for processing (2)
  • .github/workflows/backport.yaml
  • hack/release-freeze-contract.bats

📝 Walkthrough

Walkthrough

The 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.

Changes

Backport deduplication

Layer / File(s) Summary
Detect merged backports
.github/workflows/backport.yaml, hack/release-freeze-contract.bats
The workflow queries closed pull requests and detects matching merged backports through merged_at. Contract tests validate the query and matching rules.
Gate backport operations
.github/workflows/backport.yaml, hack/release-freeze-contract.bats
Checkout and backport creation run only when no merged backport exists. Tests validate guard ordering and empty, closed-unmerged, and closed-merged cases.

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
Loading

Possibly related issues

Possibly related PRs

Suggested labels: area/ci

Suggested reviewers: myasnikovdaniil

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: skipping a backport target when its backport has already merged.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/backport-skip-already-merged

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@lexfrei
Aleksei Sviridkin (lexfrei) merged commit 1b17888 into main Aug 8, 2026
16 of 17 checks passed
@lexfrei
Aleksei Sviridkin (lexfrei) deleted the fix/backport-skip-already-merged branch August 8, 2026 17:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/release Issues or PRs related to release tooling (changelog, backport, release pipeline) size/L This PR changes 100-499 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant