Repository navigation
581 lines (497 loc) · 22.1 KB
/
Copy pathci.yml
File metadata and controls
581 lines (497 loc) · 22.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
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
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
name: CI
on:
push:
branches: [master, main]
pull_request:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
fmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Format
run: cargo fmt --all --check
clippy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Cache cargo
uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
cache-dependency-path: crates/workshop/package-lock.json
- name: Install UI dependencies
run: npm ci --prefix crates/workshop
- name: Clippy
env:
CARGO_BUILD_WARNINGS: deny
run: cargo clippy --workspace --exclude workshop --exclude workshop-server --exclude workshop-server-api --all-targets --all-features
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install cargo-nextest
uses: taiki-e/install-action@4dc1969decfa71b34f25aa7f3dd4656654d9ad1e # nextest
- name: Cache cargo
uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
cache-dependency-path: crates/workshop/package-lock.json
- name: Install UI dependencies
run: npm ci --prefix crates/workshop
- name: Test (concurrent via nextest)
run: cargo nextest run --locked --workspace --exclude workshop --exclude workshop-server --exclude workshop-server-api --all-features
# No build step may write into the repository (the UI bundles build
# into OUT_DIR now); catch a regression here rather than in a diff.
- name: Clean tree
shell: bash
run: |
if [ -n "$(git status --porcelain)" ]; then
echo "the build dirtied the repository:"
git status --porcelain
exit 1
fi
docs:
runs-on: ubuntu-latest
env:
RUSTDOCFLAGS: -D warnings
steps:
- uses: actions/checkout@v4
- name: Cache cargo
uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
cache-dependency-path: crates/workshop/package-lock.json
- name: Install UI dependencies
run: npm ci --prefix crates/workshop
- name: Docs
run: cargo doc --workspace --no-deps --all-features --exclude workshop --exclude workshop-server --exclude workshop-server-api
check-workshop:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Install cargo-nextest
uses: taiki-e/install-action@4dc1969decfa71b34f25aa7f3dd4656654d9ad1e # nextest
- name: Cache cargo
uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
cache-dependency-path: crates/workshop/package-lock.json
- name: Install UI dependencies
run: npm ci --prefix crates/workshop
- name: Stage a stub Gateway sidecar
run: node tools/fetch-gateway-sidecar.mjs --stub --target x86_64-pc-windows-msvc
# workshop-server-api is the desktop app's re-export view of workshop-server,
# so it runs in this partition with the crates it fronts and stays
# out of the workspace-wide jobs like them.
- name: Clippy (workshop)
env:
CARGO_BUILD_WARNINGS: deny
run: cargo clippy -p workshop -p workshop-server -p workshop-server-api --all-targets
# The Workshop crates' suites, including the workspace jail's Windows
# paths.
- name: Test (Windows)
shell: bash
run: >-
cargo nextest run --locked
-p workshop -p workshop-server -p workshop-server-api -p workshop-workspace
-E 'package(workshop) | package(workshop-server) | package(workshop-server-api)
| package(workshop-workspace)'
- name: Docs (workshop-server, private items)
env:
RUSTDOCFLAGS: -D warnings
run: cargo doc --locked --no-deps -p workshop-server --document-private-items
- name: Remove Gateway sidecar
if: always()
run: node tools/stage-gateway-sidecar.mjs remove --target x86_64-pc-windows-msvc
- name: Clean tree
shell: bash
run: |
if [ -n "$(git status --porcelain)" ]; then
echo "the build dirtied the repository:"
git status --porcelain
exit 1
fi
# First Linux build of the desktop app: compile-only, against the Tauri
# system packages a Linux developer installs. Catches the
# missing-system-package class of failure the Windows-only job cannot see.
check-workshop-linux:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Cache cargo
uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2
# A mirror that does not answer makes apt-get wait for a long time, so
# the step fails after 20 minutes. It normally takes under one.
- name: Install Tauri system packages
timeout-minutes: 20
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends libwebkit2gtk-4.1-dev libssl-dev librsvg2-dev
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
cache-dependency-path: crates/workshop/package-lock.json
- name: Install UI dependencies
run: npm ci --prefix crates/workshop
- name: Stage a stub Gateway sidecar
run: node tools/fetch-gateway-sidecar.mjs --stub --target x86_64-unknown-linux-gnu
- name: Build (workshop, Linux)
run: cargo build --locked -p workshop
- name: Remove Gateway sidecar
if: always()
run: node tools/stage-gateway-sidecar.mjs remove --target x86_64-unknown-linux-gnu
- name: Clean tree
shell: bash
run: |
if [ -n "$(git status --porcelain)" ]; then
echo "the build dirtied the repository:"
git status --porcelain
exit 1
fi
# The UI build is its own job: typecheck, bundle, and test. The cargo
# jobs drive the same bundle through the crates' build scripts, hence
# their npm ci.
ui:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
cache-dependency-path: crates/workshop/package-lock.json
- name: Install UI dependencies
working-directory: crates/workshop
run: npm ci
- name: Typecheck
working-directory: crates/workshop
run: npm run typecheck --workspaces --if-present
- name: Build
working-directory: crates/workshop
run: npm run build --workspace ui
- name: Test
working-directory: crates/workshop
run: npm test --workspaces --if-present
supply-chain:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: taiki-e/install-action@3f74d7c16a4242f1c95561e98edc25d36adb4375 # v2
with:
tool: cargo-deny, cargo-audit
- name: cargo deny
run: cargo deny check
- name: cargo audit
run: cargo audit
# The Workshop binary links exactly one rustls crypto backend,
# aws-lc-rs. This fails when `ring` re-enters its normal-edge closure
# (through a reqwest bump or a Tauri plugin default) and when
# `cargo tree` itself cannot run; only a successful, ring-free result
# passes. The Gateway has its own repository and its own checks.
- name: One rustls crypto backend in the Workshop
shell: bash
run: |
set -euo pipefail
if ! out="$(cargo tree --locked -p workshop -e normal -i ring --depth 0 2>&1)"; then
echo "cargo tree failed:"
printf '%s\n' "$out"
exit 1
fi
if printf '%s\n' "$out" | grep -v '^warning: nothing to print' | grep -q '^ring v'; then
echo "ring is linked into the workshop; aws-lc-rs is the only permitted rustls backend"
printf '%s\n' "$out"
exit 1
fi
# The custom lints, the dylint library in cppalliance/dylints at the
# rev the root Cargo.toml's [workspace.metadata.dylint] pins. `cargo
# dylint` fetches it and builds it on the nightly in its
# rust-toolchain.toml, which rustup installs with that file's components;
# the date is never repeated here. Its UI tests run in its own CI.
# `cargo dylint` checks every crate, the desktop app included, so this
# job installs what check-workshop-linux does. It runs on 24.04, not
# check-workshop-linux's 22.04: the prebuilt cargo-dylint and
# dylint-link binaries need glibc 2.38 or later, and 22.04 ships 2.35.
dylint:
runs-on: ubuntu-24.04
env:
# The Tauri system packages, named once for the two steps that hand
# them to apt-get.
TAURI_APT_PACKAGES: libwebkit2gtk-4.1-dev libssl-dev librsvg2-dev
steps:
- uses: actions/checkout@v4
# The same release as the `dylint_linting` the library depends on.
- name: Install cargo-dylint and dylint-link
uses: taiki-e/install-action@3f74d7c16a4242f1c95561e98edc25d36adb4375 # v2
with:
tool: cargo-dylint@6.3.2, dylint-link@6.3.2
- name: Cache cargo
uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2
# On this image apt can get the archives of the Tauri packages at
# about 60 kB/s, which is 20 minutes for 70 MB. It stays on that
# mirror, because its timeout fires only when no data arrives for 15
# seconds: https://github.com/actions/runner-images/issues/14823
# So this step and the three after it keep the archives in an Actions
# cache, and apt downloads only the ones the cache lacks. This step
# asks apt which archives it would download, and the cache key is a
# hash of their names, sizes, and hashes. The key leaves the addresses
# out, because the mirror differs from runner to runner. A mirror that
# does not answer makes apt-get wait for a long time, so the step
# fails after 10 minutes.
- name: List the archives of the Tauri system packages
id: apt-list
timeout-minutes: 10
shell: bash
run: |
set -euo pipefail
read -r -a packages <<< "$TAURI_APT_PACKAGES"
list="$RUNNER_TEMP/dylint-apt-archives.txt"
sudo apt-get update
# --print-uris prints one line for each archive apt would download:
# 'address' name size KIND:hash. ForceHash makes the hash the
# SHA-256 of the package index, where apt prints the MD5 sum by
# default. An archive whose line has no SHA-256 or SHA-512 is
# listed with `-` and is never cached.
name_form='^[A-Za-z0-9][A-Za-z0-9+._~%-]*\.deb$'
hash_form='^(SHA256:[0-9a-f]{64}|SHA512:[0-9a-f]{128})$'
: > "$list.unsorted"
unread=0
if uris="$(sudo apt-get install --print-uris -qq -y --no-install-recommends \
-o Acquire::ForceHash=sha256 "${packages[@]}")"; then
while read -r address name size hash _; do
if [[ "$name" =~ $name_form && "$size" =~ ^[0-9]+$ ]]; then
[[ "$hash" =~ $hash_form ]] || hash=-
printf '%s %s %s\n' "$name" "$size" "$hash" >> "$list.unsorted"
elif [ -n "$address" ]; then
unread=$((unread + 1))
fi
done <<< "$uris"
else
echo "::warning::apt-get could not list the archives of the Tauri packages, so this run uses no cache of them."
fi
# One order on every runner, so one list gives one key.
LC_ALL=C sort -u "$list.unsorted" > "$list" || : > "$list"
if [ "$unread" -ne 0 ]; then
echo "::warning::$unread lines of apt-get --print-uris do not have the form 'address' name size hash, so their archives are not cached."
fi
echo "apt would download $(wc -l < "$list") archives, and $(grep -c -v ' -$' "$list" || true) of them have a hash this job checks."
digest="$(sha256sum < "$list")" || digest=unlisted
{
echo "list=$list"
echo "dir=$RUNNER_TEMP/dylint-apt-archives"
echo "hash=${digest%% *}"
} >> "$GITHUB_OUTPUT"
# A run that finds no cache of its own list restores the newest cache
# of another list, and the next step takes from it the archives that
# are in both lists. A restore that fails, or that takes more than 10
# minutes, is a run with no cache.
- name: Restore the archives of the Tauri system packages
id: apt-cache
continue-on-error: true
timeout-minutes: 10
uses: actions/cache/restore@v6
with:
path: ${{ steps.apt-list.outputs.dir }}
key: dylint-apt-archives-${{ steps.apt-list.outputs.hash }}
restore-keys: dylint-apt-archives-
# apt takes an archive that is already in its directory when the size
# is right, and it checks no hash of it. So a restored file goes into
# that directory only when it has the hash that apt listed, and apt
# downloads every other archive itself. After the download the cache
# directory gets the listed archives and nothing else, each checked
# the same way, and that comes before the install in case the install
# removes them. A run with no cache downloads every archive, which
# takes about 20 minutes from a slow mirror, so the step fails after
# 30. With every archive in the cache it downloads nothing.
- name: Install Tauri system packages
id: apt-install
timeout-minutes: 30
shell: bash
env:
APT_LIST: ${{ steps.apt-list.outputs.list }}
APT_CACHE: ${{ steps.apt-list.outputs.dir }}
run: |
set -euo pipefail
read -r -a packages <<< "$TAURI_APT_PACKAGES"
list="${APT_LIST:-}"
cache="${APT_CACHE:-}"
# The cache directory is removed below, so it must be this job's.
case "$cache" in "$RUNNER_TEMP"/?*) ;; *) cache= ;; esac
archives=/var/cache/apt/archives/
eval "$(apt-config shell archives Dir::Cache::Archives/d || true)"
archives="${archives%/}"
[ -d "$archives" ] || archives=/var/cache/apt/archives
# Succeeds when the file $2 has the hash $1, which is SHA256:hex
# or SHA512:hex. A hash of any other kind is not checked, so the
# file fails.
has_hash() {
local actual
case "$1" in
SHA256:*) actual="$(sha256sum < "$2")" || return 1 ;;
SHA512:*) actual="$(sha512sum < "$2")" || return 1 ;;
*) return 1 ;;
esac
[ "${1%%:*}:${actual%% *}" = "$1" ]
}
staged=0
refused=0
if [ -n "$cache" ] && [ -d "$cache" ] && [ -f "$list" ]; then
while read -r name _ expected <&3; do
case "$expected" in SHA256:* | SHA512:*) ;; *) continue ;; esac
[ -f "$cache/$name" ] || continue
if ! has_hash "$expected" "$cache/$name"; then
refused=$((refused + 1))
echo "The restored $name does not have the hash $expected."
elif sudo cp -- "$cache/$name" "$archives/$name"; then
staged=$((staged + 1))
fi
done 3< "$list"
fi
echo "$staged archives come from the cache."
if [ "$refused" -ne 0 ]; then
echo "::warning::$refused restored archives do not have the hash that apt lists, so apt downloads them again. This job saves only archives that have that hash, so the restored cache is damaged or something else saved it. Delete that cache."
fi
sudo apt-get install --download-only -y --no-install-recommends "${packages[@]}"
kept=0
wanted=0
if [ -n "$cache" ] && [ -f "$list" ] && rm -rf -- "$cache" && mkdir -p -- "$cache"; then
while read -r name _ expected <&3; do
case "$expected" in SHA256:* | SHA512:*) ;; *) continue ;; esac
wanted=$((wanted + 1))
if [ -f "$archives/$name" ] && sudo cat -- "$archives/$name" > "$cache/$name" && has_hash "$expected" "$cache/$name"; then
kept=$((kept + 1))
else
rm -f -- "$cache/$name" || true
fi
done 3< "$list"
fi
complete=false
if [ "$wanted" -gt 0 ] && [ "$kept" -eq "$wanted" ]; then
complete=true
elif [ "$wanted" -gt 0 ]; then
echo "::warning::The cache directory holds $kept of the $wanted archives to cache, so this run saves no cache."
fi
echo "The cache directory holds $kept of the $wanted archives to cache."
echo "cache-complete=$complete" >> "$GITHUB_OUTPUT"
sudo apt-get install -y --no-install-recommends "${packages[@]}"
# A step of its own, before the lint, so that a run whose lint fails
# still saves the archives. A cache is never replaced, so a run that
# restored the cache of its own list saves nothing. A run whose cache
# directory lacks an archive of the list saves nothing either, because
# a later run would restore that cache and never fill it. A save that
# fails leaves the job as it is.
- name: Save the archives of the Tauri system packages
if: steps.apt-cache.outputs.cache-hit != 'true' && steps.apt-install.outputs.cache-complete == 'true'
continue-on-error: true
timeout-minutes: 10
uses: actions/cache/save@v6
with:
path: ${{ steps.apt-list.outputs.dir }}
key: dylint-apt-archives-${{ steps.apt-list.outputs.hash }}
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
cache-dependency-path: crates/workshop/package-lock.json
- name: Install UI dependencies
run: npm ci --prefix crates/workshop
- name: Stage a stub Gateway sidecar
run: node tools/fetch-gateway-sidecar.mjs --stub --target x86_64-unknown-linux-gnu
- name: Dylint
run: cargo dylint --all -- --locked --workspace --all-targets --all-features
- name: Remove Gateway sidecar
if: always()
run: node tools/stage-gateway-sidecar.mjs remove --target x86_64-unknown-linux-gnu
- name: Clean tree
shell: bash
run: |
if [ -n "$(git status --porcelain)" ]; then
echo "the build dirtied the repository:"
git status --porcelain
exit 1
fi
# The ten live tests of workshop-server, which a normal test run skips:
# they run Workshop's server, the Workshop program, and its window against
# a real Gateway. tools/live-tests.mjs gives each group of tests the
# Gateway state it needs, and names what it runs. The chat model is
# CheapSeek, a test server that speaks the OpenAI chat API and computes
# each reply from fixed rules, so the job runs without a model file or a
# provider's key. The Gateway is the release gateway-pin/pin.json names,
# which `cargo workshop` places beside the Workshop program it builds.
live:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Install cargo-nextest
uses: taiki-e/install-action@4dc1969decfa71b34f25aa7f3dd4656654d9ad1e # nextest
- name: Cache cargo
uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2
# The window tests drive Workshop through tauri-driver and WebKit's
# own driver, on a display that xvfb-run makes and a message bus that
# dbus-run-session makes.
- name: Install Tauri and window-test packages
timeout-minutes: 20
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends libwebkit2gtk-4.1-dev libssl-dev librsvg2-dev \
webkit2gtk-driver xvfb xauth dbus lsof
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
cache-dependency-path: crates/workshop/package-lock.json
- name: Install UI dependencies
run: npm ci --prefix crates/workshop
- name: Stage the pinned Gateway
run: node tools/fetch-gateway-sidecar.mjs --target x86_64-unknown-linux-gnu
- name: Build Workshop beside the Gateway
run: cargo workshop
- name: Install tauri-driver
run: cargo install tauri-driver --locked --version 2.1.0
# The action sets CHEAPSEEK_BASE_URL for the step after it.
- name: Start CheapSeek
uses: cppalliance/cheapseek@54d18ebefc024fb2bfe86a3556792303829bcd56 # v1.1.0
- name: Live tests
run: node tools/live-tests.mjs
- name: Remove Gateway sidecar
if: always()
run: node tools/stage-gateway-sidecar.mjs remove --target x86_64-unknown-linux-gnu
- name: Clean tree
shell: bash
run: |
if [ -n "$(git status --porcelain)" ]; then
echo "the build dirtied the repository:"
git status --porcelain
exit 1
fi
# Single required status check for branch protection: it fails when any
# job fails or is cancelled, so a cancelled job cannot read as green.
# needs: is a static list, so every newly added job must be added to it
# or that job bypasses this gate.
ci-green:
runs-on: ubuntu-latest
needs: [fmt, clippy, test, docs, check-workshop, check-workshop-linux, ui, supply-chain, dylint, live]
if: always()
steps:
- name: Verify every job succeeded
shell: bash
run: |
status=0
for result in ${{ join(needs.*.result, ' ') }}; do
if [ "$result" != "success" ]; then
echo "a required job did not succeed: $result"
status=1
fi
done
exit $status