Repository navigation
496 lines (427 loc) · 22.3 KB
/
Copy pathci.yml
File metadata and controls
496 lines (427 loc) · 22.3 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
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
name: CI
# The gate every change goes through, on every push and every pull request, so a branch that cannot
# merge says so before anybody reviews it.
#
# One stage. Every job starts as soon as the changes are known, rather than waiting on a build job
# first: each restores the newest turbo cache an earlier run left, and the `^build` its tasks depend
# on is answered from it for every package that has not changed, so a job builds only what this
# change touched — seconds, where waiting on a build job of its own cost the whole run a minute and a
# half. Lint and typecheck build every package anyway, so that job leaves this commit's builds in the
# cache for the runs after it.
#
# The large suites are sharded, each shard on a runner of its own: @valence/screens six ways,
# @valence/server four and @valence/client three, with @valence/ui, @valence/mobile and @valence/tv
# as single shards in the same matrix. The phone and the television are not split further: most of
# their time is Babel compiling React Native, which a second shard would only do again, so instead
# Jest's compiled files are kept between runs. The small packages share two runners, two at a
# time, because each of them spends longer installing than testing: @valence/landing, the slowest of
# them, with the quick ones, and the rest on the other. Two at a time rather than all at once: turbo
# and vitest each size their worker pool to the machine's CPU count, and every package at once on a
# handful of cores thrashes. The split keeps a full run within the twenty jobs GitHub runs at once,
# so no shard waits for a runner.
#
# Test results outlive the run. Turbo already caches a passing test task by its inputs, and each
# test job keeps those results in the Actions cache and restores them next time, so a package or a
# shard whose code and dependencies have not changed replays its last pass in seconds.
#
# Every job after the first sits out the changes that cannot affect it. The first job asks the
# workspace which packages a pull request touches, counting the packages that depend on them, and
# the rest read its answer: a change to the docs site runs the docs tests and nothing else, a change
# to the transcoder runs Rust and nothing else, and a change to the root configuration, or a push to
# main, runs everything.
#
# The media pipeline is deliberately not here. It wants a Debian container, a Rust build and three
# minutes of encoding, and lives in media-pipeline.yml to run when it earns its keep.
on:
push:
branches: [main]
pull_request:
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
jobs:
# Which parts of the tree a change touches, so the jobs that only answer for one of them can sit
# out the changes that cannot affect them. A push to main answers yes to everything: main is what
# releases are cut from, and a cheap job skipped there saves a minute and risks the thing every
# other rule here exists to prevent.
#
# The workspace answers which packages are affected, counting the ones that depend on a changed
# one, so this file holds no list of who depends on whom to keep in step with the packages. It
# needs the history to compare against but not an install, which is what makes it cheap enough
# to be worth asking. The history comes without the contents of any file: which files changed is
# read from the trees alone, and a full clone spent most of this job's time fetching blobs it never
# read. A change to a file at the root, other than the notes and the workflows that
# belong to other pipelines, reads as touching the workspace itself, and that runs everything.
changes:
name: Detect changed areas
runs-on: ubuntu-24.04
outputs:
code: ${{ steps.what.outputs.code }}
light: ${{ steps.what.outputs.light }}
shards: ${{ steps.what.outputs.shards }}
rust: ${{ steps.what.outputs.rust }}
native: ${{ steps.what.outputs.native }}
expo: ${{ steps.what.outputs.expo }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
fetch-depth: 0
filter: blob:none
- uses: pnpm/action-setup@0977fd99725f1db4007ccb2928dbb4e90d06cc86 # v6.0.10
- id: what
env:
EVENT: ${{ github.event_name }}
BASE: ${{ github.base_ref }}
run: |
testable='["@valence/i18n","@valence/contracts","@valence/core","@valence/plugin-sdk","@valence/lint","@valence/brand","@valence/transcoder","@valence/ui","@valence/client","@valence/server","@valence/requests","@valence/database","@valence/web","@valence/desktop","@valence/landing","@valence/metrics","@valence/docs","@valence/mobile","@valence/tv"]'
if [ "$EVENT" != "pull_request" ]; then
{
echo 'code=true'
echo 'rust=true'
echo 'native=true'
echo 'expo=true'
} >> "$GITHUB_OUTPUT"
packages="$testable"
screens=true
else
git fetch --no-tags origin "$BASE"
affected=$(pnpm ls --filter "...[origin/$BASE]" --depth -1 --json \
--changed-files-ignore-pattern='**/*.md' \
--changed-files-ignore-pattern='.github/workflows/dev-image.yml' \
--changed-files-ignore-pattern='.github/workflows/nightly-image.yml' \
--changed-files-ignore-pattern='.github/workflows/prune-images.yml' \
--changed-files-ignore-pattern='.github/workflows/media-pipeline.yml' \
--changed-files-ignore-pattern='.github/workflows/desktop.yml' \
--changed-files-ignore-pattern='.github/workflows/desktop-dev.yml' \
--changed-files-ignore-pattern='.github/workflows/next-version.yml' \
--changed-files-ignore-pattern='.github/workflows/metrics.yml' \
--changed-files-ignore-pattern='.github/workflows/release.yml' \
--changed-files-ignore-pattern='.github/workflows/release-please.yml' \
--changed-files-ignore-pattern='release-please-config.json' \
--changed-files-ignore-pattern='.release-please-manifest.json' \
| jq -r '.[].name')
echo "$affected"
if echo "$affected" | grep -qx 'valence'; then
echo 'code=true' >> "$GITHUB_OUTPUT"
packages="$testable"
screens=true
else
if echo "$affected" | grep -vx '@valence/transcoder' | grep -q .; then
echo 'code=true' >> "$GITHUB_OUTPUT"
else
echo 'code=false' >> "$GITHUB_OUTPUT"
fi
packages=$(echo "$affected" | jq -R . | jq -sc --argjson testable "$testable" '[.[] | select(. as $name | $testable | index($name))]')
screens=$(echo "$affected" | grep -qx '@valence/screens' && echo true || echo false)
fi
changed=$(git diff --name-only "origin/$BASE...HEAD")
if echo "$changed" | grep -qE '^(apps/transcoder/|apps/desktop/native/|Cargo\.(toml|lock)$|\.github/workflows/ci\.yml$)'; then
echo 'rust=true' >> "$GITHUB_OUTPUT"
else
echo 'rust=false' >> "$GITHUB_OUTPUT"
fi
if echo "$changed" | grep -qE '^(apps/desktop/native/|Cargo\.(toml|lock)$|\.github/workflows/ci\.yml$)'; then
echo 'native=true' >> "$GITHUB_OUTPUT"
else
echo 'native=false' >> "$GITHUB_OUTPUT"
fi
if echo "$changed" | grep -qE '^(apps/mobile/|apps/tv/|packages/native/|patches/|pnpm-lock\.yaml$|\.github/workflows/ci\.yml$)'; then
echo 'expo=true' >> "$GITHUB_OUTPUT"
else
echo 'expo=false' >> "$GITHUB_OUTPUT"
fi
fi
# The large suites, each split into the shards its size calls for, and the rest for the
# two runners the small packages share: the slowest of them with the quick ones, and the
# others together.
sharded='{"@valence/server":4,"@valence/client":3,"@valence/ui":1,"@valence/mobile":1,"@valence/tv":1}'
beside_landing='["@valence/landing","@valence/web","@valence/brand","@valence/lint","@valence/plugin-sdk","@valence/i18n","@valence/transcoder"]'
{
echo "light=$(echo "$packages" | jq -c --argjson sharded "$sharded" --argjson beside "$beside_landing" '
[.[] | select(. as $name | $sharded | has($name) | not)] as $light
| [ {group: "landing", packages: [$light[] | select(. as $name | $beside | index($name))]},
{group: "rest", packages: [$light[] | select(. as $name | $beside | index($name) | not)]} ]
| map(select(.packages | length > 0))')"
echo "shards=$(echo "$packages" | jq -c --argjson sharded "$sharded" --arg screens "$screens" '
[ (.[] | select(. as $name | $sharded | has($name)) | . as $name | range(1; $sharded[$name] + 1) | {package: $name, shard: ., of: $sharded[$name]}),
(if $screens == "true" then range(1; 7) | {package: "@valence/screens", shard: ., of: 6} else empty end) ]')"
} >> "$GITHUB_OUTPUT"
# Lint and typecheck share a runner. Lint needs no build and could start sooner, but a runner of
# its own held a slot through the minute the test shards all want one at once. Typecheck builds
# every package, so this job is also the one that leaves this commit's builds in the cache.
typecheck:
name: Lint, typecheck and migration check
needs: changes
if: needs.changes.outputs.code == 'true'
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: pnpm/action-setup@0977fd99725f1db4007ccb2928dbb4e90d06cc86 # v6.0.10
- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version-file: .nvmrc
cache: pnpm
- run: pnpm install --frozen-lockfile
- uses: actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
path: .turbo/cache
key: turbo-build-${{ github.sha }}
restore-keys: turbo-build-
- run: pnpm lint
- run: pnpm format:check
# A hand-written migration with no snapshot beside it leaves generation silent and recreating
# tables that already exist. See VAL-193.
- run: pnpm db:check
- run: pnpm typecheck
# Keyed on the commit: the next run on this branch, or on a branch cut from it, restores the
# newest of these and rebuilds only what changed since.
- uses: actions/cache/save@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
path: .turbo/cache
key: turbo-build-${{ github.sha }}
# The small packages on two runners, two at a time on each.
test:
name: Test the smaller packages (${{ matrix.group }})
needs: changes
if: needs.changes.outputs.light != '[]'
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
include: ${{ fromJSON(needs.changes.outputs.light) }}
env:
PACKAGES: ${{ toJSON(matrix.packages) }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: pnpm/action-setup@0977fd99725f1db4007ccb2928dbb4e90d06cc86 # v6.0.10
- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version-file: .nvmrc
cache: pnpm
- run: pnpm install --frozen-lockfile
- uses: actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
path: .turbo/cache
key: turbo-build-${{ github.sha }}
restore-keys: turbo-build-
- uses: actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
path: .turbo/test-results
key: turbo-tests-light-${{ matrix.group }}-${{ github.sha }}
restore-keys: turbo-tests-light-${{ matrix.group }}-
- run: cp -n .turbo/test-results/* .turbo/cache/ 2>/dev/null || true
- run: pnpm turbo run test --concurrency=2 $(echo "$PACKAGES" | jq -r '.[] | "--filter=" + .')
# Only this job's own test results are kept, by the hashes turbo gave them, rather than the
# whole cache with every build in it.
- name: Keep the test results
run: |
rm -rf .turbo/test-results && mkdir -p .turbo/test-results
for hash in $(pnpm turbo run test $(echo "$PACKAGES" | jq -r '.[] | "--filter=" + .') --dry=json | jq -r '.tasks[] | select(.task == "test") | .hash'); do
cp .turbo/cache/"$hash"* .turbo/test-results/ 2>/dev/null || true
done
- uses: actions/cache/save@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
path: .turbo/test-results
key: turbo-tests-light-${{ matrix.group }}-${{ github.sha }}
# Each shard is its own turbo task, told which shard it is through VITEST_SHARD, which turbo
# folds into that task's hash alone. Passing the shard as an argument instead put it into the
# hash of every build the test depended on, and each runner rebuilt them all rather than taking
# them from the build job's cache.
test-shards:
name: Test ${{ matrix.package }} (${{ matrix.shard }} of ${{ matrix.of }})
needs: changes
if: needs.changes.outputs.shards != '[]'
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
include: ${{ fromJSON(needs.changes.outputs.shards) }}
env:
VITEST_SHARD: ${{ matrix.shard }}/${{ matrix.of }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: pnpm/action-setup@0977fd99725f1db4007ccb2928dbb4e90d06cc86 # v6.0.10
- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version-file: .nvmrc
cache: pnpm
- run: pnpm install --frozen-lockfile
- uses: actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
path: .turbo/cache
key: turbo-build-${{ github.sha }}
restore-keys: turbo-build-
- uses: actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
path: .turbo/test-results
key: turbo-tests-${{ matrix.package }}-${{ matrix.shard }}-of-${{ matrix.of }}-${{ github.sha }}
restore-keys: turbo-tests-${{ matrix.package }}-${{ matrix.shard }}-of-${{ matrix.of }}-
- run: cp -n .turbo/test-results/* .turbo/cache/ 2>/dev/null || true
# What Babel made of React Native and the rest of node_modules, which is most of what the
# phone's and the television's Jest spend their time on. Keyed on what decides it, so it is
# made once per lockfile and read by every run after.
- if: matrix.package == '@valence/mobile' || matrix.package == '@valence/tv'
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
path: apps/${{ matrix.package == '@valence/mobile' && 'mobile' || 'tv' }}/.jest-cache
key: jest-${{ matrix.package }}-${{ hashFiles('pnpm-lock.yaml', 'apps/mobile/jest.config.ts', 'apps/tv/jest.config.ts') }}
- run: pnpm turbo run test:shard --filter=${{ matrix.package }}
- name: Keep the test results
run: |
rm -rf .turbo/test-results && mkdir -p .turbo/test-results
for hash in $(pnpm turbo run test:shard --filter=${{ matrix.package }} --dry=json | jq -r '.tasks[] | select(.task == "test:shard") | .hash'); do
cp .turbo/cache/"$hash"* .turbo/test-results/ 2>/dev/null || true
done
- uses: actions/cache/save@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
path: .turbo/test-results
key: turbo-tests-${{ matrix.package }}-${{ matrix.shard }}-of-${{ matrix.of }}-${{ github.sha }}
rust:
name: Rust format, lint and test
runs-on: ubuntu-24.04
needs: changes
if: needs.changes.outputs.rust == 'true'
# Read only, since cargo runs build scripts from every crate it builds and nothing here writes.
permissions:
contents: read
# On the pull requests that touch Rust, and on every push to main. A test reading a child's
# niceness through `ps` once passed on every developer's macOS and failed only here, so the unit
# tests are worth running somewhere other than the machine they were written on.
#
# The suites that drive a real FFmpeg do not run here. They took nine of this job's ten minutes,
# most of it encoding fixtures, and they need a Debian container with the FFmpeg Valence ships.
# They run in media-pipeline.yml instead, by hand before a release and once a week, and in the
# pre-push hook. What is left needs no FFmpeg at all, as the Windows job below already shows.
steps:
# Nothing here pushes, and cargo runs build scripts from every crate in the workspace, so the
# token is not left behind in the checkout for them to find.
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: dtolnay/rust-toolchain@89b12181fb390509a0842a86cc55eeb8eb928c1d # stable
with:
toolchain: stable
components: clippy, rustfmt
- uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2
- run: cargo fmt --all --check
- run: cargo clippy --all-targets -- -D warnings
- run: cargo test --workspace --lib --bins
- run: cargo test -p valence-transcoder --test path_map_requests
# The transcoder also runs natively on Windows, where it reaches the GPU through Direct3D 11 rather
# than through /dev/dri (VAL-338). The Linux job cannot see a Windows-only compile error, a path
# that splits on the drive's colon, or a test that assumes a forward slash, so it is linted and its
# unit tests run here too, on the same pull requests as the Linux job. The suites that drive a real
# FFmpeg stay on Linux: there is no Valence FFmpeg for this runner to fetch from a package.
# On x64 and on Windows on Arm, each natively, so a compile error only one architecture has shows
# up on the pull request rather than in a release (VAL-355).
transcoder-windows:
name: Transcoder on Windows (${{ matrix.arch }})
runs-on: ${{ matrix.runner }}
needs: changes
if: needs.changes.outputs.rust == 'true'
permissions:
contents: read
strategy:
fail-fast: false
matrix:
include:
- arch: x64
runner: windows-2025-vs2026
- arch: arm64
runner: windows-11-arm
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: dtolnay/rust-toolchain@89b12181fb390509a0842a86cc55eeb8eb928c1d # stable
with:
toolchain: stable
components: clippy
- uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2
- run: cargo clippy -p valence-transcoder --all-targets -- -D warnings
- run: cargo test -p valence-transcoder --lib --bins --test path_map_requests
# The Rust job builds on Linux, where the desktop app's native module holds nothing but a helper.
# Its Windows Hello code only compiles on Windows, so it is linted and built there, on the pull
# requests that touch it.
#
# On both of Windows' architectures, as the transcoder is: the desktop app ships an ARM64 build too.
desktop-native:
name: Desktop native module on Windows (${{ matrix.arch }})
runs-on: ${{ matrix.runner }}
needs: changes
if: needs.changes.outputs.native == 'true'
permissions:
contents: read
strategy:
fail-fast: false
matrix:
include:
- arch: x64
runner: windows-2025-vs2026
- arch: arm64
runner: windows-11-arm
steps:
# Nothing here pushes, and cargo runs build scripts from every crate it builds, so the token
# is not left behind in the checkout for them to find.
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: dtolnay/rust-toolchain@89b12181fb390509a0842a86cc55eeb8eb928c1d # stable
with:
toolchain: stable
components: clippy
- uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2
- run: cargo clippy -p valence-desktop-native --all-targets -- -D warnings
- run: cargo test -p valence-desktop-native
- run: cargo build --release -p valence-desktop-native
# The phone and television apps' native projects, generated the way a store build generates them,
# on the pull requests that could change them. Every config plugin runs, so a broken one fails here
# in review rather than on a macOS runner at release. Linux only: nothing is compiled.
expo-prebuild:
name: Native config of the ${{ matrix.name }}
runs-on: ubuntu-24.04
needs: changes
if: needs.changes.outputs.expo == 'true'
permissions:
contents: read
strategy:
fail-fast: false
matrix:
name: [phone app, television app]
include:
- name: phone app
app: mobile
tv: ''
- name: television app
app: tv
tv: '1'
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: pnpm/action-setup@0977fd99725f1db4007ccb2928dbb4e90d06cc86 # v6.0.10
- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version-file: .nvmrc
cache: pnpm
- run: pnpm install --frozen-lockfile
# Both platforms on one runner: generating each takes seconds, and a runner apiece spent a
# minute installing for every one of them while the test shards waited for a slot.
- name: Generate the native projects
working-directory: apps/${{ matrix.app }}
run: |
npx expo prebuild --platform ios --no-install --clean
npx expo prebuild --platform android --no-install --clean
env:
EXPO_TV: ${{ matrix.tv }}
CI: '1'