Files
orca/config/scripts/release/versioning/release-rc-history.mjs
Neil 6bb2e13c35 refactor(tooling): organize remaining scripts by domain owners (#38407)
* refactor(tooling): group remaining scripts by concrete domain owners

* fix(tooling): preserve relocated launcher resource roots
2026-11-05 00:29:16 -08:00

91 lines
2.4 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/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)
// Suffixed RC tags must advance shared counter or next side-branch cut recomputes an existing tag and fails.
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
}
// Count suffixed RC commit subjects after tag deletion; otherwise explicit-version gate permits a release below clients’ current build.
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/versioning/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)
}
}