From adbf3f9f29eb75798c42723a47af2d6d9b25ef8e Mon Sep 17 00:00:00 2001 From: Mindaugas Date: Tue, 17 Nov 2026 21:12:57 +0200 Subject: [PATCH] ci: build e2e once across 12 shards, a 90 s first signal, and releases that reuse CI (#256) No test is dropped; only the scheduling changes. - e2e: one job builds the bundle and every shard downloads it. Building in each shard was most of its fixed cost, so 12 shards now pay where 4 used to. - quick: lint, the guards and the unit tests without coverage report in about 90 s. check still runs the full gate on ubuntu and windows. - CI runs e2e on the merge commit too, which is the commit a release tags. The release's new gate job always runs the dependency audit, waits for CI on the tagged commit, and reuses it only when every quick, check and e2e job passed there. A direct push, a tag on an arbitrary commit, or anything not green re-runs the suite in the release as before. Jobs after build check their direct parent, so a skipped test job does not silently skip them. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01PJaGuL4V5ghYxXSGoyYU8n --- .github/workflows/ci.yml | 63 +++++++++++++++++----- .github/workflows/release.yml | 75 +++++++++++++++++++-------- scripts/lib/releaseVerified.mjs | 12 +++++ scripts/release-verified.mjs | 35 +++++++++++++ tests/scripts/releaseVerified.test.js | 36 +++++++++++++ 5 files changed, 187 insertions(+), 34 deletions(-) create mode 100644 scripts/lib/releaseVerified.mjs create mode 100644 scripts/release-verified.mjs create mode 100644 tests/scripts/releaseVerified.test.js diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e6343997..ecfcc460 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,8 +1,8 @@ name: CI # Lint + tests on every push and PR to main, so a broken build is caught before -# it can ever be tagged for release. The release workflow re-runs `npm run check` -# too, but this gives fast feedback and blocks merges. +# it can ever be tagged for release. A release reuses this run on the commit it +# tags when every job passed, and re-runs the suite itself otherwise. on: push: branches: [main] @@ -10,6 +10,23 @@ on: branches: [main] jobs: + # The first signal, in about 90 s: lint, the guards and the unit tests, without + # coverage or a build. `check` below still runs the whole gate. + quick: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + - uses: actions/setup-node@v5 + with: + node-version: 22 + cache: npm + - run: npm install -g npm@11 --no-fund --no-audit + - run: npm ci --no-fund + - run: npm run lint + - run: npm run check:styles && npm run check:themes && npm run check:structure + - run: npm run check:i18n && npm run check:rawtext + - run: npm test + # Both platforms the app ships on. Windows is here because the release build # used to be the ONLY job that ran `npm run check` there, and v0.4.10 walked # into three Windows-only failures one tag at a time — a deprecation the @@ -66,26 +83,42 @@ jobs: if: runner.os == 'Windows' run: node scripts/packaged-smoke.mjs dist + # One bundle for every shard: building in each shard was most of its fixed cost. + e2e-build: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v5 + - uses: actions/setup-node@v5 + with: + node-version: 22 + cache: npm + - run: npm install -g npm@11 --no-fund --no-audit + - run: npm ci --no-fund + - run: npm run build + - uses: actions/upload-artifact@v6 + with: + name: e2e-build + path: build/ + retention-days: 1 + # End-to-end tests drive the app's OWN Electron (Playwright `_electron`) under a # virtual display — no bundled browser, no network, same as the Docker test env. # 22.04 keeps the pre-t64 apt package names the app's Electron links against. # - # E2E is the behavioural source of truth: it runs as the merge gate on pull - # requests to main only (not on post-merge pushes — main is reached through a - # PR). Make it a required status check in the branch-protection rule for main - # so a red run blocks the merge. + # E2E is the behavioural source of truth. It gates pull requests, and it runs + # again on the merge commit: that is the commit a release tags, and the release + # reuses this result instead of re-running it (scripts/release-verified.mjs). e2e: - if: github.event_name == 'pull_request' + needs: e2e-build runs-on: ubuntu-22.04 strategy: # Every shard reports: a cancelled sibling hides which slice actually broke. fail-fast: false matrix: - # Playwright splits by FILE, the same axis the suite already parallelises - # on, so a spec's internal order — which the relaunch tests depend on — - # is preserved. Setup + build is ~1.2 min per shard and does not divide, - # so past ~6 shards the fixed cost starts eating the gain. - shard: [1, 2, 3, 4] + # Playwright splits by FILE, so a spec's internal order, which the + # relaunch tests depend on, is kept. With the bundle built once, a + # shard's fixed cost is ~40 s of setup, which is what makes 12 pay. + shard: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] env: # Never let Playwright pull Chromium/Firefox/WebKit — the suite uses none. PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: '1' @@ -120,10 +153,14 @@ jobs: # which starts a single display and owns DISPLAY itself. - name: Start a virtual display per worker run: bash scripts/e2e-displays.sh + - uses: actions/download-artifact@v6 + with: + name: e2e-build + path: build/ - name: Run end-to-end tests # job-total, not a literal: the shard count can only be wrong in one # place, and adding a shard to the matrix is the whole edit. - run: npm run test:e2e -- --shard=${{ matrix.shard }}/${{ strategy.job-total }} + run: npx playwright test --shard=${{ matrix.shard }}/${{ strategy.job-total }} - name: Packaged app starts clean if: matrix.shard == 1 env: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3e3082fc..b9beb1ff 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -8,13 +8,49 @@ on: - 'v*.*.*' jobs: - # Fail the whole release fast, on one cheap runner, if any known - # vulnerability is present — before spending Windows/macOS build minutes. - # E2E is the behavioural source of truth. On PRs it's the merge gate (see - # ci.yml); at release time we re-run it as a safety net so a tag can never - # ship without it — a direct push to main or a tag on an arbitrary commit - # would otherwise bypass the PR gate entirely. Same setup as ci.yml's e2e job. + # Always runs. The audit is never reused: an advisory can appear after CI ran. + # The tests are reused only when CI passed every job on the tagged commit itself + # (ci.yml runs the full suite on every push to main). A direct push, a tag on + # an arbitrary commit, or anything not green re-runs them here. + gate: + runs-on: ubuntu-latest + permissions: + actions: read + checks: read + contents: read + outputs: + verified: ${{ steps.ci.outputs.verified }} + steps: + - uses: actions/checkout@v5 + - uses: actions/setup-node@v5 + with: + node-version: 22 + + # Blocks the release when npm audit finds a vulnerability at or above the + # threshold in what the app SHIPS. Dev tools are deliberately out: a build + # tool's advisory can have no fix but a major its dependents cannot take, + # and overriding those is ruled out (docs/standards.md). So nothing here + # sees an advisory in eslint or electron-builder, at any severity. + # `--audit-level=low` fails on any advisory at all. + # + # FIRST, and --package-lock-only: this reads the lock and needs no + # node_modules at all. It used to be its own job that installed the whole + # 872MB tree to run a one-second check. Here it still fails the release + # before a single build minute is spent, ~15s in. + - name: Audit dependencies for known vulnerabilities + run: npm audit --package-lock-only --omit=dev --audit-level=moderate + + - name: Reuse CI on this commit if every job passed + id: ci + env: + GH_TOKEN: ${{ github.token }} + run: node scripts/release-verified.mjs + + # E2E is the behavioural source of truth. It runs here only when the gate could + # not reuse CI's run on the tagged commit. Same setup as ci.yml's e2e job. e2e: + needs: gate + if: needs.gate.outputs.verified != 'true' runs-on: ubuntu-22.04 strategy: # Every shard reports: a cancelled sibling hides which slice actually broke. @@ -82,6 +118,8 @@ jobs: # and ci.yml runs it on ubuntu AND windows for every push to main, which is the # commit a tag points at. check: + needs: gate + if: needs.gate.outputs.verified != 'true' runs-on: ubuntu-latest steps: - uses: actions/checkout@v5 @@ -90,26 +128,18 @@ jobs: node-version: 22 cache: npm - # Blocks the release when npm audit finds a vulnerability at or above the - # threshold in what the app SHIPS. Dev tools are deliberately out: a build - # tool's advisory can have no fix but a major its dependents cannot take, - # and overriding those is ruled out (docs/standards.md). So nothing here - # sees an advisory in eslint or electron-builder, at any severity. - # `--audit-level=low` fails on any advisory at all. - # - # FIRST, and --package-lock-only: this reads the lock and needs no - # node_modules at all. It used to be its own job that installed the whole - # 872MB tree to run a one-second check. Here it still fails the release - # before a single build minute is spent, ~15s in. - - name: Audit dependencies for known vulnerabilities - run: npm audit --package-lock-only --omit=dev --audit-level=moderate - - run: npm install -g npm@11 --no-fund --no-audit - run: npm ci --no-fund - run: npm run check build: - needs: [e2e, check] + needs: [gate, e2e, check] + # e2e and check are skipped when the gate reused CI; a skipped need would + # otherwise skip this job too. + if: >- + !cancelled() && needs.gate.result == 'success' && + (needs.gate.outputs.verified == 'true' || + (needs.e2e.result == 'success' && needs.check.result == 'success')) strategy: fail-fast: false matrix: @@ -196,6 +226,7 @@ jobs: release: needs: build + if: ${{ !cancelled() && needs.build.result == 'success' }} runs-on: ubuntu-latest # Explicit here rather than relying on the repo's default token # permissions, which may be read-only. @@ -229,6 +260,7 @@ jobs: # the App. Needs repo secret SYNC_APP_PRIVATE_KEY (the App's .pem). sync-version: needs: release + if: ${{ !cancelled() && needs.release.result == 'success' }} runs-on: ubuntu-latest steps: - name: Mint a token for the version-sync App @@ -274,6 +306,7 @@ jobs: # the release itself never fails on it. homebrew: needs: release + if: ${{ !cancelled() && needs.release.result == 'success' }} runs-on: ubuntu-latest steps: - uses: actions/checkout@v5 diff --git a/scripts/lib/releaseVerified.mjs b/scripts/lib/releaseVerified.mjs new file mode 100644 index 00000000..20fff5d3 --- /dev/null +++ b/scripts/lib/releaseVerified.mjs @@ -0,0 +1,12 @@ +const OURS = /^(quick|check|e2e)\b/ +const REQUIRED = ['check (ubuntu', 'check (windows', 'e2e ('] + +// Judges CI on the tagged commit itself, so nothing is assumed about how it was merged. +export function releaseVerdict(checkRuns) { + const ours = checkRuns.filter((run) => OURS.test(run.name)) + const missing = REQUIRED.filter((prefix) => !ours.some((run) => run.name.startsWith(prefix))) + if (missing.length) return { verified: false, why: `CI did not run: ${missing.join(', ')}` } + const notGreen = ours.filter((run) => run.conclusion !== 'success').map((run) => run.name) + if (notGreen.length) return { verified: false, why: `not green: ${notGreen.join(', ')}` } + return { verified: true, why: `CI passed ${ours.length} jobs on this commit` } +} diff --git a/scripts/release-verified.mjs b/scripts/release-verified.mjs new file mode 100644 index 00000000..fad7b783 --- /dev/null +++ b/scripts/release-verified.mjs @@ -0,0 +1,35 @@ +// Release gate: waits for CI on the tagged commit, then prints verified=true only if every job passed. +import { execFileSync } from 'node:child_process' +import { appendFileSync } from 'node:fs' +import { releaseVerdict } from './lib/releaseVerified.mjs' + +const WAIT_MS = 25 * 60 * 1000 +const POLL_MS = 30 * 1000 +const repo = process.env.GITHUB_REPOSITORY +const sha = process.env.GITHUB_SHA +const api = (path) => JSON.parse(execFileSync('gh', ['api', path], { encoding: 'utf8' })) +const sleep = (ms) => new Promise((done) => setTimeout(done, ms)) + +async function finishedCiRun() { + for (const deadline = Date.now() + WAIT_MS; Date.now() < deadline; await sleep(POLL_MS)) { + const { workflow_runs: runs } = api( + `repos/${repo}/actions/workflows/ci.yml/runs?head_sha=${sha}` + ) + if (!runs.length) return null + if (runs.every((run) => run.status === 'completed')) return runs + } + return null +} + +let verdict +try { + const runs = await finishedCiRun() + verdict = runs + ? releaseVerdict(api(`repos/${repo}/commits/${sha}/check-runs?per_page=100`).check_runs) + : { verified: false, why: 'no finished CI run on this commit' } +} catch (err) { + verdict = { verified: false, why: `could not read CI: ${err.message}` } +} +console.log(`${verdict.verified ? 'reusing' : 'retesting'}: ${verdict.why}`) +if (process.env.GITHUB_OUTPUT) + appendFileSync(process.env.GITHUB_OUTPUT, `verified=${verdict.verified}\n`) diff --git a/tests/scripts/releaseVerified.test.js b/tests/scripts/releaseVerified.test.js new file mode 100644 index 00000000..d832e4de --- /dev/null +++ b/tests/scripts/releaseVerified.test.js @@ -0,0 +1,36 @@ +import { describe, expect, it } from 'vitest' +import { releaseVerdict } from '../../scripts/lib/releaseVerified.mjs' + +const green = (...names) => names.map((name) => ({ name, conclusion: 'success' })) +const FULL = green( + 'quick', + 'check (ubuntu-latest)', + 'check (windows-latest)', + 'e2e-build', + 'e2e (1)', + 'e2e (2)' +) + +describe('releaseVerdict', () => { + it('reuses CI that passed every job on the tagged commit', () => { + expect(releaseVerdict(FULL).verified).toBe(true) + }) + + it('retests when any job failed, was skipped, cancelled or never finished', () => { + for (const conclusion of ['failure', 'skipped', 'cancelled', null]) { + expect(releaseVerdict([...FULL, { name: 'e2e (3)', conclusion }]).verified).toBe(false) + } + }) + + it('retests a commit CI never fully ran on, such as a direct push', () => { + expect(releaseVerdict([]).verified).toBe(false) + expect(releaseVerdict(FULL.filter((r) => !r.name.startsWith('e2e'))).verified).toBe(false) + expect(releaseVerdict(FULL.filter((r) => r.name !== 'check (windows-latest)')).verified).toBe( + false + ) + }) + + it('ignores check runs from other workflows', () => { + expect(releaseVerdict([...FULL, { name: 'CodeQL', conclusion: 'neutral' }]).verified).toBe(true) + }) +})