An open source design system that's fully customizable and agent ready
TypeScript
fix(ci): gate releases on exact main checks (#7105)
Cindy Zhangdaa1c04f3ccb
diff --git a/.github/scripts/release-check-workflow.test.mjs b/.github/scripts/release-check-workflow.test.mjsindex 7b1031d1d9..a8f582c59a 100644--- a/.github/scripts/release-check-workflow.test.mjs+++ b/.github/scripts/release-check-workflow.test.mjs@@ -1,7 +1,7 @@// Copyright (c) Meta Platforms, Inc. and affiliates./**- * @file Exact-release-branch dispatch contracts.+ * @file Exact-main and release-branch dispatch contracts.* @input CI workflow and independent event, dependency, scope, and API fixtures* @output Fail-closed release routing and unchanged maintenance/PR assertions* @position Node contracts for AST-030 FR12 and DEC-5@@ -59,6 +59,7 @@ function runs({event = 'workflow_dispatch',operation = 'release-check',+ branch = releaseBranch,needs = dependencies(job),cancelled = false,} = {},@@ -81,7 +82,7 @@ function runs(`return Boolean(${expression});`,)({event_name: event},- {operation},+ {operation, 'release-branch': branch},needs,() => true,() => cancelled,@@ -101,9 +102,12 @@ const planDigest = 'b'.repeat(64);async function githubScript(script,{- ref = `refs/heads/${releaseBranch}`,+ branch = releaseBranch,+ ref = `refs/heads/${branch}`,remoteSha = sha,expectedHead = sha,+ checkedHead = expectedHead,+ plan = planDigest,needs,apiFails = false,} = {},@@ -130,7 +134,7 @@ async function githubScript(rest: {git: {async getRef(request) {- expect(request.ref).toBe(`heads/${releaseBranch}`);+ expect(request.ref).toBe(`heads/${branch}`);if (apiFails) throw new Error('API unavailable');return {data: {object: {sha: remoteSha}}};},@@ -141,9 +145,10 @@ async function githubScript({env: {RELEASE_NEEDS: JSON.stringify(needs),- RELEASE_BRANCH: releaseBranch,+ RELEASE_BRANCH: branch,EXPECTED_HEAD: expectedHead,- PLAN_DIGEST: planDigest,+ CHECKED_HEAD: checkedHead,+ PLAN_DIGEST: plan,},},);@@ -232,17 +237,88 @@ describe('explicit release routing', () => {});});-describe('exact release branch completion', () => {+describe('exact main pre-cut authority', () => {+ const authority = step(+ 'check-scope',+ 'Validate exact main pre-cut authority',+ );++ it('runs only for an exact-main release-check request', () => {+ expect(runs(authority, {branch: 'main'})).toBe(true);+ expect(runs(authority)).toBe(false);+ expect(runs(authority, {branch: 'main', operation: 'capture'})).toBe(false);+ expect(jobs['check-scope'].outputs.release_head).toContain(+ 'steps.main-authority.outputs.head',+ );+ });++ it('binds the run and remote main to the requested SHA', () => {+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-main-check-'));+ const output = path.join(dir, 'output');+ try {+ const result = shell(+ authority.run,+ {+ EXPECTED_HEAD: sha,+ GITHUB_REF: 'refs/heads/main',+ GITHUB_SHA: sha,+ GITHUB_OUTPUT: output,+ },+ `git() { printf '%s\\n' '${sha}\trefs/heads/main'; }`,+ );+ expect(result.status, result.stderr).toBe(0);+ expect(fs.readFileSync(output, 'utf8')).toBe(+ `branch=main\nhead=${sha}\n`,+ );+ } finally {+ fs.rmSync(dir, {recursive: true, force: true});+ }+ });++ it.each([+ ['wrong ref', {GITHUB_REF: 'refs/heads/candidate', GITHUB_SHA: sha}],+ [+ 'wrong checkout',+ {GITHUB_REF: 'refs/heads/main', GITHUB_SHA: 'b'.repeat(40)},+ ],+ ])('rejects %s', (_name, values) => {+ const result = shell(+ authority.run,+ {...values, EXPECTED_HEAD: sha, GITHUB_OUTPUT: '/dev/null'},+ `git() { printf '%s\\n' '${sha}\trefs/heads/main'; }`,+ );+ expect(result.status).not.toBe(0);+ });++ it('rejects remote main drift', () => {+ const result = shell(+ authority.run,+ {+ EXPECTED_HEAD: sha,+ GITHUB_REF: 'refs/heads/main',+ GITHUB_SHA: sha,+ GITHUB_OUTPUT: '/dev/null',+ },+ `git() { printf '%s\\n' '${'b'.repeat(40)}\trefs/heads/main'; }`,+ );+ expect(result.status).not.toBe(0);+ expect(result.stdout).toContain('Main moved before checks began');+ });+});++describe('exact main and release branch completion', () => {const join = step('release-check',- 'Require complete exact-head release branch checks',+ 'Require complete exact-head canonical checks',).with.script;const complete = Object.fromEntries(jobs['release-check'].needs.map(name => [name, {result: 'success'}]),);- it('accepts only complete exact-branch evidence', async () => {- await expect(githubScript(join, {needs: complete})).resolves.toBeUndefined();+ it('accepts complete exact release-branch evidence', async () => {+ await expect(+ githubScript(join, {needs: complete}),+ ).resolves.toBeUndefined();expect(jobs['release-check'].needs).toEqual(['check-scope','check-components',@@ -253,12 +329,29 @@ describe('exact release branch completion', () => {]);});+ it('accepts complete exact-main evidence before a cut', async () => {+ await expect(+ githubScript(join, {branch: 'main', plan: '', needs: complete}),+ ).resolves.toBeUndefined();+ });++ it('requires the successful main authority step to bind the expected head', async () => {+ await expect(+ githubScript(join, {+ branch: 'main',+ checkedHead: 'b'.repeat(40),+ plan: '',+ needs: complete,+ }),+ ).rejects.toThrow('Main authority check did not bind the expected head');+ });+it.each(['refs/heads/main', 'refs/tags/v0.6.5', ''])(- 'rejects ref %s',+ 'rejects a release-branch request from ref %s',async ref => {- await expect(- githubScript(join, {ref, needs: complete}),- ).rejects.toThrow('marked release branch');+ await expect(githubScript(join, {ref, needs: complete})).rejects.toThrow(+ 'requested branch',+ );},);@@ -269,15 +362,31 @@ describe('exact release branch completion', () => {});it.each(['b'.repeat(40), undefined])(- 'rejects release-branch drift or a missing remote SHA %s',+ 'rejects branch drift or a missing remote SHA %s',async remoteSha => {await expect(githubScript(join, {remoteSha: remoteSha ?? '', needs: complete}),- ).rejects.toThrow('Release branch moved');+ ).rejects.toThrow('moved during checks');},);- it('fails closed when the release branch cannot be read', async () => {+ it('rejects an unmarked post-bump branch', async () => {+ await expect(+ githubScript(join, {+ branch: 'candidate',+ ref: 'refs/heads/candidate',+ needs: complete,+ }),+ ).rejects.toThrow('marked release branch');+ });++ it('requires a plan digest after the bump', async () => {+ await expect(+ githubScript(join, {plan: '', needs: complete}),+ ).rejects.toThrow('active plan digest');+ });++ it('fails closed when the requested branch cannot be read', async () => {await expect(githubScript(join, {apiFails: true, needs: complete}),).rejects.toThrow('API unavailable');diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex 73319de613..0dc939de66 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -16,25 +16,25 @@ on:workflow_dispatch:inputs:operation:- description: 'Check the marked release branch or capture a main baseline candidate'+ description: 'Run the canonical check on exact main or a marked release branch, or capture a main baseline candidate'type: choiceoptions: [capture, release-check]default: capturerequired: truerelease-branch:- description: 'Marked release/vX.Y.Z branch; required for release-check'+ description: 'Exact branch to check: main before a cut, or marked release/vX.Y.Z after the bump'type: stringrequired: falserelease-version:- description: 'Exact X.Y.Z version recorded by the active marker; required for release-check'+ description: 'Exact X.Y.Z version recorded by the active marker; required only for a marked release branch'type: stringrequired: falseexpected-head:- description: 'Exact full release branch SHA; required for release-check'+ description: 'Exact full main or release branch SHA; required for release-check'type: stringrequired: falseplan-digest:- description: 'Exact SHA-256 digest recorded by the active marker; required for release-check'+ description: 'Exact SHA-256 digest recorded by the active marker; required only for a marked release branch'type: stringrequired: false@@ -68,8 +68,8 @@ jobs:spec_only: ${{ steps.scope.outputs.spec_only }}tooling_only: ${{ steps.scope.outputs.tooling_only }}release_bump: ${{ steps.scope.outputs.release_bump }}- release_branch: ${{ steps.release-authority.outputs.branch }}- release_head: ${{ steps.release-authority.outputs.head }}+ release_branch: ${{ steps.release-authority.outputs.branch || steps.main-authority.outputs.branch }}+ release_head: ${{ steps.release-authority.outputs.head || steps.main-authority.outputs.head }}release_plan_digest: ${{ steps.release-authority.outputs.planDigest }}steps:- uses: actions/checkout@v7@@ -79,14 +79,14 @@ jobs:- name: Fetch active release refsif: >-- (github.event_name == 'workflow_dispatch' && inputs.operation == 'release-check') ||+ (github.event_name == 'workflow_dispatch' && inputs.operation == 'release-check' && inputs['release-branch'] != 'main') ||(github.event_name == 'pull_request' && startsWith(github.base_ref, 'release/v'))run: git fetch origin '+refs/heads/release/v*:refs/remotes/origin/release/v*'- name: Validate active release authorityid: release-authorityif: >-- (github.event_name == 'workflow_dispatch' && inputs.operation == 'release-check') ||+ (github.event_name == 'workflow_dispatch' && inputs.operation == 'release-check' && inputs['release-branch'] != 'main') ||(github.event_name == 'pull_request' && startsWith(github.base_ref, 'release/v'))env:RELEASE_BRANCH: ${{ github.event_name == 'workflow_dispatch' && inputs['release-branch'] || github.base_ref }}@@ -123,6 +123,35 @@ jobs:finode "$VALIDATOR" "${ARGS[@]}"+ - name: Validate exact main pre-cut authority+ id: main-authority+ if: >-+ github.event_name == 'workflow_dispatch' &&+ inputs.operation == 'release-check' &&+ inputs['release-branch'] == 'main'+ env:+ EXPECTED_HEAD: ${{ inputs['expected-head'] }}+ run: |+ set -eu+ if [ "$GITHUB_REF" != 'refs/heads/main' ]; then+ echo 'Main pre-cut checks must be dispatched from main.'+ exit 1+ fi+ if ! [[ "$EXPECTED_HEAD" =~ ^[0-9a-f]{40}$ ]]; then+ echo 'Main pre-cut checks require an exact full expected head.'+ exit 1+ fi+ if [ "$GITHUB_SHA" != "$EXPECTED_HEAD" ]; then+ echo 'Checked-out main commit does not match expected head.'+ exit 1+ fi+ REMOTE_HEAD=$(git ls-remote origin refs/heads/main | awk '{print $1}')+ if [ -z "$REMOTE_HEAD" ] || [ "$REMOTE_HEAD" != "$EXPECTED_HEAD" ]; then+ echo 'Main moved before checks began; dispatch again for its new head.'+ exit 1+ fi+ printf 'branch=main\nhead=%s\n' "$EXPECTED_HEAD" >> "$GITHUB_OUTPUT"+- name: Fetch base branchif: github.event_name == 'pull_request'run: git fetch origin ${{ github.base_ref }} --depth=50@@ -2256,12 +2285,13 @@ jobs:permissions:contents: readsteps:- - name: Require complete exact-head release branch checks+ - name: Require complete exact-head canonical checksuses: actions/github-script@v9env:RELEASE_NEEDS: ${{ toJSON(needs) }}RELEASE_BRANCH: ${{ inputs['release-branch'] }}EXPECTED_HEAD: ${{ inputs['expected-head'] }}+ CHECKED_HEAD: ${{ needs.check-scope.outputs.release_head }}PLAN_DIGEST: ${{ needs.check-scope.outputs.release_plan_digest }}with:script: |@@ -2274,19 +2304,36 @@ jobs:const branch = process.env.RELEASE_BRANCH;const expectedHead = process.env.EXPECTED_HEAD;if (context.ref !== `refs/heads/${branch}`) {- throw new Error('Release checks must run from the marked release branch.');+ throw new Error('Canonical release checks must run from the requested branch.');}if (context.sha !== expectedHead) {- throw new Error('Checked-out release commit does not match expected head.');+ throw new Error('Checked-out commit does not match expected head.');}const {data} = await github.rest.git.getRef({...context.repo, ref: `heads/${branch}`});if (data.object.sha !== expectedHead) {- throw new Error('Release branch moved during checks; dispatch release-check again for its new head.');+ throw new Error(`${branch} moved during checks; dispatch release-check again for its new head.`);+ }+ if (branch === 'main') {+ if (process.env.CHECKED_HEAD !== expectedHead) {+ throw new Error('Main authority check did not bind the expected head.');+ }+ await core.summary+ .addHeading('Main pre-cut checks complete')+ .addRaw(`Exact head: ${expectedHead}\n\n`)+ .addRaw('Canonical visual, accessibility, and RTL checks completed with full scope. A release may cut only while main still points to this exact head.')+ .write();+ return;+ }+ if (!branch.startsWith('release/v')) {+ throw new Error('Post-bump release checks require a marked release branch.');+ }+ if (!/^[0-9a-f]{64}$/.test(process.env.PLAN_DIGEST)) {+ throw new Error('Post-bump release checks require the active plan digest.');}await core.summary.addHeading('Release checks complete').addRaw(`Branch: ${branch}\n\n`).addRaw(`Exact head: ${expectedHead}\n\n`).addRaw(`Plan digest: ${process.env.PLAN_DIGEST}\n\n`)- .addRaw('Canonical visual, accessibility, and RTL checks completed with full scope. Main movement is not release input. This receipt is reusable only for this exact branch, head, and plan digest; any cherry-pick requires a new run.')+ .addRaw('Canonical visual, accessibility, and RTL checks completed with full scope. Main movement is not release input. This receipt is reusable only for this exact branch, head, and plan digest; any branch revision requires a new run.').write();