Repository navigation
314 lines (303 loc) · 14.1 KB
/
Copy pathci.yml
File metadata and controls
314 lines (303 loc) · 14.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
name: CI/CD
on:
push:
branches: [main]
pull_request:
branches: [main]
# Least privilege: the workflow default is read-only. Only the jobs that need
# elevated scopes request them at the job level — `deploy` (pages/id-token, for
# Pages publishing) and `release` (contents: write, for the version-bump commit,
# tag, and GitHub Release). Test jobs (which run npm lifecycle scripts and
# Playwright) never inherit write scopes.
permissions:
contents: read
# Concurrency is scoped PER REF (branch / PR), not global. A previous static
# `group: pages` cancelled EVERY in-flight run across all branches, so opening
# or pushing one PR would cancel another PR's (and main's) CI. Keying on the ref
# means a run only supersedes an OLDER run of the SAME branch/PR — exactly the
# "newer push wins" behaviour we want — while different PRs run independently.
# GitHub Pages deploy serialization lives on the `deploy` job instead (it uses a
# dedicated `pages` group with cancel-in-progress: false so a live deploy is
# never killed mid-publish).
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
audit:
name: Security Audit
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v6
with:
node-version: 22
cache: npm
- run: npm ci
- run: npm audit --audit-level=high
lint:
name: Lint & Format
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v6
with:
node-version: 22
cache: npm
- run: npm ci
- run: npx prettier --check .
- run: npx eslint .
# Use the npm script so BOTH tsconfigs are checked: the src build and the
# scripts/release tooling (tsconfig.scripts.json). A bare `tsc --noEmit`
# would only see tsconfig.json (src), leaving the release test unchecked.
- run: npm run typecheck
test-unit:
name: Unit & Integration Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v6
with:
node-version: 22
cache: npm
- run: npm ci
- run: npx vitest run --coverage
test-e2e:
name: E2E Tests (${{ matrix.browser == 'chromium' && 'Chromium' || matrix.browser == 'firefox' && 'Firefox' || 'WebKit' }})
runs-on: ubuntu-latest
# Run inside the official Playwright image. It ships every browser AND all of
# their system (apt) dependencies preinstalled, so we DON'T run
# `playwright install --with-deps`. That apt step once took ~30 min on a slow
# Ubuntu mirror (WebKit was worst), turning a ~6-min job into a 37-min
# pipeline that looked hung. The container removes apt from the critical path.
# The tag MUST match the Playwright version locked in package-lock.json
# (@playwright/test 1.58.2). A mismatch ships a different browser revision and
# Playwright fails with "Executable doesn't exist" — keep this tag in lockstep
# with the lockfile when bumping Playwright.
container: mcr.microsoft.com/playwright:v1.58.2-noble
# `actions/setup-node` repoints $HOME at a runner temp dir not owned by the
# container's root user. Chromium/WebKit tolerate it, but Firefox REFUSES to
# launch unless $HOME is owned by the current user ("Failed to launch the
# browser process"). Pinning HOME=/root (the image's root home) is the
# documented Playwright workaround and fixes the Firefox-only launch failure.
env:
HOME: /root
strategy:
fail-fast: false
matrix:
browser: [chromium, firefox, webkit]
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v6
with:
node-version: 22
cache: npm
- run: npm ci
# No `playwright install --with-deps`: browsers + OS deps are baked into the
# image, and the pinned tag guarantees the bundled revision matches
# @playwright/test, so no install step is required.
- run: npx playwright test --project=${{ matrix.browser }}
- uses: actions/upload-artifact@v7
if: ${{ !cancelled() }}
with:
name: playwright-report-${{ matrix.browser }}
path: playwright-report/
retention-days: 14
test-e2e-fidelity:
name: E2E WebGL Fidelity Gate (ADR 0019)
runs-on: ubuntu-latest
# Same official Playwright image as test-e2e (see that job for the 30-min apt
# incident this avoids). Tag pinned to the locked @playwright/test 1.58.2.
# The image bundles the Mesa/GL userspace libraries that software WebGL2
# (ANGLE + SwiftShader) needs, so the fidelity gate runs unchanged without any
# apt install.
container: mcr.microsoft.com/playwright:v1.58.2-noble
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v6
with:
node-version: 22
cache: npm
- run: npm ci
# No `playwright install --with-deps`: Chromium + its OS/GL deps are baked
# into the image at the pinned revision.
# Software WebGL2 (ANGLE + SwiftShader) is configured in the
# `chromium-fidelity` Playwright project. RUN_FIDELITY=1 enables the gate;
# a missing WebGL2 context fails the gate LOUDLY (it never silently skips).
- run: RUN_FIDELITY=1 npx playwright test --project=chromium-fidelity
- uses: actions/upload-artifact@v7
if: ${{ !cancelled() }}
with:
name: playwright-report-fidelity
path: playwright-report/
retention-days: 14
build:
name: Build
runs-on: ubuntu-latest
needs: [audit, lint, test-unit, test-e2e, test-e2e-fidelity]
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v6
with:
node-version: 22
cache: npm
- run: npm ci
- run: npm run build
- uses: actions/upload-pages-artifact@v5
with:
path: dist/
release:
name: Cut CalVer Release
# Release only on a push to main — never on pull requests. PRs run the gates
# above for review, but nothing is tagged, committed, or published until the
# change actually lands on main. This mirrors the deploy job's trigger.
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
# Gated behind the SAME quality jobs that authorize the deploy: an
# unreleasable build is an undeployable one. `release` sits between the gates
# and `deploy` (deploy `needs` it), so the tag and GitHub Release exist by
# the time the Pages artifact goes live.
needs: [audit, lint, test-unit, test-e2e, test-e2e-fidelity, build]
runs-on: ubuntu-latest
# Scope the write permission to THIS job only. The rest of the workflow stays
# read-only (`contents: read` at the top); only the release job can push the
# version-bump commit + tag and create the GitHub Release.
#
# AUTH NOTE: the version-bump commit is pushed DIRECTLY to `main`, which is
# protected by a repository ruleset (require-pull-request + require-code-
# scanning-results). The built-in GITHUB_TOKEN (github-actions[bot]) cannot
# be added as a ruleset bypass actor — rulesets only allow roles, deploy
# keys, teams, and Apps to bypass, not the default Actions token — so a
# GITHUB_TOKEN push is rejected ("Changes must be made through a pull
# request"). We therefore push with RELEASE_TOKEN, a repository-admin
# fine-grained PAT (Contents: read/write) stored as a secret; because it
# acts as an admin identity, the ruleset's "Repository admin" bypass covers
# it. If the secret is unset we fall back to GITHUB_TOKEN so the rest of the
# job (version compute, changelog) still runs — only the protected push then
# fails, exactly as before, rather than erroring on an empty token.
permissions:
contents: write
steps:
- uses: actions/checkout@v7
with:
# Full history + tags: the version computation reads existing
# `vYYYY.0M.*` tags to derive the next MICRO, and we push a commit back
# to main (a shallow clone cannot push or see tag history).
fetch-depth: 0
# Persist the release token so the later `git push` is authenticated
# as the bypass-eligible admin identity (see AUTH NOTE above).
token: ${{ secrets.RELEASE_TOKEN || secrets.GITHUB_TOKEN }}
# Belt-and-suspenders loop guard: if the commit that triggered this run is
# itself a release commit (`chore(release): ...`), do nothing. The release
# commit already carries `[skip ci]`, so GitHub should not have triggered a
# run at all — this is the second line of defence against an infinite loop
# if that marker is ever stripped or ignored.
- name: Guard against release-commit re-trigger
id: guard
run: |
subject="$(git log -1 --pretty=%s)"
echo "Triggering commit subject: $subject"
if printf '%s' "$subject" | grep -qiE '^chore\(release\): '; then
echo "Release commit detected — skipping to avoid a release loop."
echo "skip=true" >> "$GITHUB_OUTPUT"
else
echo "skip=false" >> "$GITHUB_OUTPUT"
fi
- uses: actions/setup-node@v6
if: steps.guard.outputs.skip != 'true'
with:
node-version: 22
cache: npm
# Compute the next CalVer version (YYYY.0M.MICRO) from existing tags.
# MICRO = highest existing v<YYYY.0M>.* MICRO + 1, or 0 if none this month.
- name: Compute next version
id: version
if: steps.guard.outputs.skip != 'true'
run: node scripts/release/compute-version.mjs --github
# Transform CHANGELOG.md + bump package.json IN THE WORKING TREE, and write
# the just-released section to release-notes.md for the Release body. If
# `## [Unreleased]` has no real content (only `_Nothing yet._`/whitespace),
# the script writes nothing and sets `released=false` — a docs/chore deploy
# produces NO empty release, while the deploy below still proceeds.
- name: Cut release (changelog + version bump)
id: cut
if: steps.guard.outputs.skip != 'true'
# Pass the computed version through `env:` rather than interpolating
# `${{ }}` directly into the run block — consistent with the steps below
# and the recommended practice for getting expression values into a shell.
env:
VERSION: ${{ steps.version.outputs.version }}
run: |
node scripts/release/cut-release.mjs \
--version "${VERSION}" \
--notes release-notes.md \
--github
# Everything below runs only when a release was actually cut.
- name: Commit, tag, and push
id: publish
if: steps.guard.outputs.skip != 'true' && steps.cut.outputs.released == 'true'
env:
VERSION: ${{ steps.version.outputs.version }}
run: |
set -euo pipefail
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add CHANGELOG.md package.json
# `[skip ci]` in the commit message stops GitHub from starting a fresh
# CI run for this bot commit — without it, every release would trigger
# another release: an infinite loop.
git commit -m "chore(release): ${VERSION} [skip ci]"
# Annotated tag (carries author/date/message), required by the CalVer
# scheme and used as the next run's MICRO source.
git tag -a "v${VERSION}" -m "Release ${VERSION}"
# Push the commit and the tag together to the triggering branch.
git push origin HEAD:main
git push origin "v${VERSION}"
# Publish the GitHub Release with the freshly-cut changelog section as its
# body. We use the GitHub CLI (`gh`), which is preinstalled on
# GitHub-hosted runners and is GitHub's own first-party tool — so there is
# no third-party action to pin or audit, and nothing leaves the runner
# beyond the API call to create the release. It authenticates with the
# same RELEASE_TOKEN used for the push (creating the release also creates
# the `vYYYY.0M.*` tag, which a tag ruleset could likewise gate), falling
# back to GITHUB_TOKEN when the secret is unset.
- name: Create GitHub Release
if: steps.guard.outputs.skip != 'true' && steps.cut.outputs.released == 'true'
env:
GH_TOKEN: ${{ secrets.RELEASE_TOKEN || secrets.GITHUB_TOKEN }}
VERSION: ${{ steps.version.outputs.version }}
run: |
set -euo pipefail
gh release create "v${VERSION}" \
--title "v${VERSION}" \
--notes-file release-notes.md \
--latest \
--target main
deploy:
name: Deploy to GitHub Pages
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
# Deploy waits on `release` as well as `build`: the tag and GitHub Release
# are cut before the artifact goes live, so "deployed" and "released" line up
# for each push. `release` always runs to completion on a main push (it
# no-ops internally when there is nothing to release rather than skipping the
# job), so this `needs` stays satisfied and deploys are never blocked by an
# empty-changelog push.
needs: [build, release]
runs-on: ubuntu-latest
# Job-scoped Pages publishing scopes. `pages: write` lets actions/deploy-pages
# publish; `id-token: write` lets it mint the OIDC token Pages requires. These
# live ONLY here, not at the workflow level, so no other job inherits them.
# (Uploading the artifact in `build` needs only the read default.)
permissions:
pages: write
id-token: write
# Serialize Pages deploys here (not workflow-wide). cancel-in-progress is
# false so an in-flight publish is allowed to finish rather than be aborted
# by a newer commit's deploy.
concurrency:
group: pages
cancel-in-progress: false
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- id: deployment
uses: actions/deploy-pages@v5