Skip to content

Commit 6ff5b98

Browse files
ci(backport): target the newest existing release line
Determine the backport targets by enumerating real release-X.Y branches instead of deriving them from getLatestRelease. getLatestRelease returns the newest published stable. Now that cutting an rc creates release-X.Y before vX.Y.0 exists, that name lagged by a full line for the whole freeze window: a `backport` on a fix for the release being stabilised would have landed on the previous line and missed the release it was written for. The freeze window is when backports matter most, since the frozen branch is the only way in. Also drops the contiguous-minor assumption — `previous` was computed as min-1, naming a branch that does not exist whenever a minor is skipped. Sorting is numeric, so release-1.10 correctly outranks release-1.9. Outside a freeze window the result is unchanged: with release-1.0..1.5 present it still resolves to release-1.5 / release-1.4. Assisted-By: Claude <[email protected]> Signed-off-by: Myasnikov Daniil <[email protected]>
1 parent 53a7fc4 commit 6ff5b98

1 file changed

Lines changed: 42 additions & 30 deletions

File tree

‎.github/workflows/backport.yaml‎

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -53,41 +53,53 @@ jobs:
5353
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
5454
with:
5555
script: |
56-
// Get latest release
57-
let latestRelease;
58-
try {
59-
latestRelease = await github.rest.repos.getLatestRelease({
60-
owner: context.repo.owner,
61-
repo: context.repo.repo
62-
});
63-
} catch (e) {
64-
core.setFailed('No existing releases found; cannot determine backport target.');
56+
// Enumerate the real release-X.Y branches rather than deriving them
57+
// from the latest published release.
58+
//
59+
// Since cutting an rc freezes the line (cut-prerelease.yaml),
60+
// release-X.Y is created when the first vX.Y.0-rc.N is cut — before
61+
// vX.Y.0 is ever published. getLatestRelease returns the newest
62+
// published STABLE, so throughout the freeze window it still named
63+
// the previous line: a `backport` on a fix for the release being
64+
// stabilised would have landed on release-X.(Y-1) and missed the
65+
// release it was written for. That window is exactly when backports
66+
// matter most, since the frozen branch is the only way in.
67+
//
68+
// Enumerating branches also drops the contiguous-minor assumption:
69+
// `previous` used to be computed as min-1, which named a
70+
// non-existent branch whenever a minor was skipped.
71+
const branches = await github.paginate(github.rest.repos.listBranches, {
72+
owner: context.repo.owner,
73+
repo: context.repo.repo,
74+
per_page: 100
75+
});
76+
77+
const lines = branches
78+
.map(b => /^release-(\d+)\.(\d+)$/.exec(b.name))
79+
.filter(Boolean)
80+
.map(m => ({ name: m[0], maj: Number(m[1]), min: Number(m[2]) }))
81+
.sort((a, b) => (b.maj - a.maj) || (b.min - a.min));
82+
83+
if (lines.length === 0) {
84+
core.setFailed('No release-X.Y branches found; cannot determine backport target.');
6585
return;
6686
}
67-
68-
const [maj, min] = latestRelease.data.tag_name.replace(/^v/, '').split('.');
69-
const currentBranch = `release-${maj}.${min}`;
70-
const prevMin = parseInt(min) - 1;
71-
const previousBranch = prevMin >= 0 ? `release-${maj}.${prevMin}` : '';
72-
87+
88+
const currentBranch = lines[0].name;
89+
const previousBranch = lines.length > 1 ? lines[1].name : '';
90+
7391
core.setOutput('current_branch', currentBranch);
7492
core.setOutput('previous_branch', previousBranch);
75-
93+
94+
console.log(`Release lines found: ${lines.map(l => l.name).join(', ')}`);
7695
console.log(`Current branch: ${currentBranch}, Previous branch: ${previousBranch || 'N/A'}`);
77-
78-
// Verify previous branch exists if we need it
79-
if (previousBranch && '${{ steps.labels.outputs.backport_previous }}' === 'true') {
80-
try {
81-
await github.rest.repos.getBranch({
82-
owner: context.repo.owner,
83-
repo: context.repo.repo,
84-
branch: previousBranch
85-
});
86-
console.log(`Previous branch ${previousBranch} exists`);
87-
} catch (e) {
88-
core.setFailed(`Previous branch ${previousBranch} does not exist.`);
89-
return;
90-
}
96+
97+
// Both targets come from the enumeration above, so they exist by
98+
// construction — no getBranch probe needed. What CAN still fail is
99+
// asking for a previous line when only one exists.
100+
if (!previousBranch && '${{ steps.labels.outputs.backport_previous }}' === 'true') {
101+
core.setFailed('backport-previous requested, but only one release line exists.');
102+
return;
91103
}
92104
93105
backport:

0 commit comments

Comments
 (0)