fix(release): make stable guard timeout configurable

This commit is contained in:
Miguel Ángel
2026-08-23 20:28:05 +00:00
parent ecb34c62f8
commit 4c6e53132e
5 changed files with 72 additions and 3 deletions
+17
View File
@@ -7,6 +7,11 @@ import test from "node:test";
import { parse } from "yaml";
const workflow = readFileSync(new URL("../.github/workflows/publish.yml", import.meta.url), "utf8");
const guardSource = readFileSync(new URL("./stable-release-guard.mjs", import.meta.url), "utf8");
const releaseRunbook = readFileSync(
new URL("../docs/contributing/release-channels.mdx", import.meta.url),
"utf8",
);
const config = parse(workflow);
const publish = config.jobs.publish;
const checkout = publish.steps.find((step) => step.uses?.startsWith("actions/checkout@"));
@@ -111,6 +116,18 @@ test("the stable guard precedes every irreversible release side effect", () => {
assert.equal(publish.permissions.actions, "read");
assert.equal(publish.permissions.checks, "read");
assert.equal(publish.permissions["pull-requests"], "read");
assert.equal(publish["timeout-minutes"], 60);
});
test("effective non-check rule enforcement and maintenance are explicit", () => {
assert.match(
guardSource,
/last-push.*unattributed.*signed.*enforced indirectly.*exact.*rule-suite.*pass/is,
);
assert.match(releaseRunbook, /Unsupported effective repository rule/);
assert.match(releaseRunbook, /NON_CHECK_RULES/);
assert.match(releaseRunbook, /GitHub adds.*rule type/i);
assert.match(releaseRunbook, /rerun the original merged-PR workflow/i);
});
test("the workflow invokes one shared publisher and owns no package roster", () => {
+26 -2
View File
@@ -2,7 +2,10 @@
import { execFileSync } from "node:child_process";
import { readFileSync } from "node:fs";
export const DEFAULT_TIMEOUT_MS = 8 * 60 * 1_000;
const MIN_TIMEOUT_MINUTES = 10;
const MAX_TIMEOUT_MINUTES = 40;
const DEFAULT_TIMEOUT_MINUTES = 25;
export const DEFAULT_TIMEOUT_MS = DEFAULT_TIMEOUT_MINUTES * 60 * 1_000;
export const INITIAL_BACKOFF_MS = 5_000;
export const MAX_BACKOFF_MS = 30_000;
@@ -32,6 +35,24 @@ const NON_CHECK_RULES = new Set([
"tag_name_pattern",
]);
// One parser owns syntax and both policy bounds so configuration cannot bypass either limit.
// fallow-ignore-next-line complexity
export function parseGuardTimeoutMs(value) {
if (value === undefined) return DEFAULT_TIMEOUT_MS;
if (!/^\d+$/.test(value)) {
throw new Error(
`Stable release guard timeout must be an integer from ${MIN_TIMEOUT_MINUTES} to ${MAX_TIMEOUT_MINUTES} minutes.`,
);
}
const minutes = Number(value);
if (minutes < MIN_TIMEOUT_MINUTES || minutes > MAX_TIMEOUT_MINUTES) {
throw new Error(
`Stable release guard timeout must be an integer from ${MIN_TIMEOUT_MINUTES} to ${MAX_TIMEOUT_MINUTES} minutes.`,
);
}
return minutes * 60 * 1_000;
}
function requiredString(value, label) {
if (typeof value !== "string" || value.length === 0) throw new Error(`Missing ${label}.`);
return value;
@@ -331,6 +352,9 @@ export async function runStableReleaseGuard({
`Stable release identity verified: PR #${identity.number} head=${identity.headSha} merge=${identity.mergeSha}.`,
);
log(`Valid final-head approvals: ${approvals.join(", ")}.`);
// Last-push approval, extra unattributed-change approval, and signed commits are enforced indirectly
// by requiring the exact main-update rule-suite result to be pass; check contexts and the final-head
// non-author review count are additionally revalidated explicitly here.
log(
`Effective PR rules: last-push=${rules.requireLastPushApproval === true} unattributed=${rules.requireExtraApprovalForUnattributedChanges === true} signatures=${rules.requireSignedCommits === true}; exact update rule suite passed.`,
);
@@ -448,7 +472,7 @@ async function main() {
client: createGitHubClient({ repository, token }),
now: Date.now,
sleep: (ms) => new Promise((resolve) => setTimeout(resolve, ms)),
timeoutMs: DEFAULT_TIMEOUT_MS,
timeoutMs: parseGuardTimeoutMs(process.env.STABLE_RELEASE_GUARD_TIMEOUT_MINUTES),
initialBackoffMs: INITIAL_BACKOFF_MS,
maxBackoffMs: MAX_BACKOFF_MS,
log: console.log,
+15
View File
@@ -5,6 +5,7 @@ import {
collectEffectiveApprovals,
evaluateRequiredChecks,
extractEffectiveRules,
parseGuardTimeoutMs,
runStableReleaseGuard,
} from "./stable-release-guard.mjs";
@@ -460,3 +461,17 @@ describe("stable release polling guard", () => {
assert.ok(requestBudgets.every((budget) => budget > 0 && budget <= 25));
});
});
describe("stable release guard timeout configuration", () => {
it("uses a safe 25-minute default and accepts a bounded minute override", () => {
assert.equal(parseGuardTimeoutMs(undefined), 25 * 60 * 1_000);
assert.equal(parseGuardTimeoutMs("20"), 20 * 60 * 1_000);
assert.equal(parseGuardTimeoutMs("40"), 40 * 60 * 1_000);
});
it("rejects malformed, fractional, lower, and upper out-of-bound values", () => {
for (const value of ["", "abc", "20.5", "9", "41"]) {
assert.throws(() => parseGuardTimeoutMs(value), /10.*40.*minutes/i);
}
});
});