diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 11ef68ceb8..721219c288 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -16,7 +16,7 @@ jobs: publish: name: Publish runs-on: ubuntu-latest - timeout-minutes: 10 + timeout-minutes: 60 environment: npm-publish permissions: actions: read @@ -90,6 +90,8 @@ jobs: if: github.event_name == 'pull_request' env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + STABLE_RELEASE_GUARD_TIMEOUT_MINUTES: >- + ${{ vars.STABLE_RELEASE_GUARD_TIMEOUT_MINUTES || '25' }} VERSION: ${{ steps.version.outputs.version }} run: node scripts/stable-release-guard.mjs diff --git a/docs/contributing/release-channels.mdx b/docs/contributing/release-channels.mdx index 09239099b0..7ec1f79cfd 100644 --- a/docs/contributing/release-channels.mdx +++ b/docs/contributing/release-channels.mdx @@ -69,3 +69,14 @@ The publish workflow validates release channel boundaries before publishing: - Every publish job verifies that its checkout matches the immutable event SHA. This prevents an alpha-only feature from being included in a stable hotfix by accident. + +### Stable guard maintenance + +The stable guard intentionally fails closed when GitHub adds a rule type it does not recognize. +If a release reports `Unsupported effective repository rule`, inspect the effective rules for +`main` and decide whether the new rule needs an explicit check or is already enforced by the +exact update rule-suite result. Add a rule to `NON_CHECK_RULES` only when a `pass` rule suite +fully covers it; never soften the unknown-rule failure into a warning. + +After updating and reviewing the guard, rerun the original merged-PR workflow for recovery. +Do not push a stable tag, select a different SHA, or introduce a manual publish path. diff --git a/scripts/publish-workflow.test.mjs b/scripts/publish-workflow.test.mjs index 28b9b301df..ce130efd5c 100644 --- a/scripts/publish-workflow.test.mjs +++ b/scripts/publish-workflow.test.mjs @@ -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", () => { diff --git a/scripts/stable-release-guard.mjs b/scripts/stable-release-guard.mjs index 0bd36c2aa1..ead3723a92 100644 --- a/scripts/stable-release-guard.mjs +++ b/scripts/stable-release-guard.mjs @@ -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, diff --git a/scripts/stable-release-guard.test.mjs b/scripts/stable-release-guard.test.mjs index 317aa5a08a..f251006232 100644 --- a/scripts/stable-release-guard.test.mjs +++ b/scripts/stable-release-guard.test.mjs @@ -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); + } + }); +});