Fix branchLabelMapping precedence for main override in .backportrc.json#3072
Open
edsavage wants to merge 2 commits into
Open
Fix branchLabelMapping precedence for main override in .backportrc.json#3072edsavage wants to merge 2 commits into
edsavage wants to merge 2 commits into
Conversation
The backport tool applies the first matching branchLabelMapping entry. The minor-freeze automation appended the specific main override (e.g. ^v9.6.0$ -> main) after the generic ^vX.Y.Z$ -> X.Y rule, so the new main version label resolved to a non-existent MAJOR.MINOR branch and triggered a failing backport (PR elastic#3071 attempted a non-existent "9.6" branch). - update_backportrc.py: emit the main override first when rebuilding the mapping, and detect pure reorders as a change. - .backportrc.json: reorder so ^v9.6.0$ precedes the generic rule. - Add unit tests asserting the main override is emitted first. Co-authored-by: Cursor <cursoragent@cursor.com>
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
|
Pinging @elastic/ml-core (Team:ML) |
There was a problem hiding this comment.
Pull request overview
This PR fixes the ordering semantics of Backport’s branchLabelMapping so that the main-only version override (e.g. ^v9.6.0$ -> main) is evaluated before the generic ^vX.Y.Z$ -> X.Y rule, preventing backport attempts to non-existent release branches (e.g. 9.6).
Changes:
- Reorders
.backportrc.jsonso thev9.6.0 -> mainmapping precedes the generic mapping. - Updates
dev-tools/update_backportrc.pyto rebuildbranchLabelMappingwith the main override first and to detect pure reorders as changes. - Adds pytest coverage ensuring main override precedence, stale override removal, reorder detection, and idempotency.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
dev-tools/update_backportrc.py |
Rebuilds branchLabelMapping with the main override first and detects reorder-only changes. |
dev-tools/unittest/test_update_backportrc.py |
Adds regression tests for mapping order, stale override removal, reorder detection, and idempotency. |
.backportrc.json |
Reorders mapping entries so the main override is matched before the generic rule. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Exclude new_main_key from the non-main entries so a misconfigured existing mapping (e.g. ^v9.6.0$ -> "9.6") cannot overwrite the intended override via update(). Add a regression test for this scenario. Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The backport tool (
sorenlouv/backport-github-action) applies the first matchingbranchLabelMappingentry. The minor-freeze automation appended the specific main override after the generic rule, so onmainwe ended up with:The generic
^vX.Y.Z$rule matchedv9.6.0first and resolved it to9.6, a branch that does not exist. This is why merging #3071 (labeledv9.6.0) triggered a failing backport attempt to a non-existent9.6branch.Changes
.backportrc.json: reorder so^v9.6.0$->mainprecedes the generic^vX.Y.Z$->X.Yrule.dev-tools/update_backportrc.py: rebuildbranchLabelMappingwith the main-only override emitted first, and treat a pure reorder as a change so future minor freezes produce the correct order. Stale main overrides (e.g.^v9.5.0$) are still removed.dev-tools/unittest/test_update_backportrc.py: new tests asserting the main override is emitted first, stale overrides are dropped, reorders are detected as changes, and the operation is idempotent when already correct.Test plan
python3 -m pytest dev-tools/unittest/test_update_backportrc.py -qpassesupdate_backportrc.pyagainst the fixed.backportrc.jsonis idempotent (reports "already configured", no diff)v9.6.0should map tomain(or be skipped where appropriate) and not attempt a9.6backportRelated
no-backportguard added in [ML] Skip backport for minor-freeze version bump PRs #3070; this PR fixes the mapping so version-labeled PRs resolve to the correct branch.Made with Cursor