An open source design system that's fully customizable and agent ready
TypeScript
ci: a pull request's opt-in accessibility specs run in up to three legs (#10385)
Cindy Zhang1a6086655fc9
diff --git a/.github/scripts/a11y-pr-contracts.mjs b/.github/scripts/a11y-pr-contracts.mjsindex b213d32737..345101f468 100644--- a/.github/scripts/a11y-pr-contracts.mjs+++ b/.github/scripts/a11y-pr-contracts.mjs@@ -70,6 +70,8 @@ import fs from 'node:fs';import path from 'node:path';import {fileURLToPath} from 'node:url';+import {costOf, splitByDuration} from '../../scripts/lib/duration-split.mjs';+export const EVIDENCE_DIR = 'pr-a11y-evidence';const MODES = new Set(['always', 'audit', 'release-only', 'scoped']);@@ -690,6 +692,35 @@ function median(values) {: (sorted[middle - 1] + sorted[middle]) / 2;}+/** The longest one opt-in accessibility leg should take. */+export const LEG_BUDGET_MS = 10 * 60 * 1000;++/**+ * The legs an opt-in run needs: enough that each leg's recorded time fits+ * LEG_BUDGET_MS, at most `maxLegs`, split slowest first onto the leg with the+ * least time (`splitByDuration`, as the other leg planners). The recorded+ * times come from release legs that run four files at once on four cores; one+ * file alone on a pull-request runner runs faster, so a leg sums them without+ * the default check's margin.+ * @param {string[]} files+ * @param {Record<string, number>} seconds+ * @param {number} maxLegs+ */+export function planLegs(files, seconds, maxLegs) {+ const cost = costOf(files, seconds);+ const sum = list => list.reduce((total, file) => total + cost(file), 0);+ const count = Math.min(+ Math.max(1, maxLegs),+ Math.max(1, Math.ceil((sum(files) * 1000) / LEG_BUDGET_MS)),+ );+ const shares = splitByDuration(files, count, cost);+ return {+ count,+ shares,+ longestMs: Math.max(...shares.map(share => sum(share) * 1000)),+ };+}+/*** The default check's run. First the changed specs, at most the limit, in path* order. Then the owned specs, in path order. Then the dependents' specs, in@@ -1036,6 +1067,17 @@ function main() {const ownedBy = (ownedByValue ?? '').split(',').filter(Boolean);const dependentsOfValue = flagValue(argv, '--dependents-of');const dependentsOf = (dependentsOfValue ?? '').split(',').filter(Boolean);+ const countLegsValue = flagValue(argv, '--count-legs');+ const legValue = flagValue(argv, '--leg');+ const ofValue = flagValue(argv, '--of');+ const shareOutFile = flagValue(argv, '--share-out');+ const shareFile = flagValue(argv, '--share');+ if (+ (countLegsValue != null || shareFile != null) &&+ changedOnlyFile != null+ ) {+ throw new Error('--count-legs and --share split the opt-in run only');+ }if ((ownedByValue != null ||changedFilesFile != null ||@@ -1058,6 +1100,11 @@ function main() {changedFilesFile,ownedByValue,dependentsOfValue,+ countLegsValue,+ legValue,+ ofValue,+ shareOutFile,+ shareFile,]);// Outside CI, a run with no base compares with origin/main.const base =@@ -1110,8 +1157,69 @@ function main() {workers: contractWorkers(),});})();- const selected = budgeted.run;const notRun = budgeted.notRun;+ // The opt-in run splits into legs by recorded time. The count step plans+ // them before the Storybook download and the Chromium install; each leg+ // then runs only its share.+ const scopeKnown = changedPaths != null;+ // Every leg counts on its own runner. A leg that cannot tell this pull+ // request's files would split another list than the other legs, so it+ // plans itself as the only leg, with the whole selection, as the+ // interaction legs do.+ const scopeLost = countLegsValue != null && isPullRequest && !scopeKnown;+ const legs =+ countLegsValue != null+ ? scopeLost+ ? planLegs(+ budgeted.run.map(({file}) => file),+ {},+ 1,+ )+ : planLegs(+ budgeted.run.map(({file}) => file),+ readDurations(root, policySha),+ Number(countLegsValue),+ )+ : null;+ if (countLegsValue != null) {+ const leg = scopeLost ? 1 : Number(legValue ?? 1);+ if (scopeLost) {+ console.log(+ "::warning title=Accessibility scope unknown::This leg could not list the pull request's files, so it runs the whole selection as the only leg.",+ );+ }+ const minutes = (legs.longestMs / 60000).toFixed(1);+ console.log(+ `Accessibility legs: ${legs.count} for ${budgeted.run.length} spec files (the longest leg's recorded time ${minutes} min).`,+ );+ if (legs.longestMs > LEG_BUDGET_MS) {+ console.log(+ `::warning title=Accessibility specs over ten minutes::${legs.count} legs still leave ${minutes} min of recorded time in one leg. The selection needs more legs.`,+ );+ }+ // The run step reads this leg's share from here, so it runs exactly+ // what this count planned, never a selection of its own.+ if (shareOutFile) {+ const share = new Set(legs.shares[leg - 1] ?? []);+ fs.writeFileSync(+ shareOutFile,+ `${JSON.stringify({scopeKnown, run: budgeted.run.filter(({file}) => share.has(file))})}\n`,+ );+ }+ if (process.env.GITHUB_OUTPUT) {+ fs.appendFileSync(+ process.env.GITHUB_OUTPUT,+ `count=${legs.count}\nruns=${leg <= legs.count}\nleg=${leg}\n`,+ );+ }+ return 0;+ }+ const legIndex = legValue != null ? Number(legValue) : 1;+ // A leg runs the share its count step wrote. A missing or unreadable share+ // fails the leg, so a planned file is never dropped.+ const share =+ shareFile != null ? JSON.parse(fs.readFileSync(shareFile, 'utf8')) : null;+ const selected = share ? share.run : budgeted.run;const [audited] = auditedComponents(title);const auditConfigFile = '.github/a11y-audit-axe.json';const plan = planFor(@@ -1132,7 +1240,7 @@ function main() {{head: process.env.ASTRYX_HEAD_SHA ?? null,discovered: specs.length,- scopeKnown: changedPaths != null,+ scopeKnown: share ? share.scopeKnown : scopeKnown,components,ownedBy,audit: plan && {component: audited, ...plan},@@ -1144,7 +1252,9 @@ function main() {)}\n`,);console.log(- `PR accessibility specs: ${selected.length} of ${specs.length} discovered.`,+ shareFile != null+ ? `PR accessibility specs, leg ${legIndex} of ${ofValue ?? '?'}: the ${selected.length} spec files of this leg's share.`+ : `PR accessibility specs: ${selected.length} of ${specs.length} discovered.`,);for (const {file, reason} of selected) console.log(` ${file} (${reason})`);for (const {file, reason} of notRun) {@@ -1160,7 +1270,9 @@ function main() {let status = 0;// A component audit's own axe pass, held until its open state is ready.- if (plan) {+ // It runs once, on the first leg; every leg keeps the audit's environment+ // for the audit specs in its share.+ if (plan && legIndex === 1) {const axe = spawnSync(process.execPath, auditArgs(plan), {cwd: root,stdio: 'inherit',diff --git a/.github/scripts/a11y-pr-legs.test.mjs b/.github/scripts/a11y-pr-legs.test.mjsnew file mode 100644index 0000000000..a827ef9ae3--- /dev/null+++ b/.github/scripts/a11y-pr-legs.test.mjs@@ -0,0 +1,214 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++/**+ * @file Contract: a pull request's opt-in accessibility specs run in legs.+ *+ * The browser-specs job runs its selection on one worker, and the files'+ * recorded times assume one browser per core, so more workers on one runner+ * only stretch each file. The job instead splits the selection into up to+ * three legs by recorded time, each about ten minutes or less, inside the+ * job's fifteen minutes. A leg the selection does not need stops after its+ * count step, before the Storybook download and the Chromium install.+ */++import {spawnSync} from 'node:child_process';+import fs from 'node:fs';+import os from 'node:os';+import path from 'node:path';++import {afterAll, describe, expect, it} from 'vitest';+import yaml from 'yaml';++import {LEG_BUDGET_MS, planLegs} from './a11y-pr-contracts.mjs';+import {matrixFor} from './ci-matrix.mjs';++const root = path.resolve(import.meta.dirname, '../..');+const job = yaml.parse(+ fs.readFileSync(path.join(root, '.github/workflows/ci.yml'), 'utf8'),+).jobs['pr-a11y-specs'];+const step = name => job.steps.find(s => s.name === name);+const scratch = [];+afterAll(() => {+ for (const dir of scratch) fs.rmSync(dir, {recursive: true, force: true});+});++// One pull request's selection: 70 spec files (478 tests), at the recorded+// times then (a file with no recorded time at the median, 17.5 s). On one+// worker in one job it ran 432 tests and the job's fifteen minutes cut it.+const SELECTION_SECONDS = [+ 3.6, 4.4, 12.6, 10.7, 37.9, 17.5, 17.5, 4, 17.5, 8.8, 59.2, 20, 28.8, 17.5,+ 17.5, 17.5, 17.5, 3.1, 7.5, 4, 8.2, 17.5, 10.9, 62, 17.9, 17.5, 21.8, 17.5,+ 11.9, 17.5, 4.9, 3.8, 17.5, 85.1, 133.3, 22.1, 13.5, 9, 35.8, 16, 17.5, 22.5,+ 15.7, 17.5, 14.4, 24.5, 3.8, 2.2, 5.8, 2.6, 1.5, 15.4, 2.3, 38.2, 4, 325.2,+ 1.7, 12.3, 17.5, 17.5, 0.2, 8.5, 4, 2.5, 46.7, 3, 17.5, 17.5, 5.6, 20.9,+];+const selection = SELECTION_SECONDS.map(+ (_, i) => `packages/core/src/S${String(i).padStart(2, '0')}.a11y.spec.ts`,+);+const seconds = Object.fromEntries(+ selection.map((file, i) => [file, SELECTION_SECONDS[i]]),+);+const sumMs = files => files.reduce((t, f) => t + seconds[f] * 1000, 0);++describe('the opt-in accessibility specs split into legs', () => {+ it('splits a selection that one job cannot finish into legs that each fit ten minutes', () => {+ expect(LEG_BUDGET_MS).toBe(10 * 60 * 1000);+ // In one job, the selection's recorded time is about 26 minutes.+ expect(sumMs(selection)).toBeGreaterThan(2 * LEG_BUDGET_MS);+ const {count, shares, longestMs} = planLegs(selection, seconds, 3);+ expect(count).toBe(3);+ expect(longestMs).toBeLessThanOrEqual(LEG_BUDGET_MS);+ for (const share of shares)+ expect(sumMs(share)).toBeLessThanOrEqual(LEG_BUDGET_MS);+ // Every file runs in exactly one leg.+ expect(shares.flat().sort()).toEqual([...selection].sort());+ });++ it('keeps a small selection in one leg, and never plans more legs than the matrix has', () => {+ expect(planLegs(selection.slice(0, 5), seconds, 3).count).toBe(1);+ expect(planLegs([], seconds, 3)).toMatchObject({count: 1, shares: [[]]});+ const all = planLegs(selection, seconds, 2);+ expect(all.count).toBe(2);+ expect(all.longestMs).toBeGreaterThan(LEG_BUDGET_MS);+ });++ it('splits slowest first onto the leg with the least time, as the other leg planners do', () => {+ const ms = {a: 400, b: 300, c: 200, d: 200, e: 100};+ expect(planLegs(Object.keys(ms), ms, 2).shares).toEqual([+ ['a', 'd'],+ ['b', 'c', 'e'],+ ]);+ });+});++describe('the browser-specs job', () => {+ it('runs three legs for a pull request and one job for a release check', () => {+ expect(matrixFor(job.strategy.matrix.leg, 'pull_request')).toEqual([+ 1, 2, 3,+ ]);+ expect(matrixFor(job.strategy.matrix.leg, 'workflow_dispatch')).toEqual([+ 1,+ ]);+ expect(job.strategy['fail-fast']).toBe(false);+ // One parenthesized suffix, so status reports read the job as pr-a11y.+ expect(job.name).toBe(+ 'pr-a11y (browser specs ${{ matrix.leg }}/${{ strategy.job-total }})',+ );+ });++ it('counts the legs before the Storybook download and the Chromium install, and only a leg with a share runs its share', () => {+ const names = job.steps.map(s => s.name);+ const count = step("Count this run's accessibility legs");+ expect(names.indexOf(count.name)).toBeLessThan(+ names.indexOf('Download Storybook artifact'),+ );+ expect(names.indexOf(count.name)).toBeLessThan(+ names.indexOf('Install Playwright'),+ );+ expect(count.run).toContain(+ 'node "$runner" --count-legs ${{ strategy.job-total }} --leg ${{ matrix.leg }} --share-out "$RUNNER_TEMP/a11y-leg-share.json"',+ );+ // The runner imports the shared duration split, so it is copied beside it.+ expect(count.run).toContain(+ 'git show "$WORKFLOW_SHA:scripts/lib/duration-split.mjs" > "$RUNNER_TEMP/a11y/scripts/lib/duration-split.mjs"',+ );+ expect(count.run).toContain('BASE_SHA=$(git rev-parse "$WORKFLOW_SHA^1")');+ for (const name of [+ 'Download Storybook artifact',+ 'Install Playwright',+ 'Run browser accessibility specs',+ 'Upload browser accessibility evidence',+ ]) {+ expect(step(name).if, name).toContain(+ "steps.legs.outputs.runs == 'true'",+ );+ }+ const run = step('Run browser accessibility specs');+ // The run step runs the share the count step wrote, never a selection+ // of its own.+ expect(run.run).toContain(+ 'node "$runner" --share "$RUNNER_TEMP/a11y-leg-share.json" --leg ${{ steps.legs.outputs.leg }} --of ${{ steps.legs.outputs.count }}',+ );+ // One worker per leg: the recorded times assume one browser per core.+ expect(run.env.A11Y_CONTRACT_WORKERS).toBeUndefined();+ expect(step('Upload browser accessibility evidence').with.name).toBe(+ 'pr-a11y-evidence-${{ needs.build-storybook.outputs.short_hash }}-${{ matrix.leg }}',+ );+ });++ // Each count lists every spec through Playwright, a few seconds apiece.+ it("writes the leg count and this leg's share for the steps after it", () => {+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'a11y-legs-'));+ scratch.push(dir);+ const count = (legs, leg, env = {}) => {+ const output = path.join(dir, `output-${legs}-${leg}`);+ const result = spawnSync(+ process.execPath,+ [+ path.join(root, '.github/scripts/a11y-pr-contracts.mjs'),+ '--count-legs',+ String(legs),+ '--leg',+ String(leg),+ '--share-out',+ path.join(dir, `share-${legs}-${leg}.json`),+ ],+ {+ cwd: root,+ encoding: 'utf8',+ // Outside a pull request the count needs no pull request's files.+ env: {+ ...process.env,+ GITHUB_EVENT_NAME: 'workflow_dispatch',+ GITHUB_OUTPUT: output,+ WORKFLOW_SHA: '',+ BASE_SHA: '',+ ...env,+ },+ },+ );+ expect(result.status, result.stderr).toBe(0);+ return {+ stdout: result.stdout,+ output: Object.fromEntries(+ fs+ .readFileSync(output, 'utf8')+ .trim()+ .split('\n')+ .map(line => line.split('=')),+ ),+ };+ };+ // A leg runs only when the count reaches it.+ const third = count(3, 3);+ expect(third.output.leg).toBe('3');+ expect(['1', '2', '3']).toContain(third.output.count);+ expect(third.output.runs).toBe(String(Number(third.output.count) >= 3));+ expect(third.stdout).toMatch(/^Accessibility legs: \d for \d+ spec files/m);+ // A leg that cannot list the pull request's files runs the whole+ // selection as the only leg, so no planned file is left out.+ const lost = count(3, 2, {+ GITHUB_EVENT_NAME: 'pull_request',+ GITHUB_ACTIONS: 'true',+ });+ expect(lost.output).toEqual({count: '1', runs: 'true', leg: '1'});+ expect(lost.stdout).toContain(+ '::warning title=Accessibility scope unknown::',+ );+ const lostShare = JSON.parse(+ fs.readFileSync(path.join(dir, 'share-3-2.json'), 'utf8'),+ );+ expect(lostShare.scopeKnown).toBe(false);+ expect(lostShare.run.length).toBeGreaterThan(0);+ const one = count(1, 1);+ expect(one.output).toEqual({count: '1', runs: 'true', leg: '1'});+ // One leg's share is the whole selection, each file with its reason.+ const share = JSON.parse(+ fs.readFileSync(path.join(dir, 'share-1-1.json'), 'utf8'),+ );+ expect(share.scopeKnown).toBe(true);+ expect(share.run.length).toBeGreaterThan(0);+ for (const entry of share.run)+ expect(Object.keys(entry).sort()).toEqual(['file', 'reason']);+ }, 180_000);+});diff --git a/.github/scripts/ci-a11y-merge-base.test.mjs b/.github/scripts/ci-a11y-merge-base.test.mjsindex 603f5c4f93..0a2336fdc6 100644--- a/.github/scripts/ci-a11y-merge-base.test.mjs+++ b/.github/scripts/ci-a11y-merge-base.test.mjs@@ -25,7 +25,7 @@ const ci = yaml.parse();const step = Object.values(ci.jobs).flatMap(job => job.steps ?? [])- .find(s => s.name === 'Run browser accessibility specs');+ .find(s => s.name === "Count this run's accessibility legs");const scratch = [];afterAll(() => {for (const dir of scratch) fs.rmSync(dir, {recursive: true, force: true});@@ -65,6 +65,8 @@ function repository() {'',].join('\n'),);+ // The runner's shared duration split, which the step copies beside it.+ write('scripts/lib/duration-split.mjs', '');git(origin, 'add', '-A');git(origin, 'commit', '-qm', 'opened on', '--no-verify');const openedOn = git(origin, 'rev-parse', 'HEAD');@@ -103,18 +105,23 @@ describe('the opt-in accessibility specs plan from the pull request’s own chanit('plans only the head’s own change after the base is merged into it', () => {const {checkout, openedOn, workflow} = repository();- const result = spawnSync('bash', ['-e', '-c', step.run], {- cwd: checkout,- encoding: 'utf8',- env: {- ...process.env,- ...step.env,- // The event's stale base, which the step must not use.- BASE_SHA: openedOn,- WORKFLOW_SHA: workflow,- RUNNER_TEMP: tmp('a11y-base-temp-'),+ const result = spawnSync(+ 'bash',+ // The leg's expressions, as GitHub fills them in for a first leg.+ ['-e', '-c', step.run.replace(/\$\{\{[^}]*\}\}/g, '1')],+ {+ cwd: checkout,+ encoding: 'utf8',+ env: {+ ...process.env,+ ...step.env,+ // The event's stale base, which the step must not use.+ BASE_SHA: openedOn,+ WORKFLOW_SHA: workflow,+ RUNNER_TEMP: tmp('a11y-base-temp-'),+ },},- });+ );expect(result.status, result.stderr).toBe(0);expect(result.stdout.trim().split('\n')).toEqual(['packages/core/src/Button/Button.tsx',diff --git a/.github/scripts/ci-test-routing.test.mjs b/.github/scripts/ci-test-routing.test.mjsindex 06a290d0c2..79b0fd8cd7 100644--- a/.github/scripts/ci-test-routing.test.mjs+++ b/.github/scripts/ci-test-routing.test.mjs@@ -422,31 +422,45 @@ describe('ci.yml pr-a11y browser specs', () => {});it("runs the merge commit's runner against the PR head", () => {+ const count = steps.find(+ step => step.name === "Count this run's accessibility legs",+ );expect(run.if).toBe(- "(!cancelled()) && steps.scope.outputs.has_components == 'true'",+ "(!cancelled()) && steps.scope.outputs.has_components == 'true' && steps.legs.outputs.runs == 'true'",);// The merge commit the steps come from, not the PR's recorded base, which- // can lag main and predate the runner.- expect(run.env.WORKFLOW_SHA).toBe('${{ github.sha }}');+ // can lag main and predate the runner. The count step selects; the run+ // step runs that leg's share with the same runner.+ for (const step of [count, run]) {+ expect(step.env.WORKFLOW_SHA).toBe('${{ github.sha }}');+ expect(step.env.PR_TITLE).toBe('${{ github.event.pull_request.title }}');+ }// The base comes from the merge commit's first parent, not the event.- expect(run.env.BASE_SHA).toBeUndefined();- expect(run.run).toContain('BASE_SHA=$(git rev-parse "$WORKFLOW_SHA^1")');- expect(run.env.PR_TITLE).toBe('${{ github.event.pull_request.title }}');+ expect(count.env.BASE_SHA).toBeUndefined();+ expect(count.run).toContain('BASE_SHA=$(git rev-parse "$WORKFLOW_SHA^1")');+ expect(count.run).toContain(+ 'git show "$WORKFLOW_SHA:.github/scripts/a11y-pr-contracts.mjs" > "$runner"',+ );+ expect(count.run).toContain(+ '--share-out "$RUNNER_TEMP/a11y-leg-share.json"',+ );expect(run.run).toContain('git show "$WORKFLOW_SHA:.github/scripts/a11y-pr-contracts.mjs" > "$runner"',);- expect(run.run).toContain('node "$runner"');+ expect(run.run).toContain(+ 'node "$runner" --share "$RUNNER_TEMP/a11y-leg-share.json"',+ );expect(JSON.parse(read('package.json')).scripts['test:a11y-contract:pr'],).toBe('node .github/scripts/a11y-pr-contracts.mjs');});- it('uploads every spec receipt in one head-bound artifact', () => {+ it('uploads every spec receipt in one head-bound artifact per leg', () => {expect(upload.if).toBe(- "(!cancelled()) && steps.scope.outputs.has_components == 'true'",+ "(!cancelled()) && steps.scope.outputs.has_components == 'true' && steps.legs.outputs.runs == 'true'",);expect(upload.with.name).toBe(- 'pr-a11y-evidence-${{ needs.build-storybook.outputs.short_hash }}',+ 'pr-a11y-evidence-${{ needs.build-storybook.outputs.short_hash }}-${{ matrix.leg }}',);for (const dir of ['pr-a11y-evidence/',diff --git a/.github/scripts/release-check-workflow.test.mjs b/.github/scripts/release-check-workflow.test.mjsindex 1d44463e7e..f88d939112 100644--- a/.github/scripts/release-check-workflow.test.mjs+++ b/.github/scripts/release-check-workflow.test.mjs@@ -135,6 +135,8 @@ function runs(force_full_component_audits: 'true',},},+ // A release check runs its accessibility specs in one leg.+ legs: {outputs: {count: '1', runs: 'true', leg: '1'}},},(value, prefix) => String(value ?? '').startsWith(prefix),);diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex 64a8acf5fa..241d01acfb 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -145,7 +145,7 @@ jobs:main: ${{ github.event_name == 'workflow_dispatch' }}max-wait-minutes: ${{ github.event_name == 'workflow_dispatch' && 120 || 12 }}max-looks: ${{ github.event_name == 'workflow_dispatch' && 30 || 2 }}- label-legs: '{"ci:run-visual": 6, "ci:run-rtl": 9, "ci:run-a11y": 3}'+ label-legs: '{"ci:run-visual": 6, "ci:run-rtl": 9, "ci:run-a11y": 5}'admission:needs: [room]@@ -188,7 +188,7 @@ jobs:main: ${{ github.event_name == 'workflow_dispatch' }}max-wait-minutes: ${{ github.event_name == 'workflow_dispatch' && 120 || 12 }}max-looks: ${{ github.event_name == 'workflow_dispatch' && 30 || 2 }}- label-legs: '{"ci:run-visual": 6, "ci:run-rtl": 9, "ci:run-a11y": 3}'+ label-legs: '{"ci:run-visual": 6, "ci:run-rtl": 9, "ci:run-a11y": 5}'# A pull-request run that waited its longest while another started at# its longest wait is turned away (spec:AST-030 DEC-16): ci-full stops@@ -2238,13 +2238,21 @@ jobs:# job budget before these specs start; running beside them keeps both owners# inside the budget without weakening the stable pr-a11y join.pr-a11y-specs:- name: pr-a11y (browser specs)+ name: pr-a11y (browser specs ${{ matrix.leg }}/${{ strategy.job-total }})needs: [build-storybook, run-labels]# A status check: heavy-ci, which skips on every run but an agent push,# is an ancestor (spec:AST-030 FR20); its skip must not skip this job.if: (((github.event_name == 'pull_request' && needs.run-labels.outputs.a11y == 'true') || (github.event_name == 'workflow_dispatch' && inputs.operation == 'release-check'))) && !cancelled() && needs.build-storybook.result == 'success' && needs.run-labels.result == 'success'runs-on: ${{ (github.event_name == 'workflow_dispatch' && inputs.operation == 'release-check' && github.triggering_actor != 'github-actions[bot]') && '2-core-ubuntu-arm' || 'ubuntu-24.04-arm' }}timeout-minutes: ${{ github.event_name == 'workflow_dispatch' && 360 || 15 }}+ # A pull request's selection splits into up to three legs by recorded+ # time, each about ten minutes or less on one worker; a leg the selection+ # does not need stops after its count step. A release check runs every+ # spec in one job.+ strategy:+ fail-fast: false+ matrix:+ leg: ${{ fromJSON(github.event_name == 'workflow_dispatch' && '[1]' || '[1, 2, 3]') }}permissions:contents: readpull-requests: read@@ -2288,15 +2296,42 @@ jobs:with:name: pr-analysis- - name: Download Storybook artifact+ # How many legs the selection needs, from the specs' recorded times, and+ # this leg's share, which the run step reads. It runs before the+ # Storybook download and the Chromium install; listing the specs installs+ # the workspace's dependencies. The runner, its routing lines and the+ # times come from the merge commit. The merge commit's first parent is+ # the base branch tip that it merges into.+ - name: Count this run's accessibility legs+ id: legsif: steps.scope.outputs.has_components == 'true'+ env:+ ASTRYX_HEAD_SHA: ${{ github.event.pull_request.head.sha || github.sha }}+ PR_TITLE: ${{ github.event.pull_request.title }}+ WORKFLOW_SHA: ${{ github.sha }}+ run: |+ runner="$RUNNER_TEMP/a11y/.github/scripts/a11y-pr-contracts.mjs"+ mkdir -p "$RUNNER_TEMP/a11y/.github/scripts" "$RUNNER_TEMP/a11y/scripts/lib"+ git fetch --quiet --no-tags --depth=2 origin "$WORKFLOW_SHA"+ git show "$WORKFLOW_SHA:.github/scripts/a11y-pr-contracts.mjs" > "$runner"+ git show "$WORKFLOW_SHA:scripts/lib/duration-split.mjs" > "$RUNNER_TEMP/a11y/scripts/lib/duration-split.mjs"+ BASE_SHA=$(git rev-parse "$WORKFLOW_SHA^1")+ export BASE_SHA+ node "$runner" --count-legs ${{ strategy.job-total }} --leg ${{ matrix.leg }} --share-out "$RUNNER_TEMP/a11y-leg-share.json"++ - name: Leave the specs to the legs that have a share+ if: steps.scope.outputs.has_components == 'true' && steps.legs.outputs.runs != 'true'+ run: echo "This leg runs no accessibility specs (${{ steps.legs.outputs.count }} leg(s) planned for this selection)."++ - name: Download Storybook artifact+ if: steps.scope.outputs.has_components == 'true' && steps.legs.outputs.runs == 'true'uses: actions/download-artifact@v8with:name: storybook-${{ needs.build-storybook.outputs.short_hash }}path: apps/storybook/dist- name: Install Playwright- if: steps.scope.outputs.has_components == 'true'+ if: steps.scope.outputs.has_components == 'true' && steps.legs.outputs.runs == 'true'run: pnpm install --frozen-lockfile && npx playwright install chromium# The runner runs every spec playwright.config.ts matches whose own@@ -2304,28 +2339,23 @@ jobs:# routing lines come from the merge commit these steps come from, so an# older PR head is routed by current policy while specs run at that head.- name: Run browser accessibility specs- if: (!cancelled()) && steps.scope.outputs.has_components == 'true'+ if: (!cancelled()) && steps.scope.outputs.has_components == 'true' && steps.legs.outputs.runs == 'true'env:ASTRYX_HEAD_SHA: ${{ github.event.pull_request.head.sha || github.sha }}PR_TITLE: ${{ github.event.pull_request.title }}WORKFLOW_SHA: ${{ github.sha }}- # The merge commit's first parent is the base branch tip that it- # merges into. The event's base SHA stays at the base the pull request- # was opened on, so after the base is merged into the head, a merge- # base from it counts the base's own changes as the pull request's.+ # This leg runs exactly the share its count step planned, with the+ # merge commit's runner, which the count step fetched.run: |- runner="$RUNNER_TEMP/a11y-pr-contracts.mjs"- git fetch --quiet --no-tags --depth=2 origin "$WORKFLOW_SHA"+ runner="$RUNNER_TEMP/a11y/.github/scripts/a11y-pr-contracts.mjs"git show "$WORKFLOW_SHA:.github/scripts/a11y-pr-contracts.mjs" > "$runner"- BASE_SHA=$(git rev-parse "$WORKFLOW_SHA^1")- export BASE_SHA- node "$runner"+ node "$runner" --share "$RUNNER_TEMP/a11y-leg-share.json" --leg ${{ steps.legs.outputs.leg }} --of ${{ steps.legs.outputs.count }}- name: Upload browser accessibility evidence- if: (!cancelled()) && steps.scope.outputs.has_components == 'true'+ if: (!cancelled()) && steps.scope.outputs.has_components == 'true' && steps.legs.outputs.runs == 'true'uses: actions/upload-artifact@v7with:- name: pr-a11y-evidence-${{ needs.build-storybook.outputs.short_hash }}+ name: pr-a11y-evidence-${{ needs.build-storybook.outputs.short_hash }}-${{ matrix.leg }}path: |pr-a11y-evidence/pr-a11y-output/@@ -4334,9 +4364,11 @@ jobs:FOLDERS: ${{ steps.touched.outputs.contract_folders }}A11Y_CONTRACT_WORKERS: 4run: |- runner="$RUNNER_TEMP/a11y-pr-contracts.mjs"+ runner="$RUNNER_TEMP/a11y/.github/scripts/a11y-pr-contracts.mjs"+ mkdir -p "$RUNNER_TEMP/a11y/.github/scripts" "$RUNNER_TEMP/a11y/scripts/lib"git cat-file -e "$WORKFLOW_SHA^{commit}" 2>/dev/null || git fetch --quiet --no-tags --depth=1 origin "$WORKFLOW_SHA"git show "$WORKFLOW_SHA:.github/scripts/a11y-pr-contracts.mjs" > "$runner"+ git show "$WORKFLOW_SHA:scripts/lib/duration-split.mjs" > "$RUNNER_TEMP/a11y/scripts/lib/duration-split.mjs"node "$runner" --changed-only "$SPECS_PATH" --changed-files "$FILES_PATH" --owned-by "$OWNERS" --dependents-of "$FOLDERS"- name: Upload contract evidencediff --git a/scripts/lib/duration-split.test.mjs b/scripts/lib/duration-split.test.mjsindex 52f05ac248..c6597bcc1b 100644--- a/scripts/lib/duration-split.test.mjs+++ b/scripts/lib/duration-split.test.mjs@@ -72,10 +72,14 @@ describe('splitting test files by recorded time', () => {expect(read('.github/scripts/playwright-legs.mjs')).toMatch(/import \{[^}]*costOf[^}]*splitByDuration[^}]*\} from '\.\.\/\.\.\/scripts\/lib\/duration-split\.mjs'/,);+ expect(read('.github/scripts/a11y-pr-contracts.mjs')).toMatch(+ /import \{[^}]*costOf[^}]*splitByDuration[^}]*\} from '\.\.\/\.\.\/scripts\/lib\/duration-split\.mjs'/,+ );for (const file of ['scripts/vitest-shard-sequencer.mjs','.github/scripts/a11y-contract-shard.mjs','.github/scripts/playwright-legs.mjs',+ '.github/scripts/a11y-pr-contracts.mjs',])expect(read(file), file).not.toMatch(/known\[Math\.floor/);});