An open source design system that's fully customizable and agent ready
TypeScript
ci: hold pull-request jobs to the 15-minute budget and report job durations (#8427)
Cindy Zhang4aac938c3cef
diff --git a/.github/scripts/ci-duration-guard.test.mjs b/.github/scripts/ci-duration-guard.test.mjsnew file mode 100644index 0000000000..e4a751042a--- /dev/null+++ b/.github/scripts/ci-duration-guard.test.mjs@@ -0,0 +1,96 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++/**+ * @file PR CI stays within its 15-minute budget.+ *+ * Every job that can run on a pull request carries a `timeout-minutes` of at+ * most 15 for pull-request events, so a lane that grows past the budget fails+ * where it grew instead of silently stretching every contributor's wait.+ * Release and maintenance dispatches keep longer limits through an expression.+ * The report-only `ci-duration` job lists each job's run time once every+ * pull-request job has finished, and warns past 12 minutes.+ */++import fs from 'node:fs';+import path from 'node:path';++import {describe, expect, it} from 'vitest';+import yaml from 'yaml';++const root = path.resolve(import.meta.dirname, '../..');+const ci = yaml.parse(+ fs.readFileSync(path.join(root, '.github/workflows/ci.yml'), 'utf8'),+);++const BUDGET = 15;+// macOS Swift builds run on another runner pool with their own variance; the+// job only does work when native Swift changes.+const EXEMPT = new Set(['test-native-swift']);+// Jobs that only classify scope or join results finish in seconds and need no+// limit of their own; every job that installs, builds, or tests has one.+const JOINS = new Set([+ 'check-scope',+ 'check-components',+ 'native-swift-scope',+ 'test',+ 'build',+ 'pr-rtl',+]);++/** The limit a pull-request run gets from a job's `timeout-minutes`. */+function pullRequestLimit(value) {+ if (typeof value === 'number') return value;+ if (typeof value !== 'string') return undefined;+ const dispatch =+ /^\$\{\{ github\.event_name == 'workflow_dispatch' && (\d+) \|\| (\d+) \}\}$/.exec(+ value,+ );+ return dispatch ? Number(dispatch[2]) : undefined;+}++// A job whose condition requires a dispatch never runs on a pull request.+const runsOnPullRequests = job => {+ const condition = String(job.if ?? '');+ const dispatchOnly =+ condition.includes("github.event_name == 'workflow_dispatch' &&") &&+ !condition.includes('pull_request') &&+ !condition.includes("!= 'workflow_dispatch'");+ return !dispatchOnly;+};++describe('PR CI duration budget', () => {+ const prJobs = Object.entries(ci.jobs).filter(+ ([id, job]) => runsOnPullRequests(job) && id !== 'ci-duration',+ );+ const jobs = prJobs.filter(([id]) => !EXEMPT.has(id) && !JOINS.has(id));++ it('finds the pull-request work jobs', () => {+ expect(jobs.map(([id]) => id)).toEqual(+ expect.arrayContaining(['test-ui', 'test-node', 'pr-a11y', 'pr-visual']),+ );+ });++ it.each(jobs.map(([id, job]) => [id, job]))(+ '%s stops within the 15-minute budget on a pull request',+ (id, job) => {+ const limit = pullRequestLimit(job['timeout-minutes']);+ expect(limit, `${id} has no pull-request timeout`).toBeDefined();+ expect(limit).toBeLessThanOrEqual(BUDGET);+ },+ );++ it('reports every pull-request job after it finishes, without gating', () => {+ const report = ci.jobs['ci-duration'];+ expect(report.if).toBe(+ "${{ always() && github.event_name == 'pull_request' }}",+ );+ expect(report['continue-on-error']).toBe(true);+ expect(report.permissions).toEqual({actions: 'read'});+ // Waiting on every pull-request job is what lets the table include the+ // slowest lanes, whichever join they feed.+ expect([...report.needs].sort()).toEqual(prJobs.map(([id]) => id).sort());+ const script = report.steps[0].with.script;+ expect(script).toContain('row.minutes > 12');+ expect(script).toContain('Run span');+ });+});diff --git a/.github/scripts/ci-test-routing.test.mjs b/.github/scripts/ci-test-routing.test.mjsindex a8ef2fde70..2ea98403ea 100644--- a/.github/scripts/ci-test-routing.test.mjs+++ b/.github/scripts/ci-test-routing.test.mjs@@ -426,7 +426,10 @@ describe('ci.yml RTL package sharding', () => {expect(new Set(parts.map(leg => leg.parts)).size).toBe(1);}expect(shard['runs-on']).toBe('4-core-ubuntu');- expect(shard['timeout-minutes']).toBeLessThanOrEqual(30);+ // Pull requests get the 15-minute PR budget; the full release roster, 30.+ expect(shard['timeout-minutes']).toBe(+ "${{ github.event_name == 'workflow_dispatch' && 30 || 15 }}",+ );expect(shard['continue-on-error']).not.toBe(true);const scope = shard.steps.find(step => step.name === 'Resolve RTL shard scope',diff --git a/.github/scripts/shadcn-registry-ci.test.mjs b/.github/scripts/shadcn-registry-ci.test.mjsindex 0ba014b298..cb2619adcd 100644--- a/.github/scripts/shadcn-registry-ci.test.mjs+++ b/.github/scripts/shadcn-registry-ci.test.mjs@@ -37,7 +37,7 @@ describe('ShadCN registry CI contract', () => {expect(job.needs).toEqual(['check-scope']);expect(job.if).toContain('always()');expect(job['runs-on']).toBe('4-core-ubuntu');- expect(job['timeout-minutes']).toBe(30);+ expect(job['timeout-minutes']).toBe(15);expect(step('Require successful scope classification').run).toContain('refusing to skip required work',);diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex 99bf17a04e..cee2db154d 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -40,6 +40,12 @@ on:permissions: {}+# PR CI's budget is 15 minutes. Every job in this workflow that does work on a+# pull request carries `timeout-minutes: 15` (release and maintenance+# dispatches keep longer limits; macOS-only `test-native-swift` keeps 30), and+# `ci-duration` reports each job's run time and the run's span. Split a job+# that nears the limit (shard, scope, cache); do not raise it.+## One group per pull request (a fork's branch name can repeat across forks),# so a new push cancels the superseded run. Merge-queue entries and dispatches# get their own groups and are never cancelled by a pull request.@@ -214,6 +220,7 @@ jobs:needs: [check-scope]if: ${{ github.event_name == 'pull_request' && needs.check-scope.outputs.release_bump == 'true' }}runs-on: 2-core-ubuntu-arm+ timeout-minutes: 15permissions:contents: readsteps:@@ -279,6 +286,7 @@ jobs:if: ${{ github.event_name == 'pull_request' && github.base_ref == 'main' }}# Match the stable publisher so byte parity covers the same packed manifest.runs-on: 4-core-ubuntu+ timeout-minutes: 15permissions:contents: readsteps:@@ -364,6 +372,7 @@ jobs:needs: [check-scope, docsite-browser, docsite-data]if: ${{ github.event_name != 'workflow_dispatch' && needs.check-scope.outputs.release_bump != 'true' && always() && !cancelled() }}runs-on: 2-core-ubuntu-arm+ timeout-minutes: 15permissions:contents: readsteps:@@ -406,6 +415,7 @@ jobs:needs: [check-scope]if: github.event_name != 'workflow_dispatch' && needs.check-scope.outputs.spec_only != 'true' && needs.check-scope.outputs.tooling_only != 'true'runs-on: 2-core-ubuntu-arm+ timeout-minutes: 15permissions:contents: readsteps:@@ -451,6 +461,7 @@ jobs:# The longest docsite owner; the Next.js production build uses every core# it gets.runs-on: 4-core-ubuntu+ timeout-minutes: 15permissions:contents: readsteps:@@ -613,6 +624,7 @@ jobs:matrix:shard: [1, 2, 3, 4]runs-on: 4-core-ubuntu+ timeout-minutes: 15permissions:contents: readsteps:@@ -689,6 +701,7 @@ jobs:# Vitest runs one test file per CPU beyond the first, so the 2-core runner# ran this suite one file at a time (~23 min). Four cores give it three.runs-on: 4-core-ubuntu+ timeout-minutes: 15permissions:contents: readsteps:@@ -819,7 +832,7 @@ jobs:matrix:leg: [preview, production]runs-on: 4-core-ubuntu- timeout-minutes: 30+ timeout-minutes: 15permissions:contents: readsteps:@@ -921,6 +934,7 @@ jobs:# Every browser lane waits for this job, and the package builds and the# Storybook build run side by side (build-packages-and-storybook.mjs).runs-on: 4-core-ubuntu+ timeout-minutes: ${{ github.event_name == 'workflow_dispatch' && 360 || 15 }}permissions:contents: readoutputs:@@ -1076,6 +1090,7 @@ jobs:needs: [check-scope]if: github.event_name == 'pull_request' && needs.check-scope.result == 'success' && needs.check-scope.outputs.docsite_only != 'true' && needs.check-scope.outputs.spec_only != 'true' && needs.check-scope.outputs.tooling_only != 'true'runs-on: ubuntu-latest+ timeout-minutes: 15permissions:contents: readsteps:@@ -1157,6 +1172,7 @@ jobs:needs: [check-scope]if: ${{ (github.event_name != 'workflow_dispatch' || inputs.operation == 'release-check') && always() && !cancelled() && needs.check-scope.outputs.spec_only != 'true' }}runs-on: 2-core-ubuntu-arm+ timeout-minutes: ${{ github.event_name == 'workflow_dispatch' && 360 || 15 }}permissions:contents: readsteps:@@ -1213,6 +1229,7 @@ jobs:needs: [check-scope]if: github.event_name == 'pull_request' && needs.check-scope.outputs.docsite_only != 'true' && needs.check-scope.outputs.spec_only != 'true' && needs.check-scope.outputs.tooling_only != 'true'runs-on: 2-core-ubuntu-arm+ timeout-minutes: 15permissions:contents: readoutputs:@@ -1429,6 +1446,7 @@ jobs:needs: [build-storybook, check-components]if: (github.event_name == 'pull_request' || (github.event_name == 'workflow_dispatch' && inputs.operation == 'release-check')) && needs.check-components.outputs.has_components == 'true'runs-on: 2-core-ubuntu-arm+ timeout-minutes: ${{ github.event_name == 'workflow_dispatch' && 360 || 15 }}permissions:contents: readsteps:@@ -1689,6 +1707,7 @@ jobs:needs: [check-scope]if: github.event_name != 'workflow_dispatch' && needs.check-scope.outputs.docsite_only != 'true' && needs.check-scope.outputs.spec_only != 'true' && needs.check-scope.outputs.tooling_only != 'true'runs-on: 2-core-ubuntu-arm+ timeout-minutes: 15permissions:contents: readsteps:@@ -1712,6 +1731,7 @@ jobs:needs: [check-scope]if: github.event_name != 'workflow_dispatch' && needs.check-scope.outputs.docsite_only != 'true' && needs.check-scope.outputs.spec_only != 'true' && needs.check-scope.outputs.tooling_only != 'true'runs-on: 2-core-ubuntu-arm+ timeout-minutes: 15permissions:contents: readsteps:@@ -1754,6 +1774,7 @@ jobs:# Four pages on four cores: the scout is page-load bound, and on the rig# this cut a shard's scout by a quarter against two pages on two cores.runs-on: 4-core-ubuntu+ timeout-minutes: ${{ github.event_name == 'workflow_dispatch' && 360 || 15 }}permissions:contents: readsteps:@@ -1821,6 +1842,7 @@ jobs:needs.check-components.result == 'success') ||(needs.maintenance-request.result == 'success' && inputs.operation == 'capture'))))runs-on: 2-core-ubuntu-arm+ timeout-minutes: ${{ github.event_name == 'workflow_dispatch' && 360 || 15 }}permissions:contents: readsteps:@@ -2085,7 +2107,7 @@ jobs:- {package: richtext, part: 1, parts: 1}- {package: vega, part: 1, parts: 1}runs-on: 4-core-ubuntu- timeout-minutes: 30+ timeout-minutes: ${{ github.event_name == 'workflow_dispatch' && 30 || 15 }}permissions:contents: readsteps:@@ -2345,6 +2367,71 @@ jobs:--force-full "${{ needs.check-components.outputs.force_full_component_audits }}" \--reports-dir rtl-shard-reports+ # Report-only: after every pull-request job finishes, each job's run time+ # (start to finish, no queue) and the run's span go to the job summary, with+ # a warning for any job past 12 minutes, so a lane growing toward its+ # 15-minute limit shows before it fails. It never fails and is not required.+ ci-duration:+ needs:+ [+ check-scope,+ release-bump,+ release-merge-back,+ docsite-data,+ docsite-browser,+ docsite-test,+ check-components,+ test-ui,+ test-node,+ native-swift-scope,+ test-native-swift,+ registry-contract,+ test,+ build-storybook,+ size-base,+ typecheck,+ build-sandbox,+ build,+ pr-a11y,+ test-build,+ fixture-contrast,+ visual-scout,+ pr-visual,+ pr-rtl-shard,+ pr-rtl-merge,+ pr-rtl,+ ]+ if: ${{ always() && github.event_name == 'pull_request' }}+ runs-on: ubuntu-slim+ timeout-minutes: 5+ continue-on-error: true+ permissions:+ actions: read+ steps:+ - name: Report job durations+ uses: actions/github-script@v9+ with:+ script: |+ const jobs = await github.paginate(+ github.rest.actions.listJobsForWorkflowRunAttempt,+ {...context.repo, run_id: context.runId, attempt_number: Number(process.env.GITHUB_RUN_ATTEMPT), per_page: 100},+ );+ const done = jobs.filter(job => job.started_at && job.completed_at && job.conclusion !== 'skipped' && job.name !== 'ci-duration');+ const rows = done+ .map(job => ({name: job.name, minutes: (Date.parse(job.completed_at) - Date.parse(job.started_at)) / 60000}))+ .sort((a, b) => b.minutes - a.minutes);+ for (const row of rows.filter(row => row.minutes > 12)) {+ core.warning(`${row.name} ran ${row.minutes.toFixed(1)} min; PR jobs stop at 15. Split it (shard, scope, cache).`);+ }+ const span = done.length+ ? (Math.max(...done.map(job => Date.parse(job.completed_at))) - Math.min(...done.map(job => Date.parse(job.started_at)))) / 60000+ : 0;+ await core.summary+ .addHeading('Job durations (run time, no queue)', 3)+ .addRaw(`Run span, first job start to last job end (includes waits between jobs): ${span.toFixed(1)} min\n\n`)+ .addTable([[{data: 'Job', header: true}, {data: 'Minutes', header: true}], ...rows.map(row => [row.name, row.minutes.toFixed(1)])])+ .write();+# Release-time projection only: the existing owners above do all measurement.# A skipped owner or main drift must never look like passing release evidence.release-check: