Repository navigation
Unused code: cargo-shear and Knip in CI (sc-9611) #1414
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 | |
| with: | |
| persist-credentials: false | |
| # 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 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 | |
| # Unused dependencies, in each of the three Rust workspaces (cargo-shear; ignores in each Cargo.toml's | |
| # [package.metadata.cargo-shear], with the reason beside them). | |
| - uses: jdx/mise-action@924e7c586e33d7d4bae9c14e26c5d22e2beb6e78 # v5.3.0 | |
| with: | |
| install_args: github:Boshen/cargo-shear | |
| - run: | | |
| cargo shear | |
| (cd clients/gallery/rust && cargo shear) | |
| (cd clients/gallery/rust/examples/loco && cargo shear) | |
| # 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. clippy covers it in the lint job (formatting is the pre-commit hook's, lefthook.yml). | |
| 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@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 | |
| with: | |
| persist-credentials: false | |
| # 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@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0 | |
| 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@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3 | |
| 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@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 | |
| 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@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 | |
| with: | |
| persist-credentials: false | |
| fetch-depth: 0 | |
| - run: scripts/ci/cli_version.sh | |
| # The migrations a change adds, against its base (a required check: main's ruleset makes a pull request up to date | |
| # with main first, so two branches' migrations are always checked against each other). | |
| migrations: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 5 | |
| steps: | |
| - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 | |
| with: | |
| persist-credentials: false | |
| fetch-depth: 0 | |
| # 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 | |
| - uses: jdx/mise-action@924e7c586e33d7d4bae9c14e26c5d22e2beb6e78 # v5.3.0 | |
| with: | |
| install_args: github:sbdchd/squawk | |
| # Migrations run in file-name order and are recorded by name, so one already on main is never renamed or edited, | |
| # and a new one sorts after all of main's (two branches that each add one: the second to merge takes a later | |
| # timestamp). With no base it can reach (a new branch, a force-push), only the names are checked. | |
| - env: | |
| BASE: ${{ github.event.pull_request.base.sha || github.event.before }} | |
| run: | | |
| if [ -z "$BASE" ] || [ "$BASE" = 0000000000000000000000000000000000000000 ] || ! git cat-file -e "$BASE^{commit}" 2>/dev/null; then | |
| echo "::warning::No earlier commit to compare the migrations with (${BASE:-none}): only their names are checked." | |
| scripts/ci/check_migrations.sh "" | |
| else | |
| scripts/ci/check_migrations.sh "$BASE" | |
| python3 scripts/ci/migration_safety.py "$BASE" | |
| # Postgres migration lint on the new ones' SQL (.squawk.toml): locks that block traffic, unsafe changes. | |
| scripts/ci/squawk_migrations.sh "$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@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 | |
| with: | |
| persist-credentials: false | |
| - 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 workflows and actions: actionlint (with shellcheck on their scripts) and zizmor (.github/zizmor.yml, with its | |
| # online audits on pull requests: impostor commits, actions with known vulnerabilities); the Dockerfiles (hadolint); | |
| # spelling (typos), JS/TS (oxlint) and shell scripts (ShellCheck); and secrets in the commits this push or pull | |
| # request adds (Betterleaks, .betterleaks.toml). mise.toml pins the tools, and the pre-commit hook runs the same ones. | |
| security: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| steps: | |
| - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 | |
| with: | |
| persist-credentials: false | |
| fetch-depth: 0 | |
| - uses: jdx/mise-action@924e7c586e33d7d4bae9c14e26c5d22e2beb6e78 # v5.3.0 | |
| with: | |
| install_args: actionlint shellcheck zizmor betterleaks hadolint typos oxlint | |
| - run: actionlint | |
| # Spelling (_typos.toml), JS/TS lint (.oxlintrc.json) and every shell script (scripts/ci/shellcheck.sh). | |
| - run: typos | |
| - run: oxlint --deny-warnings . | |
| - run: scripts/ci/shellcheck.sh | |
| # Source files' length (caps for the long ones in scripts/ci/file_lengths.txt), and every lint suppression | |
| # listed with its reason (scripts/ci/suppressions.txt). | |
| - run: scripts/ci/check_file_length.py | |
| - run: scripts/ci/check_suppressions.py | |
| # The renderer's two warnings (a `cd` and a pipe in the PDFBox download step) wait for its next rebuild: any edit | |
| # to renderer.Dockerfile rebuilds the renderer image (its inputs hash), so it isn't touched for lint alone. | |
| - run: hadolint docker/app.Dockerfile && hadolint --ignore DL3003 --ignore DL4006 docker/renderer.Dockerfile | |
| # The online audits only on pull requests: a new advisory against a pinned action shouldn't turn main red, which | |
| # holds back the CLI release (release.yml waits for a green CI on main) with no code change. | |
| - run: if [ "$EVENT" = pull_request ]; then zizmor --no-progress .; else zizmor --no-progress --offline .; fi | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| EVENT: ${{ github.event_name }} | |
| # A push's or pull request's own commits; with no earlier commit to compare with (a new branch, a manual run), the | |
| # files as they are. Old history isn't scanned: what's there is made-up test values in code since deleted. | |
| - env: | |
| BASE: ${{ github.event.pull_request.base.sha || github.event.before }} | |
| run: | | |
| if [ -n "$BASE" ] && [ "$BASE" != 0000000000000000000000000000000000000000 ] && git cat-file -e "$BASE^{commit}" 2>/dev/null; then | |
| betterleaks git --no-banner --config .betterleaks.toml --log-opts="$BASE..HEAD" . | |
| else | |
| betterleaks dir --no-banner --config .betterleaks.toml . | |
| fi | |
| # 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@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 | |
| with: | |
| persist-credentials: false | |
| # 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@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 | |
| with: | |
| persist-credentials: false | |
| # 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@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0 | |
| 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@b906affcce14559ad1aafd4ab0e942779e9f58b1 # v4.3.0 | |
| with: | |
| package_json_file: frontend/package.json | |
| - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 | |
| with: | |
| node-version: "24" | |
| # plugin/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@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 | |
| with: | |
| name: visual-capture | |
| path: tmp/visual-capture.tgz | |
| if-no-files-found: error | |
| retention-days: 7 | |
| - if: failure() | |
| uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 | |
| 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@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 | |
| with: | |
| persist-credentials: false | |
| # The CLI sends parent commits, so the build finds its baseline. | |
| fetch-depth: 101 | |
| - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0 | |
| with: | |
| name: visual-capture | |
| path: tmp | |
| - run: tar xzf tmp/visual-capture.tgz | |
| - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0 | |
| 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@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 | |
| with: | |
| persist-credentials: false | |
| 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@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0 | |
| 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@b906affcce14559ad1aafd4ab0e942779e9f58b1 # v4.3.0 | |
| with: | |
| package_json_file: frontend/package.json | |
| - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 | |
| 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@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 | |
| 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: 25 | |
| steps: | |
| - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 | |
| with: | |
| persist-credentials: false | |
| # 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@7eaac3fe3108dfb746bef3a3c1a21344d57923c7 # v1.348.0 | |
| 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@b906affcce14559ad1aafd4ab0e942779e9f58b1 # v4.3.0 | |
| with: | |
| package_json_file: frontend/package.json | |
| - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 | |
| 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 | |
| # Every package carries the licence's text. | |
| - run: for p in js astro; do (cd "$p" && npm pack --dry-run 2>&1 | grep -E ' LICENSE$' >/dev/null) || { echo "$p's package has no LICENSE"; exit 1; }; done | |
| 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 gem's example apps, booted and requested: examples/rails on Propshaft and on Sprockets, and examples/rack. | |
| - run: | | |
| for gemfile in Gemfile Gemfile.sprockets; do | |
| BUNDLE_FROZEN=true BUNDLE_GEMFILE=$gemfile bundle install && BUNDLE_GEMFILE=$gemfile bundle exec ruby test/app_test.rb | |
| done | |
| working-directory: clients/gallery/ruby/examples/rails | |
| - run: BUNDLE_FROZEN=true bundle install && bundle exec ruby test/app_test.rb | |
| working-directory: clients/gallery/ruby/examples/rack | |
| # The gallery's Python renderer: the contract's golden fixtures, on the oldest Python it supports and the newest. | |
| - uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0 | |
| 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 visualci_gallery/static/visualci_gallery/visualci_gallery.js >/dev/null && unzip -l dist/*.whl | grep -E 'dist-info/.*LICENSE$' >/dev/null | |
| working-directory: clients/gallery/python | |
| # The Python guide's example apps (Django, Flask, a Jinja build script), with the frameworks installed. | |
| - run: python3.14 -m venv "$RUNNER_TEMP/gallery-examples" && "$RUNNER_TEMP/gallery-examples/bin/pip" install --quiet -r examples/requirements.txt && "$RUNNER_TEMP/gallery-examples/bin/python" -W error -m unittest discover -s examples/tests -v | |
| working-directory: clients/gallery/python | |
| env: | |
| PYTHONPATH: src | |
| # 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 gallery's Rust renderer, after the compile cache is set up (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 | |
| - run: cargo package --list --allow-dirty | grep -x LICENSE >/dev/null | |
| working-directory: clients/gallery/rust | |
| # The Rust guide's Loco app (its own project, so loco-rs stays out of the crate's build). | |
| - run: cargo test --locked && cargo clippy --locked --all-targets -- -D warnings | |
| working-directory: clients/gallery/rust/examples/loco | |
| # 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) | |
| # Unused files and dependencies in the frontend (knip.jsonc; unused exports are reported, not failed). Pinned | |
| # here rather than in package.json, so its dependency tree stays out of the frontend's lockfile. It loads | |
| # vite.config.ts, which reads the CLI release too. | |
| - run: pnpm dlx knip@6.49.0 --no-progress | |
| working-directory: frontend | |
| env: | |
| GITHUB_TOKEN: ${{ github.token }} | |
| # 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" | |
| # Every page, file and #anchor the site links to is in the build, its absolute https://visualci.com/ links | |
| # included (lychee.toml; offline, so an outside site never fails a build: the Audit workflow checks those nightly). | |
| - uses: jdx/mise-action@924e7c586e33d7d4bae9c14e26c5d22e2beb6e78 # v5.3.0 | |
| with: | |
| install_args: lychee | |
| # The pages, their Markdown copies and llms.txt. The site's own absolute links point at the build; a Markdown copy's | |
| # #anchor (an HTML page's id) is dropped, since a Markdown heading has none (one remap applies per link: first wins). | |
| - run: | | |
| site=$PWD/frontend/dist-site | |
| lychee --offline --root-dir "$site" --format compact \ | |
| --remap "^https?://(www\.)?visualci\.com/([^#]+\.md)#.*\$ file://$site/\$2" \ | |
| --remap "^https?://(www\.)?visualci\.com/?(.*)\$ file://$site/\$2" \ | |
| "$site/**/*.html" "$site/**/*.md" "$site/llms.txt" "$site/llms-full.txt" | |
| - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 | |
| 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@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 | |
| with: | |
| persist-credentials: false | |
| - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0 | |
| with: | |
| name: dist-site | |
| path: frontend/dist-site | |
| - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 | |
| 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@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 | |
| with: | |
| persist-credentials: false | |
| - 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@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 | |
| 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@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 | |
| with: | |
| persist-credentials: false | |
| - id: version | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| echo "renderer=$(cat docker/renderer.version)" >>"$GITHUB_OUTPUT" | |
| echo "date=$(date -u +%F)" >>"$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 | |
| cli=$(gh api repos/DocSpring/visualci/releases/latest --jq .tag_name) | |
| echo "cli=$cli" >>"$GITHUB_OUTPUT" | |
| # Its checksum, which the snippets check the download against | |
| sha=$(gh release download "$cli" -R DocSpring/visualci -p visualci-x86_64-unknown-linux-musl.tar.gz.sha256 -O - | cut -d' ' -f1) | |
| [[ "$sha" =~ ^[0-9a-f]{64}$ ]] || { echo "::error::no SHA-256 for CLI $cli: '$sha'"; exit 1; } | |
| echo "cli_sha256=$sha" >>"$GITHUB_OUTPUT" | |
| - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0 | |
| 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@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12.0 | |
| 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@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2 | |
| 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' }} | |
| # Pull requests load it into the runner's Docker for the Trivy scan below; main pushes it. | |
| load: ${{ env.PUSH != 'true' }} | |
| build-args: | | |
| SECURITY_UPDATES_DATE=${{ steps.version.outputs.date }} | |
| BUILD_SHA=${{ github.sha }} | |
| RENDERER_VERSION=${{ steps.version.outputs.renderer }} | |
| VISUALCI_ANALYTICS=1 | |
| VISUALCI_CLI_VERSION=${{ steps.version.outputs.cli }} | |
| VISUALCI_CLI_SHA256=${{ steps.version.outputs.cli_sha256 }} | |
| 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@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2 | |
| 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 | |
| env: | |
| DIGEST: ${{ steps.renderer_inputs.outputs.existing || steps.renderer_build.outputs.digest }} | |
| run: echo "digest=$DIGEST" >>"$GITHUB_OUTPUT" | |
| # Trivy on the images: fixable HIGH and CRITICAL vulnerabilities (ignores with an expiry in .trivyignore.yaml), | |
| # and forbidden licences (AGPL and the like). It gates pull requests. On main it only reports, so a CVE published | |
| # today never holds back a deploy; the Audit workflow scans the live app image daily and fails there. | |
| - uses: jdx/mise-action@924e7c586e33d7d4bae9c14e26c5d22e2beb6e78 # v5.3.0 | |
| with: | |
| install_args: trivy | |
| cache: false | |
| - name: Trivy (app image) | |
| continue-on-error: ${{ env.PUSH == 'true' }} | |
| env: | |
| IMAGE: ghcr.io/docspring/visualci-app:${{ github.sha }} | |
| run: | | |
| trivy image --scanners vuln --ignore-unfixed --severity HIGH,CRITICAL --exit-code 1 --ignorefile .trivyignore.yaml "$IMAGE" | |
| trivy image --scanners license --severity CRITICAL --exit-code 1 "$IMAGE" | |
| # The renderer only reports for now: fixing what it finds means rebuilding it (fresh Debian packages, which can | |
| # move pixels, and a renderer.version bump), done on purpose in its own change (sc-9674). | |
| - name: Trivy (renderer image, report only) | |
| continue-on-error: true | |
| env: | |
| IMAGE: ${{ steps.renderer_inputs.outputs.tag }} | |
| run: trivy image --scanners vuln --ignore-unfixed --severity HIGH,CRITICAL --exit-code 1 --ignorefile .trivyignore.yaml "$IMAGE" | |
| 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@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 | |
| with: | |
| persist-credentials: false | |
| 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 |