Repository navigation
423 lines (375 loc) · 18 KB
/
Copy pathci.yml
File metadata and controls
423 lines (375 loc) · 18 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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
name: CI
on:
push:
branches:
- main
pull_request:
# Merge queue: GitHub re-runs the required checks on each queued merge result
# before it lands on main. Without this trigger nothing in the queue can pass.
merge_group:
workflow_dispatch:
inputs:
deploy:
description: "Deploy app.threadlines.dev after checks pass. Only applies when dispatched from main."
required: false
default: false
type: boolean
permissions:
checks: read
contents: read
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
jobs:
# On pushes to main, check whether a green merge_group run of this workflow
# targeting main already verified every required job on this exact commit.
# Skipped immediately on pull_request, merge_group, and workflow_dispatch with
# no runner startup cost. Fails open: if precheck errors or skips, full CI
# still runs. Keep the required job list in step with DEFAULT_REQUIRED_CHECKS
# in scripts/verify-release-ci.ts.
precheck:
name: Check if commit already passed CI
if: github.event_name == 'push'
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
skip_ci: ${{ steps.check.outputs.skip_ci }}
warm_cache: ${{ steps.check.outputs.warm_cache }}
steps:
- id: check
name: Check prior merge_group verdict on this commit
env:
GH_TOKEN: ${{ github.token }}
BEFORE: ${{ github.event.before }}
run: |
set -euo pipefail
required_json='[
"Checks and Build",
"Unit Test",
"Server Test (1/4)",
"Server Test (2/4)",
"Server Test (3/4)",
"Server Test (4/4)",
"Browser Test (1/2)",
"Browser Test (2/2)",
"Release Smoke"
]'
# Find the newest successful merge_group run of ci.yml for main on this exact SHA.
merge_run_id="$(
gh api "repos/${GITHUB_REPOSITORY}/actions/workflows/ci.yml/runs?event=merge_group&head_sha=${GITHUB_SHA}&status=success&per_page=20" \
--jq '[.workflow_runs[] | select(.conclusion == "success" and (.head_branch | startswith("gh-readonly-queue/main/")))] | sort_by(.run_started_at // .created_at) | last | .id // empty'
)"
already_passed="false"
if [[ -n "$merge_run_id" ]]; then
already_passed="$(
gh api --paginate "repos/${GITHUB_REPOSITORY}/actions/runs/${merge_run_id}/jobs?per_page=100" --jq '.jobs[]' \
| jq -s --argjson required "$required_json" '
. as $jobs |
$required | all(. as $name |
any($jobs[]; .name == $name and .status == "completed" and .conclusion == "success")
)
'
)"
fi
if [[ "$already_passed" != "true" ]]; then
echo "Commit ${GITHUB_SHA} has no passing main merge_group CI run covering all required checks; running full CI."
echo "skip_ci=false" >> "$GITHUB_OUTPUT"
echo "warm_cache=false" >> "$GITHUB_OUTPUT"
exit 0
fi
echo "merge_group run ${merge_run_id} already passed every required check on ${GITHUB_SHA}; skipping duplicate push CI."
echo "skip_ci=true" >> "$GITHUB_OUTPUT"
# Keep the main-scoped pnpm store cache warm when pnpm-lock.yaml changed
# (caches saved on merge_group branches are not visible to future PRs).
# Compare the lockfile blob SHA directly so large diffs (>300 files) never
# miss a lockfile change, and warm conservatively if the lookup fails.
warm_cache="true"
if [[ -n "$BEFORE" && "$BEFORE" != "0000000000000000000000000000000000000000" ]]; then
before_blob="$(gh api "repos/${GITHUB_REPOSITORY}/contents/pnpm-lock.yaml?ref=${BEFORE}" --jq '.sha' 2>/dev/null || true)"
after_blob="$(gh api "repos/${GITHUB_REPOSITORY}/contents/pnpm-lock.yaml?ref=${GITHUB_SHA}" --jq '.sha' 2>/dev/null || true)"
if [[ -n "$before_blob" && -n "$after_blob" && "$before_blob" == "$after_blob" ]]; then
warm_cache="false"
fi
fi
echo "warm_cache=${warm_cache}" >> "$GITHUB_OUTPUT"
warm_cache:
name: Warm main dependency cache
needs: [precheck]
if: ${{ github.event_name == 'push' && needs.precheck.result == 'success' && needs.precheck.outputs.skip_ci == 'true' && needs.precheck.outputs.warm_cache == 'true' }}
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Setup Vite+
uses: voidzero-dev/setup-vp@cab1ab9eaff52d4857875f4f2c016e36af8f2c76 # v1.22.0
with:
node-version: "24"
cache: true
run-install: false
- name: Install dependencies
env:
ELECTRON_SKIP_BINARY_DOWNLOAD: "1"
run: vp install --frozen-lockfile
# scripts/verify-release-ci.ts requires this job by name.
quality:
name: Checks and Build
needs: [precheck]
if: ${{ !cancelled() && !(github.event_name == 'push' && needs.precheck.result == 'success' && needs.precheck.outputs.skip_ci == 'true') }}
runs-on: ubuntu-latest
# 20 minutes starves dependency-bump branches: a lockfile change cold-starts
# every cache and slow runners then hit the cap mid-pipeline.
timeout-minutes: 30
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Setup Vite+
uses: voidzero-dev/setup-vp@cab1ab9eaff52d4857875f4f2c016e36af8f2c76 # v1.22.0
with:
node-version: "24"
cache: true
run-install: false
- name: Install dependencies
run: vp install --frozen-lockfile
- name: Ensure Electron binary is installed
run: node scripts/ensure-electron-binary.ts
- name: Format
run: vp fmt --check
- name: Lint
run: vp exec vp lint --report-unused-disable-directives
- name: Vendored Playwright injected script is current
run: node scripts/extract-playwright-injected.ts --check
- name: Vendored Effect source matches the installed version
run: node scripts/sync-effect-source.ts --check
- name: Typecheck
# Typecheck runs before build against .ts sources directly, so packages
# don't need topological ordering (`apps/server` lists `@threadlines/web`
# only to bundle its dist output).
run: vp exec vp run --parallel --concurrency-limit 4 --filter '!@threadlines/monorepo' typecheck
- name: Build desktop pipeline
run: vp exec vp run build:desktop
- name: Check web startup bundle size
# The desktop build above also builds apps/web/dist.
run: node scripts/check-web-bundle-size.ts
- name: Verify preload bundle output
run: |
test -f apps/desktop/dist-electron/preload.cjs
grep -nE "desktopBridge|getLocalEnvironmentBootstrap|PICK_FOLDER_CHANNEL|wsUrl" apps/desktop/dist-electron/preload.cjs
# Every package's unit tests except the server's, which run in the
# `server_test` shards. Its own job so a failing test never hides a broken
# build behind it, and both finish sooner side by side.
# scripts/verify-release-ci.ts requires this job by name.
unit_test:
name: Unit Test
needs: [precheck]
if: ${{ !cancelled() && !(github.event_name == 'push' && needs.precheck.result == 'success' && needs.precheck.outputs.skip_ci == 'true') }}
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Setup Vite+
uses: voidzero-dev/setup-vp@cab1ab9eaff52d4857875f4f2c016e36af8f2c76 # v1.22.0
with:
node-version: "24"
cache: true
run-install: false
- name: Install dependencies
run: vp install --frozen-lockfile
- name: Ensure Electron binary is installed
run: node scripts/ensure-electron-binary.ts
- name: Test
# --parallel drops package ordering, so no suite waits for a package it
# depends on.
run: vp exec vp run --parallel --concurrency-limit 4 --filter '!@threadlines/server' --filter '!@threadlines/monorepo' test
# apps/server runs its test files one at a time (`fileParallelism: false`):
# side by side they hit load-sensitive flakes. Sharding spreads the files over
# separate runners instead, so no two of them ever share a machine. The shards
# split files by recorded time (scripts/lib/test-shards.ts). Release
# verification requires each shard by name: when the shard count changes,
# update DEFAULT_REQUIRED_CHECKS in scripts/verify-release-ci.ts.
server_test:
name: Server Test (${{ matrix.shard }}/${{ strategy.job-total }})
needs: [precheck]
if: ${{ !cancelled() && !(github.event_name == 'push' && needs.precheck.result == 'success' && needs.precheck.outputs.skip_ci == 'true') }}
runs-on: ubuntu-latest
timeout-minutes: 20
strategy:
# One failing shard still lets the others report their own failures.
fail-fast: false
matrix:
shard: [1, 2, 3, 4]
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Setup Vite+
uses: voidzero-dev/setup-vp@cab1ab9eaff52d4857875f4f2c016e36af8f2c76 # v1.22.0
with:
node-version: "24"
cache: true
run-install: false
- name: Install dependencies
run: vp install --frozen-lockfile
- name: Server test
env:
THREADLINES_SHARD_TIMINGS_FILE: ${{ runner.temp }}/test-timings.json
run: vp exec vp run --filter @threadlines/server test --shard=${{ matrix.shard }}/${{ strategy.job-total }}
# `node --run test:shard-weights -- server` reads these from the newest
# green run on main to rebalance the shards.
- name: Upload server test timings
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: server-test-timings-${{ matrix.shard }}
path: ${{ runner.temp }}/test-timings.json
retention-days: 14
if-no-files-found: error
# Branch protection requires this check by name, so it keeps the name of the
# single job that used to do all of this work. It passes only when every job
# it needs passed, so jobs can split or reshard without a ruleset change: add
# new ones to `needs`. `always()` rather than `!cancelled()`, because a
# skipped job reports success to branch protection and a cancelled run must
# still fail this check. That turns cancellation into failure, so release
# verification (scripts/verify-release-ci.ts) checks the jobs themselves.
quality_gate:
name: Format, Lint, Typecheck, Test, Build
if: ${{ always() && !(github.event_name == 'push' && needs.precheck.result == 'success' && needs.precheck.outputs.skip_ci == 'true') }}
needs: [precheck, quality, unit_test, server_test]
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Require every job to pass
env:
RESULTS: ${{ toJSON(needs) }}
run: |
echo "$RESULTS" | jq -r 'del(.precheck) | to_entries[] | "\(.key): \(.value.result)"'
echo "$RESULTS" | jq -e 'del(.precheck) | all(.[]; .result == "success")' > /dev/null
# The browser suite is CPU-bound (every spec renders the whole app), so one
# 4-core runner tops out at about two tabs' worth of work. Two shards on two
# runners halve it. Files split by recorded time (scripts/lib/test-shards.ts);
# release verification requires each shard by name, so a shard count change
# updates DEFAULT_REQUIRED_CHECKS in scripts/verify-release-ci.ts too.
browser:
name: Browser Test (${{ matrix.shard }}/${{ strategy.job-total }})
needs: [precheck]
if: ${{ !cancelled() && !(github.event_name == 'push' && needs.precheck.result == 'success' && needs.precheck.outputs.skip_ci == 'true') }}
runs-on: ubuntu-latest
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
shard: [1, 2]
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Setup Vite+
uses: voidzero-dev/setup-vp@cab1ab9eaff52d4857875f4f2c016e36af8f2c76 # v1.22.0
with:
node-version: "24"
cache: true
run-install: false
- name: Install dependencies
run: vp install --frozen-lockfile
# Hosted ubuntu-latest images already ship Chromium's shared libraries.
# `playwright install --with-deps` spent 2.5 to 5 minutes on throttled
# EC2 Ubuntu mirrors (`*.ec2.archive.ubuntu.com`) fetching optional font
# packages. Install the browser binaries first and only touch apt when a
# real headless launch fails (for example after a future runner image
# drops a library). When apt is needed, rewrite all Ubuntu mirror hosts
# (azure., *.ec2., etc.) to archive.ubuntu.com over HTTPS with a 10 s
# timeout and 1 retry so a stuck mirror cannot starve the job.
- name: Install browser test runtime
timeout-minutes: 10
shell: bash
run: |
set -euo pipefail
./apps/web/node_modules/.bin/playwright install chromium
probe_chromium() {
node --input-type=module -e '
import { chromium } from "./apps/web/node_modules/playwright/index.mjs";
const browser = await chromium.launch({ headless: true });
await browser.close();
'
}
if probe_chromium; then
echo "Chromium launched with preinstalled system libraries; skipping apt."
else
echo "Chromium launch failed; installing system dependencies via apt over HTTPS."
sudo find /etc/apt -type f \( -name "*.list" -o -name "*.sources" -o -name "apt-mirrors.txt" \) \
-exec sed -i -E 's|https?://([a-z0-9.-]+\.)?archive\.ubuntu\.com/ubuntu|https://archive.ubuntu.com/ubuntu|g' {} +
printf '%s\n' 'Acquire::http::Timeout "10";' 'Acquire::https::Timeout "10";' 'Acquire::Retries "1";' \
| sudo tee /etc/apt/apt.conf.d/zz-threadlines-ci >/dev/null
apt-config dump | grep -E '^Acquire::(Retries|https?::Timeout) ' || true
grep -rhoE 'https?://[a-z0-9.-]*ubuntu\.com/ubuntu' /etc/apt 2>/dev/null | sort | uniq -c || true
./apps/web/node_modules/.bin/playwright install-deps chromium
probe_chromium
fi
- name: Browser test
env:
THREADLINES_SHARD_TIMINGS_FILE: ${{ runner.temp }}/test-timings.json
run: vp exec vp run --filter @threadlines/web test:browser --shard=${{ matrix.shard }}/${{ strategy.job-total }}
# `node --run test:shard-weights -- browser` reads these from the newest
# green run on main to rebalance the shards.
- name: Upload browser test timings
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: browser-test-timings-${{ matrix.shard }}
path: ${{ runner.temp }}/test-timings.json
retention-days: 14
if-no-files-found: error
# Browser test failures are timing-sensitive and CI-only more often than
# not; the on-failure screenshot is the only evidence of what rendered.
- name: Upload browser test failure screenshots
if: failure()
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: browser-test-screenshots-${{ matrix.shard }}
path: apps/web/.vitest/attachments/failure-screenshots/**
include-hidden-files: true
if-no-files-found: ignore
# Keeps the required "Browser Test" check, the way `quality_gate` keeps its
# name: it passes only when every browser shard passed.
browser_gate:
name: Browser Test
if: ${{ always() && !(github.event_name == 'push' && needs.precheck.result == 'success' && needs.precheck.outputs.skip_ci == 'true') }}
needs: [precheck, browser]
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Require every shard to pass
env:
RESULTS: ${{ toJSON(needs) }}
run: |
echo "$RESULTS" | jq -r 'del(.precheck) | to_entries[] | "\(.key): \(.value.result)"'
echo "$RESULTS" | jq -e 'del(.precheck) | all(.[]; .result == "success")' > /dev/null
release_smoke:
name: Release Smoke
needs: [precheck]
if: ${{ !cancelled() && !(github.event_name == 'push' && needs.precheck.result == 'success' && needs.precheck.outputs.skip_ci == 'true') }}
runs-on: ubuntu-latest
# A lockfile change cold-starts the Vite+ cache: setup alone took ~8 minutes
# on #950 and the old 10-minute cap cut the job off while saving the cache.
timeout-minutes: 20
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Setup Vite+
uses: voidzero-dev/setup-vp@cab1ab9eaff52d4857875f4f2c016e36af8f2c76 # v1.22.0
with:
node-version: "24"
cache: true
run-install: false
- name: Install dependencies
run: vp install --frozen-lockfile
- name: Exercise release-only workflow steps
run: node scripts/release-smoke.ts
deploy_web_app:
name: Deploy app.threadlines.dev
needs:
- quality_gate
- browser_gate
- release_smoke
# Explicit status checks are required because `precheck` is a skipped
# transitive ancestor on workflow_dispatch (implicit success() would skip).
if: ${{ !cancelled() && needs.quality_gate.result == 'success' && needs.browser_gate.result == 'success' && needs.release_smoke.result == 'success' && github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main' && inputs.deploy == true }}
uses: ./.github/workflows/deploy-web.yml
secrets: inherit