* fix(release-cut): gate an explicit RC against its own series semver_gt compares through strip_pre(), so the explicit-version override only ever checked the stable line: 1.4.156-rc.0 read as 1.4.156, cleared a 1.4.155 stable, and republished an RC below what clients already run. Anchor a prerelease request on highest_rc_for_base -- the same rc history the kind path uses -- so the override can only advance the series. Two sibling gaps in the same block: - version_suffix was silently dropped when version was set, because the append lives in the kind branch the override skips. - the shape regex rejected X.Y.Z-rc.N.suffix, so a suffixed RC the rc path can produce could never be re-cut explicitly. * fix(release-cut): close both ends of the rc-number range the gate compares The new explicit-rc gate compares with `[[ -le ]]`, i.e. bash machine-width integers, and the author closed only the low end. Past INTMAX bash saturates, so `version=1.4.156-rc.99999999999999999999` reads as "above the published rc.3" and the gate falls open — then the tag it cuts pins highest_rc_for_base at 1e20 for that base forever, and every later cut wraps to a lower rc the fleet never updates to. Bound the rc number to nine digits. Also reject leading zeros on an all-digit prerelease identifier. `npm version` renormalizes rc.4.01 to rc.4.1 while the tag step keeps the literal input, so the shipped package.json version and its own release tag name different releases. The explicit path's embedded identifier now goes through the same validator the kind path uses instead of only the shape regex. * fix(release-cut): stop the refusal pointing minor/major RCs at the wrong series kind=rc derives its base from bump(latest_stable, patch), so the remedy the refusal suggested only works when the requested base *is* that next patch. A 1.5.0-rc.N series exists only because this override created it, so an operator resuming a stuck 1.5.0-rc.2 was told to dispatch kind=rc, which would have cut an unrelated 1.4.156-rc.4. Spell the condition out and give the fallback that does work for a non-patch base. Also correct the mechanism in the comment I added in 698c5beeaa: bash wraps two's-complement, it does not saturate, which is why the hole is value-dependent (rc.10000000000000000000 wraps negative and failed closed, rc.99999999999999999999 wraps to 7766279631452241919 and sailed through). And name both inputs in the suffix error, which now serves version_suffix and the trailing identifier in version. * fix(release-cut): count a suffixed RC from its commit subject, not just its tag The new explicit-version gate only fails closed on a deleted tag because highest_rc_for_base also reads `release: v<base>-rc.N` subjects. That fallback did not parse the suffixed form: rcNumberFromTag accepts an optional .identifier, rcNumberFromReleaseSubject did not, so `4.perf` failed its `(\d+)(\s|$)` anchor and returned null. So deleting a v1.4.156-rc.4.perf tag dropped the series back to rc.3, and an explicit 1.4.156-rc.4 was waved through — below the rc.4.perf build perf-channel clients already run. Same under-count already made kind=rc recompute rc.4 over a deleted suffixed tag. Mirror the tag form's optional identifier. Covered by a unit assertion and a git-fixture test that both fail with this reverted. * docs(release-cut): correct four operator-facing claims in the explicit path All four are wording or consistency, no behavior change (harness: 26/26 before and after, on bash 3.2 and bash 5.2). - The trailing-identifier comment justified itself as preserving a shape that "can never be re-cut through the override", but re-cutting a suffixed rc at or below the series head is exactly what the new gate refuses. State what it actually admits: a second spelling of version=X.Y.Z-rc.N + version_suffix. - version_suffix's input description still said "rc kind only" after this PR made it apply to an explicit bare X.Y.Z-rc.N. - The suffix guard's own rc pattern was unbounded while the shape check twelve lines up is bounded to nine digits; reuse the bounded one so a later edit to either cannot silently drift. - "which recovers the existing tag" was unconditional, but kind=rc recovery is also gated on tag_matches_current_ref, so a tag cut from a ref main has moved past advances to rc.N+1 instead.
95 lines
2.7 KiB
JavaScript
95 lines
2.7 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
import { execFileSync } from 'node:child_process'
|
|
import { pathToFileURL } from 'node:url'
|
|
|
|
function gitLines(args, cwd) {
|
|
try {
|
|
return execFileSync('git', args, {
|
|
cwd,
|
|
encoding: 'utf8',
|
|
stdio: ['ignore', 'pipe', 'ignore']
|
|
})
|
|
.split(/\r?\n/)
|
|
.map((line) => line.trim())
|
|
.filter(Boolean)
|
|
} catch {
|
|
return []
|
|
}
|
|
}
|
|
|
|
export function rcNumberFromTag(base, tag) {
|
|
const prefix = `v${base}-rc.`
|
|
if (!tag.startsWith(prefix)) {
|
|
return null
|
|
}
|
|
|
|
const suffix = tag.slice(prefix.length)
|
|
// Why the optional .identifier: suffixed side-branch RCs (v1.2.3-rc.4.perf)
|
|
// must advance the shared rc counter, or the next suffixed cut recomputes
|
|
// an existing tag and the workflow refuses to re-cut over it.
|
|
const match = /^(\d+)(?:\.[0-9A-Za-z]+)?$/.exec(suffix)
|
|
return match ? Number(match[1]) : null
|
|
}
|
|
|
|
export function rcNumberFromReleaseSubject(base, subject) {
|
|
const prefix = `release: v${base}-rc.`
|
|
if (!subject.startsWith(prefix)) {
|
|
return null
|
|
}
|
|
|
|
// Why the same optional .identifier as the tag form: the commit subject is
|
|
// the only record left once a tag is deleted, and that is exactly when the
|
|
// explicit-version gate leans on this. Without it, deleting a
|
|
// v1.2.3-rc.4.perf tag drops the series back to rc.3 and an explicit
|
|
// 1.2.3-rc.4 is waved through — below what perf-channel clients already run.
|
|
const match = /^(\d+)(?:\.[0-9A-Za-z]+)?(?:\s|$)/.exec(subject.slice(prefix.length))
|
|
return match ? Number(match[1]) : null
|
|
}
|
|
|
|
export function highestRcForBase(base, { cwd = process.cwd() } = {}) {
|
|
const numbers = []
|
|
|
|
for (const tag of gitLines(['tag', '--list', `v${base}-rc.*`], cwd)) {
|
|
const rcNumber = rcNumberFromTag(base, tag)
|
|
if (rcNumber !== null) {
|
|
numbers.push(rcNumber)
|
|
}
|
|
}
|
|
|
|
const logRefs = ['HEAD', 'origin/main'].filter(
|
|
(ref) => gitLines(['rev-parse', '--verify', '--quiet', ref], cwd).length > 0
|
|
)
|
|
if (logRefs.length > 0) {
|
|
for (const subject of gitLines(['log', '--format=%s', ...logRefs], cwd)) {
|
|
const rcNumber = rcNumberFromReleaseSubject(base, subject)
|
|
if (rcNumber !== null) {
|
|
numbers.push(rcNumber)
|
|
}
|
|
}
|
|
}
|
|
|
|
return numbers.length === 0 ? null : Math.max(...numbers)
|
|
}
|
|
|
|
function main() {
|
|
const base = process.argv[2]
|
|
if (!base) {
|
|
throw new Error('Usage: node config/scripts/release-rc-history.mjs <base-version>')
|
|
}
|
|
|
|
const highest = highestRcForBase(base)
|
|
if (highest !== null) {
|
|
process.stdout.write(String(highest))
|
|
}
|
|
}
|
|
|
|
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
try {
|
|
main()
|
|
} catch (error) {
|
|
console.error(error instanceof Error ? error.message : String(error))
|
|
process.exit(1)
|
|
}
|
|
}
|