fix(ci): read backport_branch from the top-level key only, and honour an empty value - #2552
Open
LeSingh1 wants to merge 1 commit into
Open
fix(ci): read backport_branch from the top-level key only, and honour an empty value#2552LeSingh1 wants to merge 1 commit into
LeSingh1 wants to merge 1 commit into
Conversation
…our an empty value
`load_backport_branch` reads `backport_branch` out of ci/versions.yml with a
regex, then falls back to GITHUB_REF_NAME. Two things go wrong.
1. The value capture is `[^"'\s#]+`, requiring at least one character. An
explicitly empty `backport_branch: ""` therefore matches nothing, which is
indistinguishable from an absent key, so control falls through to the
environment:
backport_branch: "" + GITHUB_REF_NAME=12.9.x -> '12.9.x'
A maintainer who blanks the setting to disable backport gating gets it
silently re-enabled from whatever branch the workflow ran on.
2. The line is `.strip()`ed before matching, which erases indentation. The
regex is anchored at column 0 precisely so it matches a top-level key, but
after stripping any nesting level matches, and the first one in file order
wins:
cuda:
legacy:
backport_branch: "11.8.x"
backport_branch: "12.9.x" -> '11.8.x'
Match the raw line so only a column-0 key counts, and let the capture be
empty so an explicit empty value returns None without consulting the
environment.
A commented-out `# backport_branch:` was already ignored correctly; a test
now pins that too.
Contributor
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.
Problem
load_backport_branchreadsbackport_branchout ofci/versions.ymlwith a regex, then falls back toGITHUB_REF_NAME:1. An explicitly empty value is treated as an absent key. The capture is
+, so it needs at least one character.backport_branch: ""matches nothing, which is indistinguishable from the key not being there — and control falls through to the environment.2.
.strip()erases the indentation the anchor depends on. The regex is anchored at column 0 precisely so it matches the top-level key. Stripping first makes any nesting level match, and the first one in file order wins.Measured against the real
load_backport_branchonmain:ci/versions.ymlGITHUB_REF_NAMEmainbackport_branch: "12.9.x"'12.9.x'backport_branch: "12.9.x"11.8.x'12.9.x'backport_branch: ""NoneNonebackport_branch: ""12.9.x'12.9.x'Nonebackport_branch: "11.8.x"above top-level"12.9.x"'11.8.x''12.9.x'# backport_branch: "9.9.x"above"12.9.x"'12.9.x'Row 4 is the one that bites: a maintainer who blanks
backport_branchto disable backport gating gets it silently re-enabled from whatever branch the workflow happened to run on.backport_branchfeedsvalidate_backport_decision, so this decides whether a release is allowed to proceed without backport notes.Fix
backport_branch:counts. (The anchor was already there; it just could not do its job after.strip().)*, and returnNonefor an empty value without consulting the environment — an explicit blank is a decision, not a missing key.Everything already working is unchanged: a quoted value still wins over
GITHUB_REF_NAME, an absent file still falls back to it, a non-backportGITHUB_REF_NAMEis still ignored, and a commented-out key is still skipped.Tests
TestLoadBackportBranchcovered only three cases (quoted-non-empty, file-absent + env set, file-absent + envmain). Added:GITHUB_REF_NAMEset — the silent-override case;GITHUB_REF_NAME, pinning precedence;backport_branchabove the top-level one;The new tests
monkeypatch.delenv("GITHUB_REF_NAME", raising=False)where the environment must not participate; the existing tests do not, so they were order-sensitive.Verification
Executed in full (stdlib only, no GPU, no network):
ruff check/ruff format --checkclean on both files. Restore done withcpaside +git show upstream/main:<path> >; index verified clean before committing.