Repository navigation
Rollouts: no prepared-statement cache, so adding a column never fails the previous release's SELECT * (#178's rollout 500) #1122
Workflow file for this run
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 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: | |
| permissions: | |
| contents: 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: postgres:17 | |
| 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 | |
| # S3 storage for the blob tests: RustFS, as the visual-capture job uses. | |
| - run: | | |
| docker run -d --name s3 -p 59000:9000 \ | |
| -e RUSTFS_ACCESS_KEY=visualci -e RUSTFS_SECRET_KEY=visualci-dev-secret rustfs/rustfs:1.0.6 | |
| 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 | |
| - 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: postgres:17 | |
| 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 | |
| # 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: | | |
| docker run -d --name s3 -p 59000:9000 \ | |
| -e RUSTFS_ACCESS_KEY=visualci -e RUSTFS_SECRET_KEY=visualci-dev-secret rustfs/rustfs:1.0.6 | |
| 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) | |
| - 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: postgres:17 | |
| 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 | |
| - run: | | |
| docker run -d --name s3 -p 59000:9000 \ | |
| -e RUSTFS_ACCESS_KEY=visualci -e RUSTFS_SECRET_KEY=visualci-dev-secret rustfs/rustfs:1.0.6 | |
| 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/journeys/run.sh | |
| env: | |
| 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 | |
| - uses: pnpm/action-setup@v4 | |
| with: | |
| package_json_file: frontend/package.json | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: "24" | |
| # 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' || '' }} | |
| container: rust:1.99.1-trixie | |
| 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/* | |
| - uses: docker/setup-buildx-action@v3 | |
| - if: env.PUSH == 'true' | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| # 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 | |
| build-contexts: bin=tmp/bin | |
| 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 'container: 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 | |
| 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 |