Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

ci: main's release-check runs about once an hour, covering every merge (AST-030 FR12) (#9181)

Cindy Zhange4283664471a
diff --git a/.github/scripts/ci-heavy-lanes.test.mjs b/.github/scripts/ci-heavy-lanes.test.mjs
index 031b6bf7c3..8a002a54d8 100644
--- a/.github/scripts/ci-heavy-lanes.test.mjs
+++ b/.github/scripts/ci-heavy-lanes.test.mjs
@@ -111,26 +111,33 @@ describe('visual, accessibility and RTL owners', () => {
});
});
-describe('the release-check on every push to main', () => {
+describe("main's release-check, about once an hour (DEC-11)", () => {
const job = heavy.jobs.dispatch;
const script = job.steps[0].with.script;
- it('runs on a push to main and may dispatch workflows', () => {
- expect(heavy.on).toEqual({push: {branches: ['main']}});
+ it('runs on a push to main and on a quarter-hourly schedule, and may dispatch workflows', () => {
+ expect(heavy.on).toEqual({
+ push: {branches: ['main']},
+ schedule: [{cron: '7,22,37,52 * * * *'}],
+ });
expect(job.permissions).toEqual({actions: 'write', contents: 'read'});
expect(job.steps[0].env.SHA).toBe('${{ github.sha }}');
});
- it('throttles in ci.yml: the dispatched checks share one group that never cancels a running check', () => {
+ it('decides one push or tick at a time, and ci.yml never cancels a running check', () => {
+ // Two pushes deciding at once could both see no recent check.
+ expect(heavy.concurrency).toEqual({
+ group: 'main-heavy-lanes-dispatch',
+ 'cancel-in-progress': false,
+ });
// GitHub keeps one running and one pending run per group, and a newer
- // dispatch replaces the pending one, so a burst of merges is checked once.
+ // dispatch replaces the pending one.
expect(ci.concurrency.group).toContain(
"(github.event_name == 'workflow_dispatch' && github.triggering_actor == 'github-actions[bot]' && 'main-heavy-lanes')",
);
expect(ci.concurrency['cancel-in-progress']).toBe(
"${{ github.event_name != 'workflow_dispatch' }}",
);
- expect(heavy.concurrency).toBeUndefined();
});
it("leaves Main's fast checks running for every push", () => {
@@ -138,13 +145,35 @@ describe('the release-check on every push to main', () => {
expect(JSON.stringify(main)).not.toContain('createWorkflowDispatch');
});
- /** Runs the step's script against a fake GitHub API with main at `tip`. */
- async function run(tip) {
- const calls = {dispatch: [], notices: []};
+ const sha = 'a'.repeat(40);
+ const NOW = Date.parse('2026-10-31T12:00:00Z');
+ const minutesAgo = minutes => new Date(NOW - minutes * 60000).toISOString();
+ const check = (minutes, overrides = {}) => ({
+ head_sha: 'c'.repeat(40),
+ created_at: minutesAgo(minutes),
+ conclusion: 'success',
+ actor: {login: 'github-actions[bot]'},
+ status: 'completed',
+ ...overrides,
+ });
+
+ /**
+ * Runs the step's script against a fake GitHub API with main at `tip` and
+ * `runs` as ci.yml's dispatched runs on main, newest first.
+ */
+ async function run({tip = sha, runs = [], eventName = 'push'} = {}) {
+ const calls = {dispatch: [], notices: [], listed: []};
const github = {
rest: {
repos: {getBranch: async () => ({data: {commit: {sha: tip}}})},
actions: {
+ listJobsForWorkflowRun: async ({run_id}) => ({
+ data: {jobs: runs.find(item => item.id === run_id)?.jobs ?? []},
+ }),
+ listWorkflowRuns: async args => {
+ calls.listed.push(args);
+ return {data: {workflow_runs: runs}};
+ },
createWorkflowDispatch: async args => calls.dispatch.push(args),
},
},
@@ -154,37 +183,140 @@ describe('the release-check on every push to main', () => {
'context',
'core',
'process',
+ 'Date',
`return (async () => {${script}})();`,
);
+ const FakeDate = {now: () => NOW, parse: Date.parse};
await body(
github,
- {repo: {owner: 'meta', repo: 'astryx'}},
+ {repo: {owner: 'meta', repo: 'astryx'}, eventName},
{notice: m => calls.notices.push(m)},
{env: {SHA: sha}},
+ FakeDate,
);
return calls;
}
- const sha = 'a'.repeat(40);
+ const dispatched = tip => [
+ {
+ owner: 'meta',
+ repo: 'astryx',
+ workflow_id: 'ci.yml',
+ ref: 'main',
+ inputs: {
+ operation: 'release-check',
+ 'release-branch': 'main',
+ 'expected-head': tip,
+ },
+ },
+ ];
- it('dispatches release-check on main for the exact pushed commit', async () => {
- expect((await run(sha)).dispatch).toEqual([
+ it("dispatches release-check for main's tip when no check started in the last 55 minutes", async () => {
+ const calls = await run({runs: [check(56), check(200)]});
+ expect(calls.dispatch).toEqual(dispatched(sha));
+ expect(calls.listed).toEqual([
{
owner: 'meta',
repo: 'astryx',
workflow_id: 'ci.yml',
- ref: 'main',
- inputs: {
- operation: 'release-check',
- 'release-branch': 'main',
- 'expected-head': sha,
- },
+ event: 'workflow_dispatch',
+ branch: 'main',
+ per_page: 30,
},
]);
});
+ it('dispatches for the first check there is', async () => {
+ expect((await run()).dispatch).toEqual(dispatched(sha));
+ });
+
+ it('leaves a push within 55 minutes of the last check to the next one', async () => {
+ const calls = await run({runs: [check(20)]});
+ expect(calls.dispatch).toEqual([]);
+ expect(calls.notices).toEqual([
+ 'A release-check started 20 minutes ago; the next one, at most 50 minutes from now, covers aaaaaaa.',
+ ]);
+ });
+
+ it('counts a waiting or running check, but not one replaced while waiting or started by a person', async () => {
+ expect(
+ (
+ await run({
+ runs: [check(10, {status: 'in_progress', conclusion: null})],
+ })
+ ).dispatch,
+ ).toEqual([]);
+ expect(
+ (
+ await run({
+ runs: [
+ check(5, {conclusion: 'cancelled'}),
+ check(10, {actor: {login: 'someone'}}),
+ ],
+ })
+ ).dispatch,
+ ).toEqual(dispatched(sha));
+ });
+
+ it('keeps counting a check a person re-runs', async () => {
+ const calls = await run({
+ runs: [check(90, {head_sha: sha, triggering_actor: {login: 'someone'}})],
+ });
+ expect(calls.dispatch).toEqual([]);
+ });
+
+ it('counts a failed check of the tip, so a red quiet main is not checked again', async () => {
+ const calls = await run({
+ runs: [
+ check(70, {
+ id: 3,
+ head_sha: sha,
+ conclusion: 'failure',
+ jobs: [
+ {name: 'release-authority', conclusion: 'success'},
+ {name: 'pr-rtl', conclusion: 'failure'},
+ ],
+ }),
+ ],
+ });
+ expect(calls.dispatch).toEqual([]);
+ });
+
+ it('checks a tip again when its run was asked to check an older commit', async () => {
+ // A merge landed between the tip read and the dispatch: the run checked
+ // out the tip, and its release-authority job refused the older commit.
+ const mismatched = minutes =>
+ check(minutes, {
+ id: 4,
+ head_sha: sha,
+ conclusion: 'failure',
+ jobs: [{name: 'release-authority', conclusion: 'failure'}],
+ });
+ expect((await run({runs: [mismatched(70)]})).dispatch).toEqual(
+ dispatched(sha),
+ );
+ // ...but it still holds the window.
+ expect((await run({runs: [mismatched(20)]})).dispatch).toEqual([]);
+ });
+
+ it('leaves every run name as it was', () => {
+ expect(ci['run-name']).toBeUndefined();
+ });
+
+ it('does not check a tip twice', async () => {
+ const calls = await run({runs: [check(90, {head_sha: sha})]});
+ expect(calls.dispatch).toEqual([]);
+ expect(calls.notices[0]).toMatch(/already has a release-check/);
+ });
+
+ it("picks up the tip a burst left unchecked on the schedule's tick", async () => {
+ const tip = 'b'.repeat(40);
+ const calls = await run({tip, eventName: 'schedule', runs: [check(60)]});
+ expect(calls.dispatch).toEqual(dispatched(tip));
+ });
+
it('leaves a commit main has moved past to the newer push', async () => {
- const calls = await run('b'.repeat(40));
+ const calls = await run({tip: 'b'.repeat(40)});
expect(calls.dispatch).toEqual([]);
expect(calls.notices[0]).toMatch(/newer push/);
});
diff --git a/.github/scripts/release-publish-workflow.test.mjs b/.github/scripts/release-publish-workflow.test.mjs
index c3c1b0ea3b..6a0103632b 100644
--- a/.github/scripts/release-publish-workflow.test.mjs
+++ b/.github/scripts/release-publish-workflow.test.mjs
@@ -337,3 +337,23 @@ describe('stable and canary publication authority', () => {
expect(parity).toContain('verify-published.mjs --version "$VERSION"');
});
});
+
+describe('stable publish requires the cut commit release-check (spec:AST-030 FR12, DEC-11)', () => {
+ it('checks the marker cut commit before anything is built or published', () => {
+ const names = stable.steps.map(candidate => candidate.name);
+ const guard = names.indexOf(
+ 'Require a passing release-check at the exact cut commit',
+ );
+ expect(guard).toBeGreaterThan(
+ names.indexOf('Validate marked release branch, tag commit, and plan'),
+ );
+ expect(guard).toBeLessThan(names.indexOf('Build all packages'));
+ expect(guard).toBeLessThan(names.indexOf('Publish changed packages'));
+ const script = stable.steps[guard].with.script;
+ expect(script).toContain('scripts/release/release-check-receipt.mjs');
+ expect(script).toContain('.release/active.json');
+ expect(script).toContain('requireReleaseCheck(');
+ expect(stable.steps[guard]['continue-on-error']).toBeUndefined();
+ expect(stable.permissions.actions).toBe('read');
+ });
+});
diff --git a/.github/scripts/rtl-scorecard-summary.mjs b/.github/scripts/rtl-scorecard-summary.mjs
index a0e961d015..1e83c431fa 100644
--- a/.github/scripts/rtl-scorecard-summary.mjs
+++ b/.github/scripts/rtl-scorecard-summary.mjs
@@ -29,7 +29,7 @@ const markdownCell = value =>
const lines = [
'## RTL semantic audit',
'',
- `Audit scope: **${scope}**. The unfiltered sweep runs for release-check on every push to main.`,
+ `Audit scope: **${scope}**. The unfiltered sweep runs for release-check on main about hourly and before a release cut.`,
'',
'Relationship-based (LTR vs RTL in the same run) — no golden screenshots. **Soft-gated** pending a stability window.',
'',
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 8f5db03721..a746f9e757 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -56,8 +56,8 @@ permissions: {}
#
# Visual, accessibility and RTL owners (pr-a11y*, visual-scout, pr-visual,
# pr-rtl*) do not run on pull request updates: they run for release-check,
-# which the Main heavy lanes workflow (main-heavy-lanes.yml) dispatches on every
-# push to main and the release gate dispatches before a cut. A pull request
+# which the Main heavy lanes workflow (main-heavy-lanes.yml) dispatches for
+# main's tip about once an hour and the release gate dispatches before a cut. A pull request
# opts into one suite with its label, `ci:run-visual`, `ci:run-a11y` or
# `ci:run-rtl`, applied by someone with write access (add the label, then push
# or close and reopen); run-labels decides. A main failure is fixed forward
@@ -2584,7 +2584,7 @@ jobs:
# eight browser pages on its four cores (the audit waits on page loads), and
# the stable pr-rtl join requires all five scope manifests plus a report from
# every applicable package.
- # The full-roster sweep is the release-check run on every push to main.
+ # The full-roster sweep is the release-check run on main about hourly.
#
# Three auto dimensions: D1 icon-mirror, D5 positional-mirror, and D6
# contextual directional decorations. Curated D2/D3/D4/D7/D8/D9 add
diff --git a/.github/workflows/main-heavy-lanes.yml b/.github/workflows/main-heavy-lanes.yml
index 83460f3e61..5ac6ec453d 100644
--- a/.github/workflows/main-heavy-lanes.yml
+++ b/.github/workflows/main-heavy-lanes.yml
@@ -1,20 +1,29 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
# Visual, accessibility and RTL run on main, not on every pull request update
-# (spec:AST-030 FR12, DEC-7): a push to main dispatches ci.yml's canonical
-# release-check on its exact commit; that run is main's visual/a11y/RTL result,
-# and a failure is fixed forward. ci.yml runs one such check at a time and keeps
-# only the newest waiting, so a burst of merges is checked once, at its newest
-# commit. Main's own fast checks (deploy.yml) still run for every push. The
-# release gate's exact-commit release-check before a cut is unchanged.
+# (spec:AST-030 FR12, DEC-7): this workflow dispatches ci.yml's canonical
+# release-check on main's tip; that run is main's visual/a11y/RTL result, and a
+# failure is fixed forward. A check covers every merge up to its commit, so
+# main is checked about once an hour (DEC-11): a push dispatches at once when
+# no check has started in the last 55 minutes, and a quarter-hourly schedule
+# picks up the tip a burst of merges left unchecked. Main's own fast checks
+# (deploy.yml) still run for every push. The release gate's exact-commit
+# release-check before a cut is dispatched separately and is unchanged.
name: Main heavy lanes
on:
push:
branches: ['main']
+ schedule:
+ - cron: '7,22,37,52 * * * *'
permissions: {}
+# One decision at a time, so two pushes cannot both see no recent check.
+concurrency:
+ group: main-heavy-lanes-dispatch
+ cancel-in-progress: false
+
jobs:
dispatch:
runs-on: ubuntu-slim
@@ -23,26 +32,64 @@ jobs:
actions: write
contents: read
steps:
- - name: Dispatch the visual, accessibility and RTL release-check for this commit
+ - name: Dispatch the visual, accessibility and RTL release-check for main's tip
uses: actions/github-script@v9
env:
SHA: ${{ github.sha }}
with:
script: |
- const sha = process.env.SHA;
- const {data} = await github.rest.repos.getBranch({...context.repo, branch: 'main'});
- if (data.commit.sha !== sha) {
- core.notice(`main moved past ${sha.slice(0, 7)}; the newer push's check covers it.`);
+ // A check starts at most once in this window; the schedule's
+ // quarter-hour cadence adds up to 15 minutes to it.
+ const WINDOW_MINUTES = 55;
+ const {data: branch} = await github.rest.repos.getBranch({...context.repo, branch: 'main'});
+ const tip = branch.commit.sha;
+ if (context.eventName === 'push' && tip !== process.env.SHA) {
+ core.notice(`main moved past ${process.env.SHA.slice(0, 7)}; the newer push's check covers it.`);
+ return;
+ }
+ // This workflow's checks: ci.yml runs dispatched on main by the
+ // workflow token, which stays a run's actor when a person re-runs
+ // it. A cancelled one was replaced while waiting and never ran.
+ const {data} = await github.rest.actions.listWorkflowRuns({
+ ...context.repo, workflow_id: 'ci.yml', event: 'workflow_dispatch', branch: 'main', per_page: 30,
+ });
+ const checks = data.workflow_runs.filter(run =>
+ run.actor?.login === 'github-actions[bot]' && run.conclusion !== 'cancelled');
+ // A run that checked out a newer commit than it was asked to check
+ // (a merge landed between the tip read and the dispatch) fails its
+ // release-authority job and is no check of that commit; it still
+ // holds the window. Any other run at the tip, failed included, is.
+ const authorityRefused = async run => {
+ const {data: {jobs}} = await github.rest.actions.listJobsForWorkflowRun({
+ ...context.repo, run_id: run.id, filter: 'latest', per_page: 100,
+ });
+ return jobs.some(job => job.name === 'release-authority' && job.conclusion === 'failure');
+ };
+ let checked = false;
+ for (const run of checks.filter(item => item.head_sha === tip)) {
+ if (run.status !== 'completed' || run.conclusion === 'success' || !(await authorityRefused(run))) {
+ checked = true;
+ break;
+ }
+ }
+ if (checked) {
+ core.notice(`main's tip ${tip.slice(0, 7)} already has a release-check.`);
+ return;
+ }
+ const latest = checks.map(run => Date.parse(run.created_at)).sort((a, b) => b - a)[0];
+ const minutes = latest == null ? Infinity : (Date.now() - latest) / 60000;
+ if (minutes < WINDOW_MINUTES) {
+ core.notice(`A release-check started ${Math.floor(minutes)} minutes ago; the next one, at most ${WINDOW_MINUTES - Math.floor(minutes) + 15} minutes from now, covers ${tip.slice(0, 7)}.`);
return;
}
// ci.yml queues these dispatches in one group (one running, one
// waiting; a newer one replaces the waiting one). A merge landing
- // between the tip check above and this call makes the run check out
- // the newer commit and fail its exact-head check; the newer push's
- // own dispatch then checks that commit.
+ // between the tip read above and this call makes the run check out
+ // the newer commit and fail its exact-head check; the next
+ // dispatch checks that commit.
await github.rest.actions.createWorkflowDispatch({
...context.repo,
workflow_id: 'ci.yml',
ref: 'main',
- inputs: {operation: 'release-check', 'release-branch': 'main', 'expected-head': sha},
+ inputs: {operation: 'release-check', 'release-branch': 'main', 'expected-head': tip},
});
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index c9d020e38f..0da917c6f2 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -90,6 +90,8 @@ jobs:
group: npm-release-stable
cancel-in-progress: false
permissions:
+ # The release-check receipt for the cut commit is a ci.yml run.
+ actions: read
contents: read
id-token: write # npm OIDC trusted publishing + provenance
steps:
@@ -123,6 +125,21 @@ jobs:
--active-branches "$ACTIVE_BRANCHES" \
| tee release-publish-receipt.json
+ # A release is built from a main commit whose canonical release-check
+ # passed (spec:AST-030 FR12, DEC-11): main is checked about hourly, so
+ # the cut commit's own check is required here, before anything builds.
+ - name: Require a passing release-check at the exact cut commit
+ uses: actions/github-script@v9
+ with:
+ retries: 3
+ script: |
+ const {pathToFileURL} = require('node:url');
+ const {requireReleaseCheck} = await import(
+ pathToFileURL(`${process.env.GITHUB_WORKSPACE}/scripts/release/release-check-receipt.mjs`).href
+ );
+ const {cutSha} = require(`${process.env.GITHUB_WORKSPACE}/.release/active.json`);
+ await requireReleaseCheck({github, core, ...context.repo, sha: cutSha});
+
- name: Upload exact release authority receipt
uses: actions/upload-artifact@v7
with:
diff --git a/docs/architecture/rtl-audit-evidence.md b/docs/architecture/rtl-audit-evidence.md
index 70124d51c8..0296ce02a7 100644
--- a/docs/architecture/rtl-audit-evidence.md
+++ b/docs/architecture/rtl-audit-evidence.md
@@ -280,8 +280,8 @@ component/composition contract; absent or invalid dimensions produce an error.
- `.github/scripts/rtl-scorecard-summary.mjs` — review-facing scorecard projection;
report completeness and exclusion visibility remain requirements, not authority
to suppress findings.
-- `.github/workflows/ci.yml` release-check — the full-roster audit on every push
- to main.
+- `.github/workflows/ci.yml` release-check — the full-roster audit on main's tip
+ about hourly and before a release cut (`spec:AST-030` DEC-11).
- `internal/eslint-plugin-astryx/no-physical-properties.js` — source-provable
physical/logical declaration constraints.
- `design:bidirectionality` — human product intent, owned separately.
diff --git a/docs/specs/AST-030/spec.md b/docs/specs/AST-030/spec.md
index e659ea2bf1..fa8497bd40 100644
--- a/docs/specs/AST-030/spec.md
+++ b/docs/specs/AST-030/spec.md
@@ -210,11 +210,14 @@ they are separately named.
later commits remain next-release input. A rewrite or divergence that removes
the checked SHA from current `main` history invalidates the receipt.
This replaces constituent-PR-only release gating, not the canonical checks'
- existing finding policies. A main-push workflow MUST dispatch that
- release-check for every push to `main`, bound to the pushed commit; the
- dispatched checks share one concurrency group that never cancels a running
- check: at most one runs and one waits, and a burst of pushes is checked once,
- at its newest commit. A commit `main` has already moved past leaves its check
+ existing finding policies. Main's heavy-lane workflow MUST dispatch that
+ release-check for `main`'s tip, bound to that commit, on a push to `main` and
+ on a quarter-hourly schedule, unless the tip already has one or one was
+ dispatched in the last 55 minutes (DEC-11). A check replaced while waiting,
+ which never ran, does not count. A check covers every merge up to its commit,
+ so every merge is covered by the next one. The dispatched checks share one
+ concurrency group that never cancels a running check: at most one runs and
+ one waits. A push whose commit `main` has already moved past leaves its check
to the newer push. That release-check run is main's result, and a failure is
fixed forward by an atomic pull request. Main's own fast
checks still run for every push. Release checks MUST NOT capture
@@ -473,6 +476,8 @@ retroactive status as release evidence.
**Reference:** `spec:AST-030/DEC-7`
**Decider:** `cixzhang`, `2026-10-28`
+**Superseded in part by:** `spec:AST-030/DEC-11` (main is checked about hourly,
+not on every push)
Run the visual, accessibility and RTL owners on every push to `main`, through
the same exact-commit `release-check` the release gate uses, and before a cut;
@@ -540,6 +545,26 @@ other writers read; it is not a required check, so a contributor waits on
Rejected: keeping a separate spec-owner workflow, which split one review state
across two workflows and two visible gates.
+### DEC-11 — Main's release-check runs about once an hour
+
+**Reference:** `spec:AST-030/DEC-11`
+**Decider:** `cixzhang`
+
+Dispatched on every push, main's release-check ran back to back through busy
+hours, about 65 full runs a day of roughly 165 runner-minutes each. A check
+covers every merge up to its commit, so one check about an hour keeps every
+merge covered with about a third of the runs. A push after a quiet hour is
+checked at once; in a burst, the next check starts at most 55 minutes after
+the last one, plus up to 15 minutes for the schedule to notice, so a failing
+merge is reported within about two hours of landing instead of about one and a
+quarter. A release cut dispatches its own exact-commit check, which this does
+not affect.
+
+Rejected: waiting for main to be quiet for some minutes (busy hours never go
+quiet, so the check would starve); holding a runner to wait out each push (it
+is billed while it waits); a daily check (main's result would lag a whole
+day).
+
## Open questions
None.
diff --git a/scripts/release/release-check-receipt.mjs b/scripts/release/release-check-receipt.mjs
new file mode 100644
index 0000000000..0c6be9129e
--- /dev/null
+++ b/scripts/release/release-check-receipt.mjs
@@ -0,0 +1,89 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/**
+ * @file The passing canonical release-check for a release's exact cut commit.
+ *
+ * @input the GitHub REST client and the cut commit from the release marker
+ * @output the passing ci.yml release-check run for that commit, or a failure
+ * that names main's last commit with one (spec:AST-030 FR12, DEC-11)
+ * @position read by release.yml's stable publish before anything is built
+ */
+
+/**
+ * Whether a ci.yml run is a passing canonical release-check: its
+ * `release-check` join succeeded. A maintenance capture, also a dispatch of
+ * ci.yml on main, has no such job.
+ */
+async function passedReleaseCheck({github, owner, repo, run}) {
+ if (run.conclusion !== 'success') return false;
+ const {
+ data: {jobs},
+ } = await github.rest.actions.listJobsForWorkflowRun({
+ owner,
+ repo,
+ run_id: run.id,
+ per_page: 100,
+ });
+ return jobs.some(
+ job => job.name === 'release-check' && job.conclusion === 'success',
+ );
+}
+
+/** ci.yml's passing dispatched runs on main, newest first. */
+async function dispatchedRuns({github, owner, repo, sha}) {
+ const {data} = await github.rest.actions.listWorkflowRuns({
+ owner,
+ repo,
+ workflow_id: 'ci.yml',
+ event: 'workflow_dispatch',
+ branch: 'main',
+ status: 'success',
+ per_page: 30,
+ ...(sha ? {head_sha: sha} : {}),
+ });
+ return data.workflow_runs.filter(run => !sha || run.head_sha === sha);
+}
+
+/** The passing release-check run for exactly `sha`, or null. */
+export async function findReleaseCheck({github, owner, repo, sha}) {
+ for (const run of await dispatchedRuns({github, owner, repo, sha})) {
+ if (await passedReleaseCheck({github, owner, repo, run})) return run;
+ }
+ return null;
+}
+
+/** The newest main commit with a passing release-check, or null. */
+export async function lastCheckedMain({github, owner, repo}) {
+ for (const run of await dispatchedRuns({github, owner, repo})) {
+ if (await passedReleaseCheck({github, owner, repo, run}))
+ return run.head_sha;
+ }
+ return null;
+}
+
+/**
+ * Fails the step unless the cut commit has a passing release-check. The
+ * failure names main's last commit with one, so the release can be re-cut
+ * there.
+ */
+export async function requireReleaseCheck({github, core, owner, repo, sha}) {
+ if (!/^[0-9a-f]{40}$/.test(sha ?? '')) {
+ core.setFailed(`The release marker's cut commit is not a full SHA: ${sha}`);
+ return null;
+ }
+ const run = await findReleaseCheck({github, owner, repo, sha});
+ if (run) {
+ core.info(`Cut commit ${sha} passed release-check in ${run.html_url}.`);
+ return run;
+ }
+ const last = await lastCheckedMain({github, owner, repo});
+ // A check can only be dispatched for main's tip, so the way forward is a
+ // cut from a commit that has one.
+ core.setFailed(
+ `No passing release-check for the cut commit ${sha}. ` +
+ (last
+ ? `Re-cut the release from main's last commit with a passing release-check, ${last}, or wait for main's next check and cut from it.`
+ : "No main commit has a passing release-check in the recent runs; wait for main's next check and cut from it."),
+ );
+ return null;
+}
diff --git a/scripts/release/release-check-receipt.test.mjs b/scripts/release/release-check-receipt.test.mjs
new file mode 100644
index 0000000000..758ce14ca5
--- /dev/null
+++ b/scripts/release/release-check-receipt.test.mjs
@@ -0,0 +1,143 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/**
+ * @file A stable release publishes only from a cut commit whose canonical
+ * release-check passed.
+ *
+ * @input a stubbed GitHub REST client with ci.yml runs and their jobs
+ * @output proofs that the receipt is the exact commit's passing release-check
+ * join, and that anything else fails naming main's last checked commit
+ * (spec:AST-030 FR12, DEC-11)
+ * @position focused suite for scripts/release/release-check-receipt.mjs
+ */
+
+import {describe, expect, it} from 'vitest';
+import {
+ findReleaseCheck,
+ requireReleaseCheck,
+} from './release-check-receipt.mjs';
+
+const CUT = 'c'.repeat(40);
+const OTHER = 'd'.repeat(40);
+
+const run = (id, headSha, conclusion = 'success') => ({
+ id,
+ head_sha: headSha,
+ conclusion,
+ html_url: `https://github.com/o/r/actions/runs/${id}`,
+});
+const join = conclusion => ({name: 'release-check', conclusion});
+
+/** `runs` are newest first; `jobs` maps a run id to its jobs. */
+function fake({runs = [], jobs = {}} = {}) {
+ const listed = [];
+ return {
+ listed,
+ github: {
+ rest: {
+ actions: {
+ listWorkflowRuns: async params => {
+ listed.push(params);
+ return {
+ data: {
+ workflow_runs: runs.filter(
+ item =>
+ (!params.head_sha || item.head_sha === params.head_sha) &&
+ item.conclusion === params.status,
+ ),
+ },
+ };
+ },
+ listJobsForWorkflowRun: async ({run_id}) => ({
+ data: {jobs: jobs[run_id] ?? []},
+ }),
+ },
+ },
+ },
+ };
+}
+
+async function require_(options, sha = CUT) {
+ const {github, listed} = fake(options);
+ const messages = {info: [], failed: []};
+ const core = {
+ info: message => messages.info.push(message),
+ setFailed: message => messages.failed.push(message),
+ };
+ const result = await requireReleaseCheck({
+ github,
+ core,
+ owner: 'o',
+ repo: 'r',
+ sha,
+ });
+ return {result, messages, listed};
+}
+
+describe('the release-check receipt for a cut commit', () => {
+ it('accepts the exact cut commit whose release-check join passed', async () => {
+ const {result, messages, listed} = await require_({
+ runs: [run(7, CUT)],
+ jobs: {7: [join('success')]},
+ });
+ expect(result.id).toBe(7);
+ expect(messages.failed).toEqual([]);
+ expect(listed[0]).toEqual({
+ owner: 'o',
+ repo: 'r',
+ workflow_id: 'ci.yml',
+ event: 'workflow_dispatch',
+ branch: 'main',
+ status: 'success',
+ per_page: 30,
+ head_sha: CUT,
+ });
+ });
+
+ it('does not take a maintenance capture of the same commit for a release-check', async () => {
+ const {github} = fake({
+ runs: [run(8, CUT), run(7, CUT)],
+ jobs: {
+ 8: [{name: 'maintenance-request', conclusion: 'success'}],
+ 7: [join('success')],
+ },
+ });
+ expect(
+ (await findReleaseCheck({github, owner: 'o', repo: 'r', sha: CUT})).id,
+ ).toBe(7);
+ });
+
+ it("fails naming main's last checked commit when the cut commit has no passing release-check", async () => {
+ const {result, messages} = await require_({
+ runs: [run(9, CUT, 'failure'), run(8, OTHER)],
+ jobs: {9: [join('failure')], 8: [join('success')]},
+ });
+ expect(result).toBeNull();
+ expect(messages.failed).toEqual([
+ `No passing release-check for the cut commit ${CUT}. Re-cut the release from main's last commit with a passing release-check, ${OTHER}, or wait for main's next check and cut from it.`,
+ ]);
+ });
+
+ it('fails when the run passed but its release-check join did not run', async () => {
+ const {result, messages} = await require_({
+ runs: [run(7, CUT)],
+ jobs: {7: [join('skipped')]},
+ });
+ expect(result).toBeNull();
+ expect(messages.failed[0]).toMatch(
+ /^No passing release-check for the cut commit/,
+ );
+ expect(messages.failed[0]).toMatch(
+ /No main commit has a passing release-check/,
+ );
+ });
+
+ it('refuses a cut commit that is not a full SHA', async () => {
+ const {result, messages, listed} = await require_({}, 'main');
+ expect(result).toBeNull();
+ expect(listed).toEqual([]);
+ expect(messages.failed).toEqual([
+ "The release marker's cut commit is not a full SHA: main",
+ ]);
+ });
+});