Repository navigation
766 lines (749 loc) · 41.5 KB
/
Copy pathci.yml
File metadata and controls
766 lines (749 loc) · 41.5 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
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
# VisualCI's CI: lint, test (the CLI's crates; app/ with Postgres and RustFS; the Ruby client; the gallery library; the frontend
# build), then on main build and push the app and renderer images and deploy them by committing their digests to
# talira-ai/infra (k3s/resources/visualci/kustomization.yaml), which ArgoCD applies. That commit is the deploy;
# reverting it is the rollback.
name: CI
on:
push:
branches: [main]
pull_request:
workflow_dispatch:
# packages: read lets jobs pull the base images CI runs from ghcr.io/docspring/visualci/mirror (private; .github/mirror.txt).
permissions:
contents: read
packages: read
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
env:
CARGO_TERM_COLOR: always
jobs:
lint:
runs-on: ${{ fromJSON(vars.CI_RUNNER || '"ubuntu-latest"') }}
environment: ${{ github.ref == 'refs/heads/main' && 'kache-write' || '' }}
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
# Compile cache (kache, as Cargo's rustc wrapper): the R2 bucket every machine shares (KACHE_BUCKET), else the
# GitHub Actions cache. Only main writes it: the read-write key is a secret of the kache-write environment,
# which only main may use, so a pull request (whatever its ci.yml says) gets the read-only key.
- uses: kunobi-ninja/kache-action@061011817fd04b0e460f79d6bb3c115b1fc8f029 # v1
with:
version: "2.4.0"
cache-key-prefix: kache-${{ github.job }}
save-cache: ${{ github.ref == 'refs/heads/main' }}
pr-comment: false
s3-bucket: ${{ vars.KACHE_BUCKET }}
s3-endpoint: ${{ vars.KACHE_ENDPOINT }}
s3-region: auto
s3-prefix: rust
# One manifest per kind of build (kache's prefetch list and its shards), so clippy's doesn't overwrite the
# tests'. visual-capture and journeys build the same binaries and share one. The bucket (docspring-kache, near
# GitHub's runners) is shared by every DocSpring Rust project under one prefix: its entries are addressed by
# their inputs, so sharing them is safe; each project's manifest keys start with its name. For the same reason
# a writer could poison every project's builds (an entry's content isn't checked against its key), so the
# read-write key goes only to main-branch jobs of DocSpring's own repositories, in a protected environment;
# forks and repositories that run outside contributors' code on main get the read-only key at most.
manifest-key: visualci-clippy
s3-access-key-id: ${{ github.ref == 'refs/heads/main' && secrets.KACHE_RW_ACCESS_KEY_ID || secrets.KACHE_RO_ACCESS_KEY_ID }}
s3-secret-access-key: ${{ github.ref == 'refs/heads/main' && secrets.KACHE_RW_SECRET_ACCESS_KEY || secrets.KACHE_RO_SECRET_ACCESS_KEY }}
- run: rustup show active-toolchain || rustup toolchain install
- run: cargo fmt --all --check
- run: cargo clippy --locked --workspace --all-targets -- -D warnings
# snapshot-diff goes on crates.io: it builds without its schemars feature too.
- run: cargo clippy --locked -p snapshot-diff --no-default-features --all-targets -- -D warnings
# The app (app/, Laravel Rust, the root workspace's visualci-app). Its tests also render every customer email as HTML
# and text for the visual job. fmt and clippy cover it in the lint job.
app:
runs-on: ${{ fromJSON(vars.CI_RUNNER || '"ubuntu-latest"') }}
environment: ${{ github.ref == 'refs/heads/main' && 'kache-write' || '' }}
timeout-minutes: 40
services:
postgres:
image: ghcr.io/docspring/visualci/mirror/postgres:17@sha256:e711be2c7ff64c9eb8883fc87571621be6caa2f943d825a49e5d20ac5b0221d7
credentials:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
env:
POSTGRES_USER: visualci
POSTGRES_PASSWORD: visualci
POSTGRES_DB: visualci_app_test
ports: ["55433:5432"]
options: --health-cmd pg_isready --health-interval 5s --health-timeout 5s --health-retries 10
steps:
- uses: actions/checkout@v4
# Base images come from GHCR's copy of Docker Hub (.github/mirror.txt), pinned by digest, so a Docker Hub outage
# can't fail the job.
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# S3 storage for the blob tests: RustFS, as the visual-capture job uses.
- run: |
image=ghcr.io/docspring/visualci/mirror/rustfs:1.0.6@sha256:0dff1515b3c52b5ce8c5df2263420c7f93ae1c5d07cca79e19e57cff86b84c85
scripts/ci/pull.sh "$image"
docker run -d --name s3 -p 59000:9000 \
-e RUSTFS_ACCESS_KEY=visualci -e RUSTFS_SECRET_KEY=visualci-dev-secret "$image"
for _ in $(seq 1 30); do curl -s -o /dev/null http://127.0.0.1:59000/ && break; sleep 1; done
# Trial (c) on this job: rust-cache restores target/ (incremental state and our own crates), with kache behind
# it for dependency misses. Its key covers Cargo.lock and the toolchain; only main saves it, like kache.
- uses: Swatinem/rust-cache@v2
with:
save-if: ${{ github.ref == 'refs/heads/main' }}
# Compile cache (kache, as Cargo's rustc wrapper): the R2 bucket every machine shares (KACHE_BUCKET), else the
# GitHub Actions cache. Only main writes it: the read-write key is a secret of the kache-write environment,
# which only main may use, so a pull request (whatever its ci.yml says) gets the read-only key.
- uses: kunobi-ninja/kache-action@061011817fd04b0e460f79d6bb3c115b1fc8f029 # v1
with:
version: "2.4.0"
cache-key-prefix: kache-${{ github.job }}
save-cache: ${{ github.ref == 'refs/heads/main' }}
pr-comment: false
s3-bucket: ${{ vars.KACHE_BUCKET }}
s3-endpoint: ${{ vars.KACHE_ENDPOINT }}
s3-region: auto
s3-prefix: rust
manifest-key: visualci-app-test
s3-access-key-id: ${{ github.ref == 'refs/heads/main' && secrets.KACHE_RW_ACCESS_KEY_ID || secrets.KACHE_RO_ACCESS_KEY_ID }}
s3-secret-access-key: ${{ github.ref == 'refs/heads/main' && secrets.KACHE_RW_SECRET_ACCESS_KEY || secrets.KACHE_RO_SECRET_ACCESS_KEY }}
- run: rustup show active-toolchain || rustup toolchain install
- run: cargo test --locked -p visualci-app
env:
VISUALCI_EMAIL_SNAPSHOTS: ${{ github.workspace }}/tmp/email-snapshots
# The blob store's own account of a failed run (a bucket that went missing, a restart): RustFS logs to stdout.
- if: failure()
run: docker logs s3 2>&1 | tail -n 300
- uses: actions/upload-artifact@v4
with:
name: email-snapshots
path: tmp/email-snapshots
if-no-files-found: error
retention-days: 7
# The CLI changed since its last release without a version bump: the docs would describe a CLI nobody can download.
# Not needed by deploy, so it never holds back a release.
cli-version:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- run: scripts/ci/cli_version.sh
# Migrations run before the rollout, so the release still serving must work with the new schema: a new migration
# mustn't drop, rename or retype what main's code reads (4 Dec 2026: a dropped column failed requests for ~20 s).
- run: python3 -m unittest scripts/ci/test_migration_safety.py
- env:
BASE: ${{ github.event.pull_request.base.sha || github.event.before }}
run: |
if [ -z "$BASE" ] || [ "$BASE" = 0000000000000000000000000000000000000000 ]; then
echo "No earlier commit to compare with."
else
python3 scripts/ci/migration_safety.py "$BASE"
fi
# The CircleCI orb's scripts (clients/circleci-orb), rendered and linted: validating it with CircleCI needs a token.
orb:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v4
- run: command -v shellcheck >/dev/null || (sudo apt-get update && sudo apt-get install -y shellcheck)
- run: python3 -c 'import yaml' 2>/dev/null || pip install pyyaml
- run: python3 scripts/ci/check_orb.py
# The CLI and its crates (crates/*: the CLI, core, renderer, snapshot-diff, wasm), built apart from the app so its
# dependencies' features (such as serde_json's preserve_order) don't reach the CLI's tests.
test:
runs-on: ${{ fromJSON(vars.CI_RUNNER || '"ubuntu-latest"') }}
environment: ${{ github.ref == 'refs/heads/main' && 'kache-write' || '' }}
timeout-minutes: 40
steps:
- uses: actions/checkout@v4
# Compile cache (kache, as Cargo's rustc wrapper): the R2 bucket every machine shares (KACHE_BUCKET), else the
# GitHub Actions cache. Only main writes it: the read-write key is a secret of the kache-write environment,
# which only main may use, so a pull request (whatever its ci.yml says) gets the read-only key.
- uses: kunobi-ninja/kache-action@061011817fd04b0e460f79d6bb3c115b1fc8f029 # v1
with:
version: "2.4.0"
cache-key-prefix: kache-${{ github.job }}
save-cache: ${{ github.ref == 'refs/heads/main' }}
pr-comment: false
s3-bucket: ${{ vars.KACHE_BUCKET }}
s3-endpoint: ${{ vars.KACHE_ENDPOINT }}
s3-region: auto
s3-prefix: rust
manifest-key: visualci-crates-test
s3-access-key-id: ${{ github.ref == 'refs/heads/main' && secrets.KACHE_RW_ACCESS_KEY_ID || secrets.KACHE_RO_ACCESS_KEY_ID }}
s3-secret-access-key: ${{ github.ref == 'refs/heads/main' && secrets.KACHE_RW_SECRET_ACCESS_KEY || secrets.KACHE_RO_SECRET_ACCESS_KEY }}
- run: cargo test --locked --workspace --exclude visualci-app
# VisualCI tests itself: screenshots of the landing page, docs and app (against seeded data), Vitest component
# snapshots, app/'s JSON golden files and the emails from `app`, sent as one build to the docspring/visualci project.
# visual-capture takes them while `app` runs its tests, and `visual` sends them with app's emails once both are done.
visual-capture:
runs-on: ${{ fromJSON(vars.CI_RUNNER || '"ubuntu-latest"') }}
environment: ${{ github.ref == 'refs/heads/main' && 'kache-write' || '' }}
timeout-minutes: 30
services:
postgres:
image: ghcr.io/docspring/visualci/mirror/postgres:17@sha256:e711be2c7ff64c9eb8883fc87571621be6caa2f943d825a49e5d20ac5b0221d7
credentials:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
env:
POSTGRES_USER: loco
POSTGRES_PASSWORD: loco
POSTGRES_DB: visualci_screenshots
ports: ["55433:5432"]
options: --health-cmd pg_isready --health-interval 5s --health-timeout 5s --health-retries 10
steps:
- uses: actions/checkout@v4
with:
# As `visual` has it, so the site and docs build from the same history.
fetch-depth: 101
# Base images come from GHCR's copy of Docker Hub (.github/mirror.txt), pinned by digest, so a Docker Hub outage
# can't fail the job.
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# S3 storage for the seeded blobs: RustFS (Apache-2.0), since MinIO's images are no longer public. A step rather
# than a service, so the job doesn't wait on a health check the image doesn't define.
- run: |
image=ghcr.io/docspring/visualci/mirror/rustfs:1.0.6@sha256:0dff1515b3c52b5ce8c5df2263420c7f93ae1c5d07cca79e19e57cff86b84c85
scripts/ci/pull.sh "$image"
docker run -d --name s3 -p 59000:9000 \
-e RUSTFS_ACCESS_KEY=visualci -e RUSTFS_SECRET_KEY=visualci-dev-secret "$image"
for _ in $(seq 1 30); do curl -s -o /dev/null http://127.0.0.1:59000/ && break; sleep 1; done
# Compile cache (kache, as Cargo's rustc wrapper): the R2 bucket every machine shares (KACHE_BUCKET), else the
# GitHub Actions cache. Only main writes it: the read-write key is a secret of the kache-write environment,
# which only main may use, so a pull request (whatever its ci.yml says) gets the read-only key.
- uses: kunobi-ninja/kache-action@061011817fd04b0e460f79d6bb3c115b1fc8f029 # v1
with:
version: "2.4.0"
cache-key-prefix: kache-${{ github.job }}
save-cache: ${{ github.ref == 'refs/heads/main' }}
pr-comment: false
s3-bucket: ${{ vars.KACHE_BUCKET }}
s3-endpoint: ${{ vars.KACHE_ENDPOINT }}
s3-region: auto
s3-prefix: rust
manifest-key: visualci-dev-bins
s3-access-key-id: ${{ github.ref == 'refs/heads/main' && secrets.KACHE_RW_ACCESS_KEY_ID || secrets.KACHE_RO_ACCESS_KEY_ID }}
s3-secret-access-key: ${{ github.ref == 'refs/heads/main' && secrets.KACHE_RW_SECRET_ACCESS_KEY || secrets.KACHE_RO_SECRET_ACCESS_KEY }}
# The CLI and the app the screenshots are taken against, each built on its own (so the CLI is the one users get).
- run: cargo build --locked -p visualci-cli
- run: cargo build --locked -p visualci-app --bin visualci-app
- uses: pnpm/action-setup@v4
with:
package_json_file: frontend/package.json
- uses: actions/setup-node@v4
with:
node-version: "24"
# skills/ is generated from the docs pages: fail when someone edited one without the other.
- run: node scripts/skills.mjs --check
working-directory: frontend
- run: pnpm install --frozen-lockfile && pnpm build
working-directory: frontend
env:
GITHUB_TOKEN: ${{ github.token }} # the docs' CLI release (scripts/cli-version.mjs)
- run: pnpm install --frozen-lockfile && pnpm --filter visualci-gallery build
working-directory: clients/gallery
- uses: ./.github/actions/playwright
with:
save: ${{ github.ref == 'refs/heads/main' }}
- run: scripts/ci/visual.sh capture
# What `visual` sends, in one file: the screenshots and site files, the Vitest snapshots (written into
# frontend/src, which git ignores) and the CLI this commit built, without its debug info.
- run: |
strip -o tmp/visualci target/debug/visualci
find frontend/src -path '*/__snapshots__/*' -type f >tmp/vitest-snapshots
tar czf tmp/visual-capture.tgz tmp/visual tmp/visualci -T tmp/vitest-snapshots
ls -lh tmp/visual-capture.tgz
- uses: actions/upload-artifact@v4
with:
name: visual-capture
path: tmp/visual-capture.tgz
if-no-files-found: error
retention-days: 7
- if: failure()
uses: actions/upload-artifact@v4
with:
name: visual
path: tmp/visual
retention-days: 7
# A changed snapshot doesn't fail this job: the GitHub check waits for review. It runs when app or visual-capture
# failed too, and fails, so this required check is never skipped. One job sends the whole build, so re-running it
# alone (after a flaky `app`) sends the same build again. Pull requests from forks have no token and skip the upload.
visual:
needs: [app, visual-capture]
if: ${{ !cancelled() }}
runs-on: ${{ fromJSON(vars.CI_RUNNER || '"ubuntu-latest"') }}
timeout-minutes: 10
steps:
- env:
APP: ${{ needs.app.result }}
CAPTURE: ${{ needs.visual-capture.result }}
run: |
if [ "$APP" != success ] || [ "$CAPTURE" != success ]; then
echo "::error::Nothing to send: app was $APP and visual-capture was $CAPTURE."
exit 1
fi
- uses: actions/checkout@v4
with:
# The CLI sends parent commits, so the build finds its baseline.
fetch-depth: 101
- uses: actions/download-artifact@v4
with:
name: visual-capture
path: tmp
- run: tar xzf tmp/visual-capture.tgz
- uses: actions/download-artifact@v4
with:
name: email-snapshots
path: tmp/email-snapshots
# VisualCI's own GitHub Action (clients/github-action), with the CLI this commit built.
- uses: ./clients/github-action
with:
token: ${{ secrets.VISUALCI_TOKEN }}
cli: tmp/visualci
upload: |
tmp/visual/screenshots --prefix screenshots/ --platform chrome-linux
tmp/visual/site --prefix site/
tmp/visual/og --prefix og/
tmp/visual/site/docs/quick-start.md --prefix site/docs/ --format text
frontend/src --from vitest --prefix components/
app/tests/golden/api --prefix json/api/ --format json
app/tests/golden/mcp --prefix json/mcp/ --format json
app/tests/golden/mcp_admin --prefix json/mcp_admin/ --format json
tmp/email-snapshots --prefix emails/ --keep-extension
# The journeys (scripts/journeys/run.sh): VisualCI as production runs it, on four .test hosts behind Caddy with
# TLS and a GitHub stub, clicked through in a browser. Each step's screenshot goes to VisualCI as the `journeys`
# build (its own check, "VisualCI: journeys").
journeys:
runs-on: ${{ fromJSON(vars.CI_RUNNER || '"ubuntu-latest"') }}
environment: ${{ github.ref == 'refs/heads/main' && 'kache-write' || '' }}
timeout-minutes: 30
services:
postgres:
image: ghcr.io/docspring/visualci/mirror/postgres:17@sha256:e711be2c7ff64c9eb8883fc87571621be6caa2f943d825a49e5d20ac5b0221d7
credentials:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
env:
POSTGRES_USER: loco
POSTGRES_PASSWORD: loco
POSTGRES_DB: visualci_journeys
ports: ["55433:5432"]
options: --health-cmd pg_isready --health-interval 5s --health-timeout 5s --health-retries 10
env:
VISUALCI_SITE_URL: https://visualci.test
VISUALCI_APP_URL: https://app.visualci.test
VISUALCI_API_URL: https://api.visualci.test
VISUALCI_MCP_URL: https://mcp.visualci.test
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 101
- run: echo "127.0.0.1 visualci.test app.visualci.test api.visualci.test mcp.visualci.test github.test" | sudo tee -a /etc/hosts
# Base images come from GHCR's copy of Docker Hub (.github/mirror.txt), pinned by digest, so a Docker Hub outage
# can't fail the job.
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- run: |
image=ghcr.io/docspring/visualci/mirror/rustfs:1.0.6@sha256:0dff1515b3c52b5ce8c5df2263420c7f93ae1c5d07cca79e19e57cff86b84c85
scripts/ci/pull.sh "$image"
docker run -d --name s3 -p 59000:9000 \
-e RUSTFS_ACCESS_KEY=visualci -e RUSTFS_SECRET_KEY=visualci-dev-secret "$image"
for _ in $(seq 1 30); do curl -s -o /dev/null http://127.0.0.1:59000/ && break; sleep 1; done
- uses: kunobi-ninja/kache-action@061011817fd04b0e460f79d6bb3c115b1fc8f029 # v1
with:
version: "2.4.0"
cache-key-prefix: kache-${{ github.job }}
save-cache: ${{ github.ref == 'refs/heads/main' }}
pr-comment: false
s3-bucket: ${{ vars.KACHE_BUCKET }}
s3-endpoint: ${{ vars.KACHE_ENDPOINT }}
s3-region: auto
s3-prefix: rust
manifest-key: visualci-dev-bins
s3-access-key-id: ${{ github.ref == 'refs/heads/main' && secrets.KACHE_RW_ACCESS_KEY_ID || secrets.KACHE_RO_ACCESS_KEY_ID }}
s3-secret-access-key: ${{ github.ref == 'refs/heads/main' && secrets.KACHE_RW_SECRET_ACCESS_KEY || secrets.KACHE_RO_SECRET_ACCESS_KEY }}
- run: cargo build --locked -p visualci-cli
- run: cargo build --locked -p visualci-app --bin visualci-app
- uses: pnpm/action-setup@v4
with:
package_json_file: frontend/package.json
- uses: actions/setup-node@v4
with:
node-version: "24"
# The site and the app's page, built for the .test hosts (scripts/hosts.mjs reads VISUALCI_*_URL)
- run: pnpm install --frozen-lockfile && pnpm build && node scripts/site.mjs
working-directory: frontend
env:
GITHUB_TOKEN: ${{ github.token }}
- uses: ./.github/actions/playwright
with:
save: ${{ github.ref == 'refs/heads/main' }}
- run: |
scripts/ci/pull.sh "$CADDY_IMAGE"
scripts/journeys/run.sh
env:
CADDY_IMAGE: ghcr.io/docspring/visualci/mirror/caddy:2.11.9@sha256:fc9cbc100585871d18d4e451cca7021785c90a7006087427ae5ceb3e4efe6424
DATABASE_URL: postgres://loco:loco@127.0.0.1:55433/visualci_journeys
# The screenshots go up even when a journey failed: its last one shows where it stopped.
- if: ${{ !cancelled() }}
uses: ./clients/github-action
with:
token: ${{ secrets.VISUALCI_TOKEN }}
cli: target/debug/visualci
name: journeys
upload: |
tmp/journeys/screenshots --prefix journeys/ --platform chrome-linux
- if: failure()
uses: actions/upload-artifact@v4
with:
name: journeys
path: tmp/journeys
retention-days: 7
clients:
runs-on: ${{ fromJSON(vars.CI_RUNNER || '"ubuntu-latest"') }}
environment: ${{ github.ref == 'refs/heads/main' && 'kache-write' || '' }}
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
# The GitHub Action (sc-9246): with no token and no VISUALCI_TOKEN it fails, so a missing or misnamed secret
# can't pass quietly; with VISUALCI_TOKEN only in env, every CLI call gets it. It skips fork and Dependabot
# runs, so these checks run only on this repository's own.
- id: no-token
if: github.actor != 'dependabot[bot]' && !github.event.repository.fork && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository)
uses: ./clients/github-action
continue-on-error: true
- if: github.actor != 'dependabot[bot]' && !github.event.repository.fork && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository)
env:
OUTCOME: ${{ steps.no-token.outcome }}
SKIPPED: ${{ steps.no-token.outputs.skipped }}
run: |
if [ "$OUTCOME" != failure ] || [ -n "$SKIPPED" ]; then
echo "::error::the action without a token should fail at its token step (outcome $OUTCOME, skipped '$SKIPPED')"
exit 1
fi
# A stub CLI that records the token each call gets.
cat > "$RUNNER_TEMP/visualci-stub" <<'STUB'
#!/bin/sh
echo "$1 $VISUALCI_TOKEN" >> "$RUNNER_TEMP/visualci-stub.log"
[ "$1" = build ] && [ "$2" = create ] && echo 1
exit 0
STUB
- id: env-token
if: github.actor != 'dependabot[bot]' && !github.event.repository.fork && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository)
uses: ./clients/github-action
env:
VISUALCI_TOKEN: env-only-token
with:
cli: ${{ runner.temp }}/visualci-stub
upload: some/dir
- if: github.actor != 'dependabot[bot]' && !github.event.repository.fork && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository)
env:
SKIPPED: ${{ steps.env-token.outputs.skipped }}
run: |
cat "$RUNNER_TEMP/visualci-stub.log"
[ "$SKIPPED" = false ] || { echo "::error::skipped with VISUALCI_TOKEN in env ($SKIPPED)"; exit 1; }
[ "$(grep -c ' env-only-token$' "$RUNNER_TEMP/visualci-stub.log")" = 3 ] || { echo "::error::not every CLI call got the env token"; exit 1; }
- uses: ruby/setup-ruby@v1
with:
ruby-version: "3.4"
- run: ruby -Ilib spec/visualci_spec.rb
working-directory: clients/ruby
# The gallery's Ruby renderer: the contract's golden fixtures.
- run: ruby -Ilib test/gallery_test.rb
working-directory: clients/gallery/ruby
- uses: pnpm/action-setup@v4
with:
package_json_file: frontend/package.json
- uses: actions/setup-node@v4
with:
node-version: "24"
# The gallery (clients/gallery, a pnpm workspace): the library's type check and build (the ES5 file's test reads
# it), then every package's tests, which check the contract's golden fixtures (the Astro component's include a
# real astro build).
- run: pnpm install --frozen-lockfile && pnpm --filter visualci-gallery typecheck && pnpm build && pnpm test
working-directory: clients/gallery
# The gem carries the library's built script and stylesheet, and the licence: it builds with them.
- run: bin/assets && gem build visualci-gallery.gemspec && tar -xOf visualci-gallery-*.gem data.tar.gz | tar -tz > /tmp/gem-files && grep -x app/assets/javascripts/visualci_gallery.js /tmp/gem-files && grep -x LICENSE /tmp/gem-files
working-directory: clients/gallery/ruby
# The gallery's Python renderer: the contract's golden fixtures, on the oldest Python it supports and the newest.
- uses: actions/setup-python@v5
with:
python-version: |
3.10
3.14
- run: python3.10 -W error -m unittest discover -s tests && python3.14 -W error -m unittest discover -s tests
working-directory: clients/gallery/python
env:
PYTHONPATH: src
# Its wheel carries the library's built script and stylesheet.
- run: bin/assets && python3.14 -m pip install --quiet build && python3.14 -m build --wheel && unzip -l dist/*.whl | grep -q visualci_gallery/static/visualci_gallery/visualci_gallery.js
working-directory: clients/gallery/python
# The gallery's Rust renderer (its own workspace): the contract's golden fixtures, Askama included, and clippy.
- run: cargo test --locked --all-features && cargo clippy --locked --all-features --all-targets -- -D warnings
working-directory: clients/gallery/rust
# The Compare two PDFs page runs crates/visualci-wasm in the browser (scripts/wasm.mjs builds it).
- run: rustup target add wasm32-unknown-unknown
# Compile cache (kache, as Cargo's rustc wrapper): the R2 bucket every machine shares (KACHE_BUCKET), else the
# GitHub Actions cache. Only main writes it: the read-write key is a secret of the kache-write environment,
# which only main may use, so a pull request (whatever its ci.yml says) gets the read-only key.
- uses: kunobi-ninja/kache-action@061011817fd04b0e460f79d6bb3c115b1fc8f029 # v1
with:
version: "2.4.0"
cache-key-prefix: kache-${{ github.job }}
save-cache: ${{ github.ref == 'refs/heads/main' }}
pr-comment: false
s3-bucket: ${{ vars.KACHE_BUCKET }}
s3-endpoint: ${{ vars.KACHE_ENDPOINT }}
s3-region: auto
s3-prefix: rust
manifest-key: visualci-wasm
s3-access-key-id: ${{ github.ref == 'refs/heads/main' && secrets.KACHE_RW_ACCESS_KEY_ID || secrets.KACHE_RO_ACCESS_KEY_ID }}
s3-secret-access-key: ${{ github.ref == 'refs/heads/main' && secrets.KACHE_RW_SECRET_ACCESS_KEY || secrets.KACHE_RO_SECRET_ACCESS_KEY }}
# The production site: with the Plausible snippets (analytics.ts) and, required, the WebAssembly.
- run: pnpm install --frozen-lockfile && VISUALCI_ANALYTICS=1 VISUALCI_REQUIRE_WASM=1 pnpm build
working-directory: frontend
env:
GITHUB_TOKEN: ${{ github.token }} # the docs' CLI release (scripts/cli-version.mjs)
# visualci.com's static site: assembled from the build and checked (every docs page has its Markdown copy, and
# llms.txt links each one), then deployed by the site job.
- run: VISUALCI_ANALYTICS=1 node scripts/site.mjs
working-directory: frontend
env:
GITHUB_TOKEN: ${{ github.token }}
VISUALCI_REQUIRE_WASM: "1"
- uses: actions/upload-artifact@v4
with:
name: dist-site
path: frontend/dist-site
# .well-known/agent-skills/ is hidden, and upload-artifact leaves hidden files out by default.
include-hidden-files: true
retention-days: 7
# visualci.com is a Cloudflare Worker with static assets (frontend/site/wrangler.jsonc), deployed on main
# before the app, so the apex never points at an app that no longer serves it. Needs the repo secret
# CLOUDFLARE_API_TOKEN (Workers Scripts on the DocSpring Products account, Workers Routes on visualci.com) and the
# repo variable CLOUDFLARE_ACCOUNT_ID; without them it warns and skips.
site:
needs: [lint, test, clients]
if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request'
runs-on: ${{ fromJSON(vars.CI_RUNNER || '"ubuntu-latest"') }}
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: dist-site
path: frontend/dist-site
- uses: actions/setup-node@v4
with:
node-version: "24"
- name: Deploy to Cloudflare
working-directory: frontend/site
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ vars.CLOUDFLARE_ACCOUNT_ID }}
WRANGLER_SEND_METRICS: "false"
run: |
if [ -z "$CLOUDFLARE_API_TOKEN" ] || [ -z "$CLOUDFLARE_ACCOUNT_ID" ]; then
echo "::warning::CLOUDFLARE_API_TOKEN or CLOUDFLARE_ACCOUNT_ID isn't set: visualci.com wasn't deployed."
exit 0
fi
npx --yes wrangler@4.168.0 deploy
# The app's and the renderer's release binaries, built with the compile cache in the rust image the Dockerfiles use
# (so the same Debian and glibc as the runtime images), for `images` to put in the images. Starts with the run, in
# parallel with the tests. Pull requests build them too, and `images` builds without pushing there, so a change that
# breaks an image fails its pull request instead of main's deploy.
release-bins:
runs-on: ${{ fromJSON(vars.CI_RUNNER || '"ubuntu-latest"') }}
environment: ${{ github.ref == 'refs/heads/main' && 'kache-write' || '' }}
# The renderer's inputs hash (in `images`) greps this image line: keep it on one line.
container:
image: ghcr.io/docspring/visualci/mirror/rust:1.99.1-trixie@sha256:3ddd9771c00ed2c214d75ba497ad28691ebeaf2279476068dd191cf39b4be033
credentials:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- uses: kunobi-ninja/kache-action@061011817fd04b0e460f79d6bb3c115b1fc8f029 # v1
with:
version: "2.4.0"
cache-key-prefix: kache-${{ github.job }}
save-cache: ${{ github.ref == 'refs/heads/main' }}
pr-comment: false
s3-bucket: ${{ vars.KACHE_BUCKET }}
s3-endpoint: ${{ vars.KACHE_ENDPOINT }}
s3-region: auto
s3-prefix: rust
manifest-key: visualci-release
s3-access-key-id: ${{ github.ref == 'refs/heads/main' && secrets.KACHE_RW_ACCESS_KEY_ID || secrets.KACHE_RO_ACCESS_KEY_ID }}
s3-secret-access-key: ${{ github.ref == 'refs/heads/main' && secrets.KACHE_RW_SECRET_ACCESS_KEY || secrets.KACHE_RO_SECRET_ACCESS_KEY }}
- run: cargo build --release --locked -p visualci-app --bin visualci-app
env:
BUILD_SHA: ${{ github.sha }}
# Built on its own, as its Dockerfile does, so the app's dependency features don't reach it.
- run: cargo build --release --locked -p visualci-renderer
- run: mkdir -p tmp/bin && cp target/release/visualci-app target/release/visualci-renderer tmp/bin/
- uses: actions/upload-artifact@v4
with:
name: release-bins
path: tmp/bin
if-no-files-found: error
retention-days: 3
images:
needs: [lint, test, app, clients, release-bins]
runs-on: ${{ fromJSON(vars.CI_RUNNER || '"ubuntu-latest"') }}
# main pushes the images and writes BuildKit's layer cache (in the kache bucket, under buildkit/) with the read-write
# key of the kache-write environment; pull requests build them with the read-only key and push nothing.
environment: ${{ github.ref == 'refs/heads/main' && 'kache-write' || '' }}
timeout-minutes: 30
permissions:
contents: read
packages: write
env:
PUSH: ${{ github.ref == 'refs/heads/main' && github.event_name != 'pull_request' }}
S3_CACHE: type=s3,region=auto,bucket=${{ vars.KACHE_BUCKET }},endpoint_url=${{ vars.KACHE_ENDPOINT }},use_path_style=true,prefix=buildkit/,access_key_id=${{ github.ref == 'refs/heads/main' && secrets.KACHE_RW_ACCESS_KEY_ID || secrets.KACHE_RO_ACCESS_KEY_ID }},secret_access_key=${{ github.ref == 'refs/heads/main' && secrets.KACHE_RW_SECRET_ACCESS_KEY || secrets.KACHE_RO_SECRET_ACCESS_KEY }}
outputs:
app: ${{ steps.app.outputs.digest }}
renderer: ${{ steps.renderer.outputs.digest }}
steps:
- uses: actions/checkout@v4
- id: version
env:
GH_TOKEN: ${{ github.token }}
run: |
echo "renderer=$(cat docker/renderer.version)" >>"$GITHUB_OUTPUT"
# The CLI release the app's add-to-CI snippets install (frontend/scripts/cli-version.mjs): a build arg, so a
# new release rebuilds the cached frontend layer
echo "cli=$(gh api repos/DocSpring/visualci/releases/latest --jq .tag_name)" >>"$GITHUB_OUTPUT"
- uses: actions/download-artifact@v4
with:
name: release-bins
path: tmp/bin
- run: chmod +x tmp/bin/*
# Logged in on pull requests too: BuildKit and the Dockerfiles' base images come from ghcr.io/docspring/visualci/mirror.
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/setup-buildx-action@v3
with:
driver-opts: image=ghcr.io/docspring/visualci/mirror/buildkit:buildx-stable-1@sha256:7583a0667093d941826bcd1d2878d6a360dfd08a82c93e6d6a6f6cce78801e12
# The app (app/), which serves the API, the web app, MCP and the site's pages on its hosts
- id: app
uses: docker/build-push-action@v6
with:
context: .
file: docker/app.Dockerfile
# The Dockerfiles' FROM images, from the mirror (the same digests as Docker Hub's; local builds use Docker Hub)
build-contexts: |
bin=tmp/bin
rust:1.99.1-trixie=docker-image://ghcr.io/docspring/visualci/mirror/rust:1.99.1-trixie@sha256:3ddd9771c00ed2c214d75ba497ad28691ebeaf2279476068dd191cf39b4be033
node:24-trixie-slim=docker-image://ghcr.io/docspring/visualci/mirror/node:24-trixie-slim@sha256:efb444a6c8b45a1ebdd70974912147dc2be917714174f52334e236aa23c0e3a6
debian:trixie-slim=docker-image://ghcr.io/docspring/visualci/mirror/debian:trixie-slim@sha256:ab3b3c8c5159eebfca4376430132d53c4d425f869c765ecbe47177a030da575d
push: ${{ env.PUSH == 'true' }}
build-args: |
BUILD_SHA=${{ github.sha }}
RENDERER_VERSION=${{ steps.version.outputs.renderer }}
VISUALCI_ANALYTICS=1
VISUALCI_CLI_VERSION=${{ steps.version.outputs.cli }}
tags: ghcr.io/docspring/visualci-app:${{ github.sha }}
cache-from: ${{ env.S3_CACHE }},name=visualci-app
cache-to: ${{ env.PUSH == 'true' && format('{0},name=visualci-app,mode=max,ignore-error=true', env.S3_CACHE) || '' }}
# The renderer is rebuilt only when its inputs change, so its digest (and the running renderers) stay put
# through deploys that only touch the app. Rebuilding an unchanged renderer would give a new digest and roll
# the renderers mid-build for nothing. Its inputs: the workspace crates it's built from, the toolchain, the
# workspace's build settings (Cargo.toml without the version, which every CLI release bumps), and the exact
# crates it's built from (its dependency tree, without the workspace's own crates, whose sources are hashed
# here already). The whole Cargo.lock also holds app/'s and the CLI's dependencies, which never reach it.
- run: rustup show active-toolchain || rustup toolchain install
- id: renderer_inputs
run: |
set -euo pipefail
tree=$(cargo tree --locked -p visualci-renderer -e normal,build --prefix none --format '{p}' | sort -u)
# The workspace's own crates it uses (visualci-core, snapshot-diff, itself): their sources, by path.
paths=$(echo "$tree" | sed -n 's|.* (\(/.*\))$|\1|p' | sed "s|^$PWD/||")
deps=$(echo "$tree" | grep -v ' (/')
# shellcheck disable=SC2086
# The image release-bins compiles it in (its `container:`) is an input too.
hash=$( { git ls-files -s docker/renderer.Dockerfile docker/renderer.version rust-toolchain.toml $paths; grep -v '^version = ' Cargo.toml; echo "$deps"; grep -m1 '^ *image: ghcr.io/docspring/visualci/mirror/rust:' .github/workflows/ci.yml; } | sha256sum | cut -c1-24)
echo "tag=ghcr.io/docspring/visualci-renderer:inputs-$hash" >>"$GITHUB_OUTPUT"
if digest=$(docker buildx imagetools inspect "ghcr.io/docspring/visualci-renderer:inputs-$hash" --format '{{json .Manifest}}' 2>/dev/null | python3 -c 'import json,sys; print(json.load(sys.stdin)["digest"])'); then
echo "existing=$digest" >>"$GITHUB_OUTPUT"
echo "::notice::Renderer inputs unchanged: reusing $digest"
fi
- id: renderer_build
if: steps.renderer_inputs.outputs.existing == ''
uses: docker/build-push-action@v6
with:
context: .
file: docker/renderer.Dockerfile
build-contexts: |
bin=tmp/bin
rust:1.99.1-trixie=docker-image://ghcr.io/docspring/visualci/mirror/rust:1.99.1-trixie@sha256:3ddd9771c00ed2c214d75ba497ad28691ebeaf2279476068dd191cf39b4be033
node:24-trixie-slim=docker-image://ghcr.io/docspring/visualci/mirror/node:24-trixie-slim@sha256:efb444a6c8b45a1ebdd70974912147dc2be917714174f52334e236aa23c0e3a6
debian:trixie-slim=docker-image://ghcr.io/docspring/visualci/mirror/debian:trixie-slim@sha256:ab3b3c8c5159eebfca4376430132d53c4d425f869c765ecbe47177a030da575d
push: ${{ env.PUSH == 'true' }}
build-args: RENDERER_VERSION=${{ steps.version.outputs.renderer }}
tags: |
${{ steps.renderer_inputs.outputs.tag }}
ghcr.io/docspring/visualci-renderer:${{ github.sha }}
cache-from: ${{ env.S3_CACHE }},name=visualci-renderer
cache-to: ${{ env.PUSH == 'true' && format('{0},name=visualci-renderer,mode=max,ignore-error=true', env.S3_CACHE) || '' }}
- id: renderer
run: echo "digest=${{ steps.renderer_inputs.outputs.existing || steps.renderer_build.outputs.digest }}" >>"$GITHUB_OUTPUT"
deploy:
needs: [images, site]
if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request' && vars.DEPLOY_ENABLED == 'true'
runs-on: ${{ fromJSON(vars.CI_RUNNER || '"ubuntu-latest"') }}
timeout-minutes: 5
env:
APP_DIGEST: ${{ needs.images.outputs.app }}
RENDERER_DIGEST: ${{ needs.images.outputs.renderer }}
KUSTOMIZATION: infra/k3s/resources/visualci/kustomization.yaml
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
# A write deploy key on talira-ai/infra, used for this push only; it also signs the commit.
- name: talira-ai/infra
env:
INFRA_DEPLOY_KEY: ${{ secrets.INFRA_DEPLOY_KEY }}
run: |
install -m 700 -d ~/.ssh
printf '%s\n' "$INFRA_DEPLOY_KEY" >~/.ssh/infra
chmod 600 ~/.ssh/infra
echo 'github.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOMqqnkVzrm0SdG6UOoqKLsabgH5C9okWi0dh2l9GKJl' >~/.ssh/known_hosts
export GIT_SSH_COMMAND="ssh -i $HOME/.ssh/infra -o IdentitiesOnly=yes"
git clone -q --depth 50 git@github.com:talira-ai/infra.git infra
git -C infra config user.name 'VisualCI CI'
git -C infra config user.email 'ci@visualci.com'
git -C infra config gpg.format ssh
git -C infra config user.signingkey "$HOME/.ssh/infra"
git -C infra config commit.gpgsign true
# Production only moves forward: the commit production runs must be an ancestor of this one.
- name: Commit the digests
run: |
export GIT_SSH_COMMAND="ssh -i $HOME/.ssh/infra -o IdentitiesOnly=yes"
deployed=$(sed -n 's/^# visualci commit: \([0-9a-f]\{40\}\)$/\1/p' "$KUSTOMIZATION")
# The placeholder commit (all zeros) means nothing is deployed yet.
if [ -n "$deployed" ] && [ "$deployed" != 0000000000000000000000000000000000000000 ] &&
! git merge-base --is-ancestor "$deployed" "$GITHUB_SHA"; then
echo "::notice::Not deployed: production runs $deployed, which this commit doesn't come after"; exit 0
fi
for _ in 1 2 3 4 5; do
python3 scripts/ci/set_digests.py "$KUSTOMIZATION" "$GITHUB_SHA" "$APP_DIGEST" "$RENDERER_DIGEST"
git -C infra commit -qam "visualci: deploy ${GITHUB_SHA::12}" -m "$(git log -1 --format=%s "$GITHUB_SHA" | cut -c1-120)"
if git -C infra push -q origin HEAD:main; then exit 0; fi
git -C infra fetch -q origin main && git -C infra reset -q --hard origin/main
done
exit 1