Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 50 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
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]
pull_request:
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
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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:
Expand Down
75 changes: 54 additions & 21 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions scripts/lib/releaseVerified.mjs
Original file line number Diff line number Diff line change
@@ -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` }
}
35 changes: 35 additions & 0 deletions scripts/release-verified.mjs
Original file line number Diff line number Diff line change
@@ -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`)
36 changes: 36 additions & 0 deletions tests/scripts/releaseVerified.test.js
Original file line number Diff line number Diff line change
@@ -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)
})
})
Loading