From d3c0fbaede0359421c3ba2dbf763e0f03b1e3c1b Mon Sep 17 00:00:00 2001 From: Will Manning Date: Mon, 30 Nov 2026 17:06:29 +0000 Subject: [PATCH] Report the Lighthouse check under its literal name when its jobs are skipped The `report` job's name was an expression. GitHub evaluates a job's name only when the job runs, so on a fork PR, where the audits are skipped, the check reported under the unevaluated text, and the ruleset waited for "Lighthouse and axe" forever (#243). The job now has the literal name and runs on every pull request. It passes a PR whose audits were all skipped because it gets no secrets, and fails any other skip or failure. The Lighthouse matrix moves to the reusable lighthouse-audit.yml, and the baseline to lighthouse-baseline.yml, so no baseline run has a job by the required name: a skipped job still reports a check, and a skipped required check passes. tests/unit/required-checks.test.ts asserts that each check the ruleset requires of a workflow is a literal job name. Signed-off-by: Will Manning --- .github/workflows/lighthouse-audit.yml | 146 +++++++++++++++++ .github/workflows/lighthouse-baseline.yml | 80 ++++++++++ .github/workflows/lighthouse.yml | 183 ++++++---------------- CLAUDE.md | 6 +- lighthouserc.cjs | 4 +- tests/unit/lighthouse-scores.test.ts | 5 +- tests/unit/required-checks.test.ts | 106 +++++++++++++ 7 files changed, 389 insertions(+), 141 deletions(-) create mode 100644 .github/workflows/lighthouse-audit.yml create mode 100644 .github/workflows/lighthouse-baseline.yml create mode 100644 tests/unit/required-checks.test.ts diff --git a/.github/workflows/lighthouse-audit.yml b/.github/workflows/lighthouse-audit.yml new file mode 100644 index 0000000..471d0cb --- /dev/null +++ b/.github/workflows/lighthouse-audit.yml @@ -0,0 +1,146 @@ +name: Lighthouse audit + +# The Lighthouse jobs, one per page and profile, for a commit's Vercel +# preview. lighthouse.yml calls this on each pull request, and +# lighthouse-baseline.yml on a manual run. bench renders from its database, +# which only a deployment has, so the jobs audit the site and bench together +# on the preview, instead of a local build. +# +# Each page gets its own job, all at the same time. They can't share a +# runner: a second audit on the same CPU would skew Lighthouse's timings. +# Each job keeps its reports' scores as an artifact named +# `lighthouse--` for the caller to collect. +on: + workflow_call: + inputs: + sha: + description: The commit whose preview to audit. + type: string + required: true + runs: + description: Lighthouse runs for each page and profile + type: number + default: 3 + baseline: + description: Assert nothing, and keep every run's scores for the summary. + type: boolean + default: false + secrets: + bypass-secret: + description: The Vercel automation bypass secret. + required: true + +permissions: + contents: read + +env: + PROXY: http://127.0.0.1:3201 + +jobs: + lighthouse: + name: Lighthouse (${{ matrix.page }}, ${{ matrix.profile }}) + runs-on: ubuntu-26.04 + timeout-minutes: 30 + permissions: + contents: read + deployments: read + strategy: + fail-fast: false + # The keys of `pages` and `policy` in lighthouserc.cjs; + # tests/unit/lighthouse-scores.test.ts keeps them equal. + matrix: + page: [home, blog, post, faq, bench, chart, methodology] + profile: [desktop, mobile] + steps: + # The commit Vercel built the preview from (a PR's head commit, not + # the merge commit a pull_request checkout defaults to): the config + # must describe the app it audits (a post only on main would be a 404). + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + ref: ${{ inputs.sha }} + persist-credentials: false + + # The proxy and lighthouserc.cjs use only Node's built-in modules, so + # this job needs no `bun install`. + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 + with: + node-version-file: .nvmrc + + # zizmor's self-repository audit suggests a newer `$/` syntax. The `./` + # form loads the action from the workspace, which this job's first + # step checks out at the audited commit, the commit this workflow + # file comes from, and no earlier step writes to `.github/actions`. + - uses: ./.github/actions/preview-proxy # zizmor: ignore[self-repository] + with: + sha: ${{ inputs.sha }} + bypass-secret: ${{ secrets.bypass-secret }} + + # Request the page once, so no Lighthouse run measures a cold start. + # The chart job audits the first chart bench lists, and finds none on + # a database with no charts. + - name: Pick the page and warm it + id: page + env: + PAGE: ${{ matrix.page }} + run: | + path="$(node -p "require('./lighthouserc.cjs').pages['${PAGE}'] ?? ''")" + if [ "${PAGE}" = chart ]; then + slug="$(curl -sf "${PROXY}/bench/api/groups" \ + | jq -r '[.groups[] | select(.charts | length > 0)][0].charts[0].slug // empty')" + if [ -z "${slug}" ]; then + echo "::notice::bench lists no charts, so there is no chart page to audit." + exit 0 + fi + echo "chart=/chart/${slug}" >> "$GITHUB_OUTPUT" + path="/bench/chart/${slug}" + fi + if [ -z "${path}" ]; then + echo "::notice::There is no ${PAGE} page to audit." + exit 0 + fi + echo "path=${path}" >> "$GITHUB_OUTPUT" + curl -s -o /dev/null -w "%{http_code} %{time_total}s ${path}\n" "${PROXY}${path}" + + # The action runs Lighthouse against the page, asserts the thresholds + # and writes the reports to .lighthouseci/. They stay out of + # Lighthouse's public report storage, because the pages come from the + # protected preview. Threshold rationale lives in lighthouserc.cjs. + - name: Lighthouse CI + if: steps.page.outputs.path != '' + uses: treosh/lighthouse-ci-action@3e7e23fb74242897f95c0ba9cabad3d0227b9b18 # v12 + env: + BASE_URL: ${{ env.PROXY }} + LHCI_PAGE: ${{ matrix.page }} + LHCI_PROFILE: ${{ matrix.profile }} + BENCH_CHART_PATH: ${{ steps.page.outputs.chart }} + LHCI_RUNS: ${{ inputs.runs }} + LHCI_BASELINE: ${{ inputs.baseline && '1' || '' }} + with: + configPath: ./lighthouserc.cjs + uploadArtifacts: false + + # The full reports hold screenshots and page details of the protected + # preview, and anyone signed in to GitHub can download a public + # repository's artifacts, so they stay on the runner. This step checks + # that each report is an audit of the page on this job's profile, and + # keeps only its scores, metric values and the IDs of its failed + # audits, which it also prints. See scripts/lighthouse-scores.mjs. + - name: Check the reports and keep the scores + if: always() && steps.page.outputs.path != '' + env: + BASE_URL: ${{ env.PROXY }} + LHCI_PAGE: ${{ matrix.page }} + LHCI_PROFILE: ${{ matrix.profile }} + BENCH_CHART_PATH: ${{ steps.page.outputs.chart }} + LHCI_RUNS: ${{ inputs.runs }} + run: node scripts/lighthouse-scores.mjs keep "${RUNNER_TEMP}/lighthouse-scores" + + # Uploaded when the assertions fail too. + - name: Upload the scores + if: always() && steps.page.outputs.path != '' + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: lighthouse-${{ matrix.page }}-${{ matrix.profile }} + path: ${{ runner.temp }}/lighthouse-scores/ + if-no-files-found: ignore + retention-days: 7 diff --git a/.github/workflows/lighthouse-baseline.yml b/.github/workflows/lighthouse-baseline.yml new file mode 100644 index 0000000..6f58711 --- /dev/null +++ b/.github/workflows/lighthouse-baseline.yml @@ -0,0 +1,80 @@ +name: Lighthouse baseline + +# A baseline: a manual run on a branch with a Vercel preview, such as an +# open PR's branch. It audits every page on both profiles with more runs, +# asserts nothing, and posts no comment; the run's summary shows each +# page's scores and metric values, to calibrate the floors in +# lighthouserc.cjs. Run it with `gh workflow run lighthouse-baseline.yml +# --ref `. +# +# This is its own workflow, apart from lighthouse.yml, so that no run of it +# has a job named "Lighthouse and axe": a skipped job still reports a check +# under its name, and a skipped required check passes, so a baseline run in +# that workflow could stand in for the required check on the PR's commit. +on: + workflow_dispatch: + inputs: + runs: + description: Lighthouse runs for each page and profile + type: number + default: 5 + +permissions: + contents: read + +concurrency: + group: lighthouse-baseline-${{ github.ref }} + cancel-in-progress: true + +jobs: + lighthouse: + name: Lighthouse + # zizmor's self-repository audit suggests a newer `$/` syntax. The `./` + # form runs the workflow from this commit, the one this file comes from. + uses: ./.github/workflows/lighthouse-audit.yml # zizmor: ignore[self-repository] + permissions: + contents: read + deployments: read + with: + sha: ${{ github.sha }} + runs: ${{ inputs.runs }} + baseline: true + secrets: + bypass-secret: ${{ secrets.VERCEL_AUTOMATION_BYPASS_SECRET }} + + # The summary: the scores and metric values of every page on both + # profiles, across the runs. + baseline: + name: Lighthouse baseline + needs: [lighthouse] + if: ${{ !cancelled() }} + runs-on: ubuntu-26.04 + timeout-minutes: 10 + permissions: + contents: read + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + sparse-checkout: | + scripts/lighthouse-scores.mjs + sparse-checkout-cone-mode: false + + - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 + with: + pattern: lighthouse-* + path: reports + + - name: Summarize the runs + run: | + shopt -s nullglob + reports=(reports/*/lhr-*.json) + if [ "${#reports[@]}" -eq 0 ]; then exit 0; fi + node scripts/lighthouse-scores.mjs summary "${reports[@]}" >> "$GITHUB_STEP_SUMMARY" + + - name: Require every audit to pass + env: + LIGHTHOUSE: ${{ needs.lighthouse.result }} + run: | + echo "Lighthouse: ${LIGHTHOUSE}" + [ "${LIGHTHOUSE}" = success ] diff --git a/.github/workflows/lighthouse.yml b/.github/workflows/lighthouse.yml index dd9a9e2..cd73b73 100644 --- a/.github/workflows/lighthouse.yml +++ b/.github/workflows/lighthouse.yml @@ -1,27 +1,19 @@ name: Lighthouse # Lighthouse and axe for both sites, on each pull request's Vercel preview. -# bench renders from its database, which only a deployment has, so the jobs -# audit the site and bench together there, instead of a local build. +# The Lighthouse jobs come from lighthouse-audit.yml, one page and profile +# each; axe runs in another job at the same time, on its own runner, since a +# second browser on the same CPU would skew Lighthouse's timings. The +# `report` job, the required check "Lighthouse and axe", collects their +# results on every pull request. # -# Each page gets its own Lighthouse job, and axe runs in another, all at the -# same time. They can't share a runner: a second audit or browser on the same -# CPU would skew Lighthouse's timings. The `report` job, the required check -# "Lighthouse and axe", collects their results. +# A baseline (every page on both profiles with more runs, no assertions) is +# lighthouse-baseline.yml, a manual run on a branch with a preview. It is a +# separate workflow so that no run of it has a job named "Lighthouse and +# axe": a skipped job still reports a check under its name, and a skipped +# required check passes. on: pull_request: - # Baseline: a manual run on a branch with a Vercel preview, such as an open - # PR's branch. It audits every page on both profiles with more runs, asserts - # nothing, and posts no comment; the run's summary shows each page's - # scores and metric values, to calibrate the floors in lighthouserc.cjs. - # Its check is named "Lighthouse baseline", so it never stands in for the - # required "Lighthouse and axe". - workflow_dispatch: - inputs: - runs: - description: Lighthouse runs for each page and profile - type: number - default: 5 permissions: contents: read @@ -37,117 +29,21 @@ env: jobs: lighthouse: - name: Lighthouse (${{ matrix.page }}, ${{ matrix.profile }}) + name: Lighthouse # Fork PRs and Dependabot's PRs get no secrets, so they can't reach the - # protected preview. The jobs are skipped for them, which counts as - # passing for the required check. - if: github.event_name == 'workflow_dispatch' || (github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]') - runs-on: ubuntu-26.04 - timeout-minutes: 30 + # protected preview. The audits are skipped for them, and the `report` + # job below passes a PR whose audits were all skipped for that reason. + if: github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]' + # zizmor's self-repository audit suggests a newer `$/` syntax. The `./` + # form runs the workflow from this commit, the one this file comes from. + uses: ./.github/workflows/lighthouse-audit.yml # zizmor: ignore[self-repository] permissions: contents: read deployments: read - strategy: - fail-fast: false - # The keys of `pages` and `policy` in lighthouserc.cjs; - # tests/unit/lighthouse-scores.test.ts keeps them equal. - matrix: - page: [home, blog, post, faq, bench, chart, methodology] - profile: [desktop, mobile] - steps: - # The PR's head commit, which Vercel built the preview from, not the - # merge commit a pull_request checkout defaults to: the config must - # describe the app it audits (a post only on main would be a 404). A - # baseline audits the branch's head commit. - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - ref: ${{ github.event.pull_request.head.sha || github.sha }} - persist-credentials: false - - # The proxy and lighthouserc.cjs use only Node's built-in modules, so - # this job needs no `bun install`. - - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 - with: - node-version-file: .nvmrc - - # zizmor's self-repository audit suggests a newer `$/` syntax. The `./` - # form loads the action from the workspace, which this job's first - # step checks out at the PR's head commit, the commit this workflow - # file comes from, and no earlier step writes to `.github/actions`. - - uses: ./.github/actions/preview-proxy # zizmor: ignore[self-repository] - with: - sha: ${{ github.event.pull_request.head.sha || github.sha }} - bypass-secret: ${{ secrets.VERCEL_AUTOMATION_BYPASS_SECRET }} - - # Request the page once, so no Lighthouse run measures a cold start. - # The chart job audits the first chart bench lists, and finds none on - # a database with no charts. - - name: Pick the page and warm it - id: page - env: - PAGE: ${{ matrix.page }} - run: | - path="$(node -p "require('./lighthouserc.cjs').pages['${PAGE}'] ?? ''")" - if [ "${PAGE}" = chart ]; then - slug="$(curl -sf "${PROXY}/bench/api/groups" \ - | jq -r '[.groups[] | select(.charts | length > 0)][0].charts[0].slug // empty')" - if [ -z "${slug}" ]; then - echo "::notice::bench lists no charts, so there is no chart page to audit." - exit 0 - fi - echo "chart=/chart/${slug}" >> "$GITHUB_OUTPUT" - path="/bench/chart/${slug}" - fi - if [ -z "${path}" ]; then - echo "::notice::There is no ${PAGE} page to audit." - exit 0 - fi - echo "path=${path}" >> "$GITHUB_OUTPUT" - curl -s -o /dev/null -w "%{http_code} %{time_total}s ${path}\n" "${PROXY}${path}" - - # The action runs Lighthouse against the page, asserts the thresholds - # and writes the reports to .lighthouseci/. They stay out of - # Lighthouse's public report storage, because the pages come from the - # protected preview. Threshold rationale lives in lighthouserc.cjs. - - name: Lighthouse CI - if: steps.page.outputs.path != '' - uses: treosh/lighthouse-ci-action@3e7e23fb74242897f95c0ba9cabad3d0227b9b18 # v12 - env: - BASE_URL: ${{ env.PROXY }} - LHCI_PAGE: ${{ matrix.page }} - LHCI_PROFILE: ${{ matrix.profile }} - BENCH_CHART_PATH: ${{ steps.page.outputs.chart }} - LHCI_RUNS: ${{ inputs.runs || 3 }} - LHCI_BASELINE: ${{ github.event_name == 'workflow_dispatch' && '1' || '' }} - with: - configPath: ./lighthouserc.cjs - uploadArtifacts: false - - # The full reports hold screenshots and page details of the protected - # preview, and anyone signed in to GitHub can download a public - # repository's artifacts, so they stay on the runner. This step checks - # that each report is an audit of the page on this job's profile, and - # keeps only its scores, metric values and the IDs of its failed - # audits, which it also prints. See scripts/lighthouse-scores.mjs. - - name: Check the reports and keep the scores - if: always() && steps.page.outputs.path != '' - env: - BASE_URL: ${{ env.PROXY }} - LHCI_PAGE: ${{ matrix.page }} - LHCI_PROFILE: ${{ matrix.profile }} - BENCH_CHART_PATH: ${{ steps.page.outputs.chart }} - LHCI_RUNS: ${{ inputs.runs || 3 }} - run: node scripts/lighthouse-scores.mjs keep "${RUNNER_TEMP}/lighthouse-scores" - - # Uploaded when the assertions fail too. - - name: Upload the scores - if: always() && steps.page.outputs.path != '' - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 - with: - name: lighthouse-${{ matrix.page }}-${{ matrix.profile }} - path: ${{ runner.temp }}/lighthouse-scores/ - if-no-files-found: ignore - retention-days: 7 + with: + sha: ${{ github.event.pull_request.head.sha }} + secrets: + bypass-secret: ${{ secrets.VERCEL_AUTOMATION_BYPASS_SECRET }} axe: name: axe @@ -259,13 +155,22 @@ jobs: path: test-results/ retention-days: 7 - # The required check. It runs when a job above fails, so the comment still - # shows which page regressed, and it fails unless every job above passed. - # It is skipped with them for fork and Dependabot PRs. + # The required check "Lighthouse and axe". It runs on every pull request, + # including one where the jobs above were skipped (a fork's or + # Dependabot's), and when one of them failed, so the comment still shows + # which page regressed. It passes when every job above passed, or when + # all of them were skipped because the PR gets no secrets; it fails + # otherwise. + # + # The name is a literal, and must stay one: GitHub evaluates a job's `name` + # only when the job runs, so a skipped job with an expression for a name + # reports its check under the unevaluated text, and a ruleset that waits + # for this job's name then waits forever. tests/unit/required-checks.test.ts + # checks that every required check is a literal job name. report: - name: ${{ github.event_name == 'workflow_dispatch' && 'Lighthouse baseline' || 'Lighthouse and axe' }} + name: Lighthouse and axe needs: [lighthouse, axe] - if: ${{ !cancelled() && (github.event_name == 'workflow_dispatch' || (github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]')) }} + if: ${{ !cancelled() }} runs-on: ubuntu-26.04 timeout-minutes: 10 permissions: @@ -274,14 +179,16 @@ jobs: steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: - ref: ${{ github.event.pull_request.head.sha || github.sha }} + ref: ${{ github.event.pull_request.head.sha }} persist-credentials: false sparse-checkout: | scripts/lighthouse-comment.sh scripts/lighthouse-scores.mjs sparse-checkout-cone-mode: false + # Only a run of the Lighthouse jobs leaves reports to collect. - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 + if: needs.lighthouse.result != 'skipped' with: pattern: lighthouse-* path: reports @@ -299,7 +206,6 @@ jobs: # steps are non-fatal. - name: Format PR comment id: lh-comment - if: github.event_name == 'pull_request' continue-on-error: true run: | shopt -s nullglob @@ -319,12 +225,19 @@ jobs: header: lighthouse message: ${{ steps.lh-comment.outputs.body }} - # A baseline skips axe. + # Fork PRs and Dependabot's PRs get no secrets, so they can't reach the + # protected preview; the jobs above are skipped for them, and that is + # a pass. Any other skip, or a failure, fails the check. - name: Require every job to pass env: LIGHTHOUSE: ${{ needs.lighthouse.result }} AXE: ${{ needs.axe.result }} - BASELINE: ${{ github.event_name == 'workflow_dispatch' }} + NO_SECRETS: ${{ github.event.pull_request.head.repo.full_name != github.repository || github.actor == 'dependabot[bot]' }} run: | echo "Lighthouse: ${LIGHTHOUSE}, axe: ${AXE}" - [ "${LIGHTHOUSE}" = success ] && { [ "${AXE}" = success ] || [ "${BASELINE}" = true ]; } + if [ "${NO_SECRETS}" = true ]; then + echo "This PR gets no secrets, so the audits were skipped." + [ "${LIGHTHOUSE}" = skipped ] && [ "${AXE}" = skipped ] + else + [ "${LIGHTHOUSE}" = success ] && [ "${AXE}" = success ] + fi diff --git a/CLAUDE.md b/CLAUDE.md index a94dfe2..5251ab4 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -29,7 +29,7 @@ How the two sites share the app: - **Headers.** The CSP and the other security headers in `next.config.mjs` cover both sites: one policy, since both self-host their fonts. bench now sends the site's security headers, including `X-Frame-Options: DENY` and `frame-ancestors 'none'`, so no other site can embed bench's pages in a frame. `vercel.json` holds bench's cron (`/bench/api/health`) and bench's CDN rule for its landing, chart, and methodology pages on bench.vortex.dev (header rules match the path as requested, before the rewrites). bench's HTML differs between its two URL forms, so the `/bench` form gets the CDN rule only outside production (`benchPrefixCdnRules` in `next.config.mjs`): a cached `/bench` page must never answer for bench.vortex.dev. - **Toolchain.** One package: one `package.json`, one `bun.lock`, one `bunfig.toml`, one `tsconfig.json`. Next.js 16.4.1, React 19.3 and TypeScript 7. `tsconfig.json` has every strict flag either app had, including bench's `noFallthroughCasesInSwitch` and `noUncheckedSideEffectImports`; `src/css.d.ts` types the CSS side-effect imports. The root `biome.json` lints and formats both sites: an override keeps bench's files (`src/bench`, `src/app/(bench)`, the parity and deploy checks, `vitest.config.ts`) in bench's old Prettier style (single quotes, trailing commas, 100 columns) with bench's lint rules (see "bench" below), and `bun run check:ci` checks all of it. bench's tests run on Vitest from the root `vitest.config.ts`, scoped to bench's files; the site's run on `bun test`. bench's PostCSS config sits beside its stylesheets (`src/bench/styles/postcss.config.mjs`), and Turbopack applies it to those alone: with no config at the root, the site's CSS gets Turbopack's defaults. - **CI.** Every check covers both sites and runs on every change; nothing is split by which site a change touches. `ci.yml`'s `Lint, build, verify` first lints the workflows with actionlint and zizmor (images pinned by digest; justify a zizmor exception beside its line as `# zizmor: ignore[audit] reason`), then runs Biome on the whole repository, one build, the typecheck, knip, the site's unit tests, bench's Vitest suite with its Postgres integration tests (testcontainers, so the runner needs Docker), the migration-runner (`db/tests`), infrastructure (`infra/tests`), parity and deploy-check tests, `bun run verify`, the Playwright smoke specs, and `bun audit`, which fails the job on any advisory (see "Audit advisories"). The smoke specs run in Microsoft's Playwright image, pinned by digest, so no step runs apt; the tag must name the installed `@playwright/test`, and Renovate moves both in one PR. CI retries a failed browser test once for diagnosis, but a test that passes only on retry still fails (`failOnFlakyTests`), and the JSON report (`test-results/results.json`) uploads on every run. Dependency review, the secret scan and REUSE run beside it. `links.yml` checks the blog's external links with lychee each week and on a PR that changes `src/content/`; it is not a required check, so a broken link on another site never blocks a merge. -- **Lighthouse and axe.** `lighthouse.yml` audits both sites on the pull request's Vercel preview, because bench renders from its database and only a deployment has one. Its jobs run in parallel, each on its own runner, since a second audit or browser on the same CPU would skew Lighthouse's timings. Each one waits for the preview (Vercel's GitHub deployment in the `Preview` environment, through the `.github/actions/preview-proxy` action) and requests its page once to get past the cold start. Fourteen Lighthouse jobs each audit one page on one profile, named by `LHCI_PAGE` and `LHCI_PROFILE`: `/`, `/blog`, the newest post, `/faq`, `/bench`, one bench chart page and `/bench/methodology`, each on desktop (Lighthouse's desktop preset) and mobile (its default phone, on slow 4G with a 4× CPU slowdown). `lighthouserc.cjs` holds the pages and, for each profile, the floors and metric caps with their rationale; a page can override them, with a reason. `scripts/lighthouse-scores.mjs` fails a job whose reports are not audits of its page on its profile (a redirect, a document that is not HTTP 200, a runtime error, the wrong device settings, or a missing run), and keeps each run's scores, metric values and failed audit IDs. A manual run of the workflow is a baseline: more runs (5 by default), no assertions, and a summary table to calibrate the floors from, under the check name `Lighthouse baseline`, which can't satisfy the required check. Run it on a branch that has a preview: `gh workflow run lighthouse.yml --ref `. The `axe` job runs `tests/a11y.spec.ts` in the same Playwright image as `ci.yml` (`--grep @axe`: WCAG 2.1 A and AA, and a serious or critical violation fails). The `report` job, the required check `Lighthouse and axe`, posts one score table on the PR from the Lighthouse jobs' reports and fails unless every job passed. The preview is reached through `scripts/preview-proxy.mjs`, which adds the `VERCEL_AUTOMATION_BYPASS_SECRET` header only to requests for the preview, so no other origin a page loads from sees it. The proxy reads the secret on standard input and refuses to start with the variable in its environment, because the audits run third-party code as the same user, and it forwards only to an HTTPS `*.vercel.app` deployment. Lighthouse blocks `vercel.live` and `pusher.com`, the hosts of Vercel's preview-only Toolbar: the Toolbar can set a third-party cookie that drops best practices to 0.78 on every page. Fork and Dependabot PRs get no secrets, so the jobs are skipped for them, which counts as passing. The smoke run in `ci.yml` leaves the axe specs out (`--grep-invert @axe`). To run axe yourself: `BASE_URL=https://vortex.dev BENCH_URL=https://bench.vortex.dev bunx playwright test --grep @axe`. +- **Lighthouse and axe.** `lighthouse.yml` audits both sites on the pull request's Vercel preview, because bench renders from its database and only a deployment has one. Its Lighthouse jobs come from the reusable `lighthouse-audit.yml`, and run in parallel with axe, each on its own runner, since a second audit or browser on the same CPU would skew Lighthouse's timings. Each one waits for the preview (Vercel's GitHub deployment in the `Preview` environment, through the `.github/actions/preview-proxy` action) and requests its page once to get past the cold start. Fourteen Lighthouse jobs each audit one page on one profile, named by `LHCI_PAGE` and `LHCI_PROFILE`: `/`, `/blog`, the newest post, `/faq`, `/bench`, one bench chart page and `/bench/methodology`, each on desktop (Lighthouse's desktop preset) and mobile (its default phone, on slow 4G with a 4× CPU slowdown). `lighthouserc.cjs` holds the pages and, for each profile, the floors and metric caps with their rationale; a page can override them, with a reason. `scripts/lighthouse-scores.mjs` fails a job whose reports are not audits of its page on its profile (a redirect, a document that is not HTTP 200, a runtime error, the wrong device settings, or a missing run), and keeps each run's scores, metric values and failed audit IDs. `lighthouse-baseline.yml` is a manual baseline: the same audits with more runs (5 by default), no assertions, and a summary table to calibrate the floors from, under the check name `Lighthouse baseline`. It is a separate workflow so that no baseline run has a job named `Lighthouse and axe`, since a skipped job still reports a check under its name and a skipped required check passes. Run it on a branch that has a preview: `gh workflow run lighthouse-baseline.yml --ref `. The `axe` job runs `tests/a11y.spec.ts` in the same Playwright image as `ci.yml` (`--grep @axe`: WCAG 2.1 A and AA, and a serious or critical violation fails). The `report` job, the required check `Lighthouse and axe`, runs on every pull request: it posts one score table on the PR from the Lighthouse jobs' reports and fails unless every job passed. The preview is reached through `scripts/preview-proxy.mjs`, which adds the `VERCEL_AUTOMATION_BYPASS_SECRET` header only to requests for the preview, so no other origin a page loads from sees it. The proxy reads the secret on standard input and refuses to start with the variable in its environment, because the audits run third-party code as the same user, and it forwards only to an HTTPS `*.vercel.app` deployment. Lighthouse blocks `vercel.live` and `pusher.com`, the hosts of Vercel's preview-only Toolbar: the Toolbar can set a third-party cookie that drops best practices to 0.78 on every page. Fork and Dependabot PRs get no secrets, so the audits are skipped for them, and `report` passes a PR whose audits were all skipped for that reason. Every required check's job has a literal `name`: GitHub evaluates an expression in a job's name only when the job runs, so a skipped job reports under the unevaluated text, and the ruleset would wait for the literal name forever (the first fork PR, #243, stalled that way); `tests/unit/required-checks.test.ts` checks the names, and its list mirrors the ruleset's. The smoke run in `ci.yml` leaves the axe specs out (`--grep-invert @axe`). To run axe yourself: `BASE_URL=https://vortex.dev BENCH_URL=https://bench.vortex.dev bunx playwright test --grep @axe`. - **Deploys.** The `vortex` Vercel project builds and deploys the app, both sites, through the git integration, on every commit. `bench-verify-deploy.yml` runs on each push to `main`: it waits for that commit's production deployment, as `lighthouse.yml` waits for a preview, then runs `scripts/verify-web-deploy.mjs` against bench under `/bench` on the deployment's own URL. It runs on push rather than on `deployment_status`, so pull requests show no skipped run of it. Schema migrations go through `bench-schema-deploy.yml`, which only runs manually from `main` because the AWS role trusts nothing else. ## Architecture Overview @@ -156,7 +156,7 @@ Defense in depth against the npm-worm class (Shai-Hulud, mini-Shai-Hulud, the Ma 6. **`trufflesecurity/trufflehog`** secret scan runs on every PR and push to main. Defense-in-depth on top of GitHub's push protection; catches verified secrets that slipped past push protection (low-entropy formats, detector patterns added after the secret was committed, or push-protection bypass). 7. **OpenSSF Scorecard** (`.github/workflows/scorecard.yml`) grades the repo weekly on supply-chain hygiene (pinned actions, branch protection, token permissions, dangerous workflow patterns). SARIF posts to the Security tab; aggregate score publishes to https://scorecard.dev. 8. **All third-party GitHub Actions are SHA-pinned**, not tag-pinned. A tag can be moved to point at a malicious commit (and has been, in prior supply-chain incidents); a SHA can't. Renovate's `helpers:pinGitHubActionDigests` preset enforces this on auto-bump PRs. When bumping an action manually, update both the SHA and the trailing `# vX.Y.Z` comment in the same diff. The Docker images that CI runs (Playwright, actionlint and zizmor) are pinned by tag and digest in env vars, and `customManagers` in `renovate.json` updates them. -9. **Pinned runner images** (never `ubuntu-latest`), so runner-image bumps are deliberate PRs, not silent infrastructure drift. The checks (`ci.yml`, `lighthouse.yml`) and the repository-wide workflows (`dependency-snapshot.yml`, `scorecard.yml`, `claude.yml`, `links.yml`) run on `ubuntu-26.04`, including bench's Docker (testcontainers) Postgres suite. bench's operational workflows run on `ubuntu-24.04`: `bench-verify-deploy.yml`, `bench-keep-warm.yml` and `bench-schema-deploy.yml`. Move them to 26.04 in a PR of their own. The Node version inside the runner image can still drift; `.nvmrc` pins that separately. +9. **Pinned runner images** (never `ubuntu-latest`), so runner-image bumps are deliberate PRs, not silent infrastructure drift. The checks (`ci.yml`, `lighthouse.yml`, `lighthouse-audit.yml`, `lighthouse-baseline.yml`) and the repository-wide workflows (`dependency-snapshot.yml`, `scorecard.yml`, `claude.yml`, `links.yml`) run on `ubuntu-26.04`, including bench's Docker (testcontainers) Postgres suite. bench's operational workflows run on `ubuntu-24.04`: `bench-verify-deploy.yml`, `bench-keep-warm.yml` and `bench-schema-deploy.yml`. Move them to 26.04 in a PR of their own. The Node version inside the runner image can still drift; `.nvmrc` pins that separately. ### Node version @@ -167,7 +167,7 @@ Three places must agree with each other and with what Vercel runs. Vercel offers - `@types/node` → `^26`, matching the runtime so `tsc` cannot green-light an API that production does not have. Keep them in lockstep when bumping, and move to a new major only after Vercel offers it; check https://vercel.com/docs/functions/runtimes/node-js/node-js-versions first. -10. **Renovate auto-merge** is patch + minor only via `:automergeStableNonMajor`. Major bumps stay open for human review. The 7-day cooldown is the first gate, and the required checks on `main` are the second. Renovate merges through GitHub's auto-merge, which waits only for required checks: `Lint, build, verify` (lint, build, typecheck, both sites' tests, `bun run verify` and Playwright), `dependency-review`, `secret-scan`, `DCO`, `REUSE compliance`, `Submit bun.lock`, `Lighthouse and axe` and `Vercel`, plus a CodeQL code scanning rule. The `Vercel` check is the `vortex` project's preview deployment, which now builds bench too. `bun audit` runs in `Lint, build, verify`, so an advisory holds an auto-merge too. `claude.yml` does not start for an issue or PR that Renovate opened, so Claude cannot push a commit to a branch that then merges without a person. Lighthouse takes the best of three runs per URL, so one slow shared runner doesn't fail it. A Renovate PR runs `Lighthouse and axe` like any same-repository PR; a Dependabot PR skips it. Lock file maintenance automerges too. Renovate cannot apply `minimumReleaseAge` to a Bun lock refresh, so `renovate.json` turns it off for that update type; `bunfig.toml` enforces the same wait while Bun regenerates `bun.lock`. `biome.json` takes its `$schema` from the installed `@biomejs/biome` package rather than a versioned URL, so a Biome update can't fail on a schema version mismatch, and it leaves Markdown and YAML alone, as Biome 2.5 did. +10. **Renovate auto-merge** is patch + minor only via `:automergeStableNonMajor`. Major bumps stay open for human review. The 7-day cooldown is the first gate, and the required checks on `main` are the second. Renovate merges through GitHub's auto-merge, which waits only for required checks: `Lint, build, verify` (lint, build, typecheck, both sites' tests, `bun run verify` and Playwright), `dependency-review`, `secret-scan`, `DCO`, `REUSE compliance`, `Submit bun.lock`, `Lighthouse and axe` and `Vercel`, plus a CodeQL code scanning rule. The `Vercel` check is the `vortex` project's preview deployment, which now builds bench too. `bun audit` runs in `Lint, build, verify`, so an advisory holds an auto-merge too. `claude.yml` does not start for an issue or PR that Renovate opened, so Claude cannot push a commit to a branch that then merges without a person. Lighthouse takes the best of three runs per URL, so one slow shared runner doesn't fail it. A Renovate PR runs `Lighthouse and axe` like any same-repository PR; a Dependabot PR's audits are skipped and the check passes. Lock file maintenance automerges too. Renovate cannot apply `minimumReleaseAge` to a Bun lock refresh, so `renovate.json` turns it off for that update type; `bunfig.toml` enforces the same wait while Bun regenerates `bun.lock`. `biome.json` takes its `$schema` from the installed `@biomejs/biome` package rather than a versioned URL, so a Biome update can't fail on a schema version mismatch, and it leaves Markdown and YAML alone, as Biome 2.5 did. ### Linker and lifecycle scripts diff --git a/lighthouserc.cjs b/lighthouserc.cjs index d6d1997..b6aaf71 100644 --- a/lighthouserc.cjs +++ b/lighthouserc.cjs @@ -1,6 +1,6 @@ // Lighthouse CI config for both sites. CI audits the pull request's Vercel // preview, where bench has its database, through scripts/preview-proxy.mjs -// (see .github/workflows/lighthouse.yml): +// (see .github/workflows/lighthouse-audit.yml): // // BASE_URL where the app answers: the proxy in CI, or a server // you started, such as `bun run start` with bench's @@ -163,7 +163,7 @@ if (!profileSettings[profile]) { // mobile performance floor is 0.8, and each metric cap is about 1.3 to 2 // times the worst value above. Accessibility and SEO were 1.00 in every run. // -// Recalibrate from a baseline run (see "Baseline" in lighthouse.yml), and +// Recalibrate from a baseline run (lighthouse-baseline.yml), and // don't relax a value to mask a regression without a separate PR. const policy = { desktop: { diff --git a/tests/unit/lighthouse-scores.test.ts b/tests/unit/lighthouse-scores.test.ts index 3e125ef..9221c76 100644 --- a/tests/unit/lighthouse-scores.test.ts +++ b/tests/unit/lighthouse-scores.test.ts @@ -164,7 +164,10 @@ describe("the Lighthouse floors", () => { pages: Record; policy: Policy; }; - const workflow = readFileSync(".github/workflows/lighthouse.yml", "utf8"); + const workflow = readFileSync( + ".github/workflows/lighthouse-audit.yml", + "utf8" + ); it("give each page override a reason, and only known keys", () => { for (const [profile, { defaults, pages }] of Object.entries( diff --git a/tests/unit/required-checks.test.ts b/tests/unit/required-checks.test.ts new file mode 100644 index 0000000..1d87c85 --- /dev/null +++ b/tests/unit/required-checks.test.ts @@ -0,0 +1,106 @@ +/** + * Every required check is a literal job name. + * + * The `main` ruleset waits for a fixed list of check names. A GitHub Actions + * job reports its check under its `name`, or its id when it has none. GitHub + * evaluates an expression in `name` only when the job runs: a job whose `if` + * is false reports its check under the unevaluated text instead. A required + * check named by an expression therefore never reports on a pull request + * that skips the job, and the ruleset waits forever. The first fork PR + * (vortex-data/vortex.dev#243) stalled that way on "Lighthouse and axe". + * + * These tests read the workflows and check that each name the ruleset + * requires of a workflow is a job's literal name. The list here mirrors the + * ruleset; change both together. The other required checks, `DCO` and + * `Vercel`, come from apps, not workflows. + */ + +import assert from "node:assert/strict"; +import { readdirSync, readFileSync } from "node:fs"; +import { join } from "node:path"; +import { describe, it } from "node:test"; + +const WORKFLOWS = ".github/workflows"; + +// The required status checks of the `main` ruleset that workflows report. +const REQUIRED = [ + "Lint, build, verify", + "dependency-review", + "secret-scan", + "REUSE compliance", + "Submit bun.lock", + "Lighthouse and axe" +]; + +// The start of the `jobs:` block, a job's id (two spaces in), and a job's +// `name:` (four spaces in). A step's `name:` sits deeper. +const JOBS = /^jobs:[ \t]*$/; +const JOB_ID = /^ {2}([A-Za-z_][\w-]*):[ \t]*$/; +const JOB_NAME = /^ {4}name:[ \t]*(.*?)[ \t]*$/; + +/** The check name each job in a workflow reports under. */ +function checkNames(source: string): string[] { + const names: string[] = []; + let inJobs = false; + let id: string | null = null; + let named = false; + const close = () => { + if (id !== null && !named) names.push(id); + }; + for (const line of source.split("\n")) { + if (!inJobs) { + inJobs = JOBS.test(line); + continue; + } + const job = JOB_ID.exec(line); + if (job) { + close(); + id = job[1] ?? null; + named = false; + continue; + } + const name = JOB_NAME.exec(line); + if (name && id !== null) { + names.push(unquote(name[1] ?? "")); + named = true; + } + } + close(); + return names; +} + +function unquote(value: string): string { + const quoted = /^(["'])(.*)\1$/.exec(value); + return quoted ? (quoted[2] ?? "") : value; +} + +describe("the required checks", () => { + const names = readdirSync(WORKFLOWS) + .filter((file) => file.endsWith(".yml")) + .flatMap((file) => checkNames(readFileSync(join(WORKFLOWS, file), "utf8"))); + + it("are found in the workflows", () => { + assert.ok(names.length > 0, "no jobs found under .github/workflows"); + }); + + for (const context of REQUIRED) { + it(`"${context}" is a literal job name`, () => { + assert.ok( + names.includes(context), + `No job is named "${context}". A name built from an expression is not evaluated when the job is skipped, so the ruleset would wait for it forever.` + ); + }); + } + + it("are not named inside an expression", () => { + const dynamic = names.filter((name) => name.includes("${{")); + for (const context of REQUIRED) { + const hit = dynamic.find((name) => name.includes(context)); + assert.equal( + hit, + undefined, + `A job name expression contains the required check "${context}": ${hit}` + ); + } + }); +});