diff --git a/.betterleaks.toml b/.betterleaks.toml new file mode 100644 index 000000000..99bf7e012 --- /dev/null +++ b/.betterleaks.toml @@ -0,0 +1,26 @@ +# Betterleaks (secret scanning), run by lefthook on staged changes and by CI's workflows job on a push's or pull +# request's commits, with `--config .betterleaks.toml`. Allow only made-up values that are safe to publish: say what +# each one is. +[extend] +useDefault = true + +[[allowlists]] +description = "Local and example database URLs: the test databases' throwaway users (visualci/visualci, loco/loco on 127.0.0.1) and the docs' self-hosting example (visualci:secret@db)" +regexTarget = "match" +regexes = [ + '''postgres(ql)?://(visualci|loco):(visualci|loco|secret)@(127\.0\.0\.1|localhost|db)[:/]''', +] + +[[allowlists]] +description = "Made-up credentials in URLs that the CLI's tests and doc comments use to check they're redacted" +regexTarget = "match" +regexes = [ + '''https://(user:token@host|x-token:secret@github\.com|x-access-token:abc@github\.com)''', +] + +[[allowlists]] +description = "CI's Postgres service users, the same throwaway test users" +regexTarget = "match" +regexes = [ + '''^PASSWORD: (visualci|loco)$''', +] diff --git a/.github/actions/playwright/action.yml b/.github/actions/playwright/action.yml index adffa5230..530c8e48a 100644 --- a/.github/actions/playwright/action.yml +++ b/.github/actions/playwright/action.yml @@ -22,7 +22,7 @@ runs: . /etc/os-release echo "key=playwright-debs-$ID-$VERSION_ID-$(dpkg --print-architecture)-" >>"$GITHUB_OUTPUT" - id: restore - uses: actions/cache/restore@v4 + uses: actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 with: path: ~/.cache/playwright-debs key: ${{ steps.prefix.outputs.key }}none @@ -50,6 +50,8 @@ runs: # Only the versions installed now are kept, so the cache doesn't grow with every package update. - id: debs shell: bash + env: + PREFIX: ${{ steps.prefix.outputs.key }} run: | dir=$HOME/.cache/playwright-debs for f in "$dir"/*.deb; do @@ -61,10 +63,10 @@ runs: n=$(find "$dir" -name '*.deb' | wc -l) echo "$n .deb files to keep" hash=$(find "$dir" -name '*.deb' -printf '%f\n' | sort | sha256sum | cut -c1-16) - echo "key=${{ steps.prefix.outputs.key }}$hash" >>"$GITHUB_OUTPUT" + echo "key=$PREFIX$hash" >>"$GITHUB_OUTPUT" echo "count=$n" >>"$GITHUB_OUTPUT" - if: inputs.save == 'true' && steps.debs.outputs.count != '0' && steps.debs.outputs.key != steps.restore.outputs.cache-matched-key - uses: actions/cache/save@v4 + uses: actions/cache/save@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 with: path: ~/.cache/playwright-debs key: ${{ steps.debs.outputs.key }} diff --git a/.github/workflows/audit.yml b/.github/workflows/audit.yml new file mode 100644 index 000000000..f6876b5ba --- /dev/null +++ b/.github/workflows/audit.yml @@ -0,0 +1,83 @@ +# Known vulnerabilities and licences in the dependencies: cargo-deny for the three Rust workspaces (deny.toml beside +# each manifest: RustSec advisories, licences, sources), Trivy for every lockfile (Cargo, pnpm, Bundler, pip; dev +# dependencies included, fixable findings only, ignores in .trivyignore.yaml with an expiry). In deny.toml, an ignore or +# an allowed licence that no longer matches anything fails too; a Trivy ignore fails again when it expires. +# +# Its own workflow, not CI's: a new advisory can turn it red without any change here, and CI's result on main decides +# the CLI release (release.yml). Pull requests run it (a required check), and so does a daily run on main, whose +# failure reaches the coordinator like any other. +name: Audit + +on: + pull_request: + push: + branches: [main] + schedule: + - cron: "41 4 * * *" + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: audit-${{ github.ref }} + cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} + +jobs: + audit: + runs-on: ubuntu-latest + timeout-minutes: 15 + steps: + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 + with: + persist-credentials: false + - uses: jdx/mise-action@924e7c586e33d7d4bae9c14e26c5d22e2beb6e78 # v5.3.0 + with: + install_args: cargo-deny trivy + - name: cargo-deny + run: | + status=0 + for manifest in Cargo.toml clients/gallery/rust/Cargo.toml clients/gallery/rust/examples/loco/Cargo.toml; do + echo "::group::$manifest" + cargo deny --manifest-path "$manifest" check -D advisory-not-detected -D license-not-encountered || status=1 + echo "::endgroup::" + done + exit $status + - name: Trivy (lockfiles) + run: >- + trivy fs --scanners vuln --include-dev-deps --ignore-unfixed --exit-code 1 + --ignorefile .trivyignore.yaml --skip-dirs target --skip-dirs '**/node_modules' . + # Trivy only knows lockfiles by their usual names: the Rails example's second bundle (the Sprockets one ci.yml + # tests) goes in under Gemfile.lock. + - name: Trivy (Rails example, Sprockets bundle) + run: | + dir=$RUNNER_TEMP/sprockets && mkdir -p "$dir" + cp clients/gallery/ruby/examples/rails/Gemfile.sprockets.lock "$dir/Gemfile.lock" + trivy fs --scanners vuln --ignore-unfixed --exit-code 1 --ignorefile .trivyignore.yaml "$dir" + + # The app image production runs (the commit https://api.visualci.com/status reports), daily and by hand: CI's scan of + # an image only gates pull requests, so a CVE published after a deploy is caught here. + live-image: + if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + runs-on: ubuntu-latest + timeout-minutes: 15 + permissions: + contents: read + packages: read + steps: + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 + with: + persist-credentials: false + - uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - uses: jdx/mise-action@924e7c586e33d7d4bae9c14e26c5d22e2beb6e78 # v5.3.0 + with: + install_args: trivy + - run: | + commit=$(curl -fsS --retry 3 --max-time 10 https://api.visualci.com/status | jq -r '.commit // empty') + [[ "$commit" =~ ^[0-9a-f]{40}$ ]] || { echo "::error::no commit from https://api.visualci.com/status"; exit 1; } + trivy image --scanners vuln --ignore-unfixed --severity HIGH,CRITICAL --exit-code 1 --ignorefile .trivyignore.yaml \ + "ghcr.io/docspring/visualci-app:$commit" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fb63f4952..35c3f1e45 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,7 +28,9 @@ jobs: environment: ${{ github.ref == 'refs/heads/main' && 'kache-write' || '' }} timeout-minutes: 30 steps: - - uses: actions/checkout@v4 + - 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. @@ -53,13 +55,12 @@ jobs: 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. + # 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' || '' }} @@ -77,10 +78,12 @@ jobs: ports: ["55433:5432"] options: --health-cmd pg_isready --health-interval 5s --health-timeout 5s --health-retries 10 steps: - - uses: actions/checkout@v4 + - 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@v3 + - uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0 with: registry: ghcr.io username: ${{ github.actor }} @@ -94,7 +97,7 @@ jobs: 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 + - 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 @@ -120,7 +123,7 @@ jobs: # 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 + - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 with: name: email-snapshots path: tmp/email-snapshots @@ -133,8 +136,9 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 5 steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 with: + persist-credentials: false 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 @@ -154,11 +158,53 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 5 steps: - - uses: actions/checkout@v4 + - 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 + # 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: @@ -166,7 +212,9 @@ jobs: environment: ${{ github.ref == 'refs/heads/main' && 'kache-write' || '' }} timeout-minutes: 40 steps: - - uses: actions/checkout@v4 + - 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. @@ -205,13 +253,14 @@ jobs: ports: ["55433:5432"] options: --health-cmd pg_isready --health-interval 5s --health-timeout 5s --health-retries 10 steps: - - uses: actions/checkout@v4 + - 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@v3 + - uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0 with: registry: ghcr.io username: ${{ github.actor }} @@ -243,10 +292,10 @@ jobs: # 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 + - uses: pnpm/action-setup@b906affcce14559ad1aafd4ab0e942779e9f58b1 # v4.3.0 with: package_json_file: frontend/package.json - - uses: actions/setup-node@v4 + - 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. @@ -269,14 +318,14 @@ jobs: 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 + - 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@v4 + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 with: name: visual path: tmp/visual @@ -299,16 +348,17 @@ jobs: echo "::error::Nothing to send: app was $APP and visual-capture was $CAPTURE." exit 1 fi - - uses: actions/checkout@v4 + - 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@v4 + - 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@v4 + - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0 with: name: email-snapshots path: tmp/email-snapshots @@ -353,13 +403,14 @@ jobs: VISUALCI_API_URL: https://api.visualci.test VISUALCI_MCP_URL: https://mcp.visualci.test steps: - - uses: actions/checkout@v4 + - 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@v3 + - uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0 with: registry: ghcr.io username: ${{ github.actor }} @@ -385,10 +436,10 @@ jobs: 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 + - uses: pnpm/action-setup@b906affcce14559ad1aafd4ab0e942779e9f58b1 # v4.3.0 with: package_json_file: frontend/package.json - - uses: actions/setup-node@v4 + - 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) @@ -415,7 +466,7 @@ jobs: upload: | tmp/journeys/screenshots --prefix journeys/ --platform chrome-linux - if: failure() - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 with: name: journeys path: tmp/journeys @@ -426,7 +477,9 @@ jobs: environment: ${{ github.ref == 'refs/heads/main' && 'kache-write' || '' }} timeout-minutes: 25 steps: - - uses: actions/checkout@v4 + - 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. @@ -465,7 +518,7 @@ jobs: 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 + - uses: ruby/setup-ruby@7eaac3fe3108dfb746bef3a3c1a21344d57923c7 # v1.348.0 with: ruby-version: "3.4" - run: ruby -Ilib spec/visualci_spec.rb @@ -473,10 +526,10 @@ jobs: # 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 + - uses: pnpm/action-setup@b906affcce14559ad1aafd4ab0e942779e9f58b1 # v4.3.0 with: package_json_file: frontend/package.json - - uses: actions/setup-node@v4 + - 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 @@ -485,7 +538,7 @@ jobs: - 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 -qE ' LICENSE$') || { echo "$p's package has no LICENSE"; exit 1; }; done + - 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 @@ -499,7 +552,7 @@ jobs: - 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@v5 + - uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0 with: python-version: | 3.10 @@ -509,7 +562,7 @@ jobs: 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 && unzip -l dist/*.whl | grep -qE 'dist-info/.*LICENSE$' + - 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 @@ -537,7 +590,7 @@ jobs: # 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 -qx LICENSE + - 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 @@ -554,7 +607,7 @@ jobs: env: GITHUB_TOKEN: ${{ github.token }} VISUALCI_REQUIRE_WASM: "1" - - uses: actions/upload-artifact@v4 + - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 with: name: dist-site path: frontend/dist-site @@ -572,12 +625,14 @@ jobs: runs-on: ${{ fromJSON(vars.CI_RUNNER || '"ubuntu-latest"') }} timeout-minutes: 10 steps: - - uses: actions/checkout@v4 - - uses: actions/download-artifact@v4 + - 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@v4 + - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 with: node-version: "24" - name: Deploy to Cloudflare @@ -608,7 +663,9 @@ jobs: password: ${{ secrets.GITHUB_TOKEN }} timeout-minutes: 30 steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 + with: + persist-credentials: false - uses: kunobi-ninja/kache-action@061011817fd04b0e460f79d6bb3c115b1fc8f029 # v1 with: version: "2.4.0" @@ -628,7 +685,7 @@ jobs: # 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 + - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 with: name: release-bins path: tmp/bin @@ -652,12 +709,15 @@ jobs: app: ${{ steps.app.outputs.digest }} renderer: ${{ steps.renderer.outputs.digest }} steps: - - uses: actions/checkout@v4 + - 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) @@ -666,23 +726,23 @@ jobs: 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@v4 + - 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@v3 + - uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - uses: docker/setup-buildx-action@v3 + - 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@v6 + uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2 with: context: . file: docker/app.Dockerfile @@ -693,7 +753,10 @@ jobs: 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 @@ -726,7 +789,7 @@ jobs: fi - id: renderer_build if: steps.renderer_inputs.outputs.existing == '' - uses: docker/build-push-action@v6 + uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2 with: context: . file: docker/renderer.Dockerfile @@ -743,7 +806,30 @@ jobs: 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" + 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] @@ -755,8 +841,9 @@ jobs: RENDERER_DIGEST: ${{ needs.images.outputs.renderer }} KUSTOMIZATION: infra/k3s/resources/visualci/kustomization.yaml steps: - - uses: actions/checkout@v4 + - 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 diff --git a/.github/workflows/mirror.yml b/.github/workflows/mirror.yml index 720deb8c4..281215617 100644 --- a/.github/workflows/mirror.yml +++ b/.github/workflows/mirror.yml @@ -25,7 +25,7 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 30 steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 with: persist-credentials: false - name: Install crane (go-containerregistry), checksum verified diff --git a/.github/workflows/release-gallery-crate.yml b/.github/workflows/release-gallery-crate.yml index d6f754d8f..1371916bb 100644 --- a/.github/workflows/release-gallery-crate.yml +++ b/.github/workflows/release-gallery-crate.yml @@ -24,7 +24,9 @@ jobs: run: working-directory: clients/gallery/rust steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 + with: + persist-credentials: false - name: The tag matches the crate's version if: startsWith(github.ref, 'refs/tags/gallery-rust-v') run: | @@ -33,7 +35,7 @@ jobs: - run: cargo test --locked --all-features - id: oidc if: env.CRATES_IO_TOKEN == '' - uses: rust-lang/crates-io-auth-action@v1 + uses: rust-lang/crates-io-auth-action@3268eb413133e2960fa4ae0e963ca76380c54cd9 # v1.0.6 - run: cargo publish --locked env: CARGO_REGISTRY_TOKEN: ${{ env.CRATES_IO_TOKEN || steps.oidc.outputs.token }} diff --git a/.github/workflows/release-gallery-gem.yml b/.github/workflows/release-gallery-gem.yml index c02de6890..49b3a1af8 100644 --- a/.github/workflows/release-gallery-gem.yml +++ b/.github/workflows/release-gallery-gem.yml @@ -17,16 +17,19 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 10 steps: - - uses: actions/checkout@v4 - - uses: pnpm/action-setup@v4 + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 with: - package_json_file: clients/gallery/package.json - - uses: actions/setup-node@v4 + persist-credentials: false + - uses: pnpm/action-setup@b906affcce14559ad1aafd4ab0e942779e9f58b1 # v4.3.0 with: + package_json_file: clients/gallery/package.json + # setup-node v4 caches only when `cache:` is set, and this publishing job sets none. + - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 + with: # zizmor: ignore[cache-poisoning] node-version: "24" - run: pnpm install --frozen-lockfile && pnpm --filter visualci-gallery build working-directory: clients/gallery - - uses: ruby/setup-ruby@v1 + - uses: ruby/setup-ruby@7eaac3fe3108dfb746bef3a3c1a21344d57923c7 # v1.348.0 with: ruby-version: "3.4" - name: The tag matches the gem's version @@ -37,7 +40,7 @@ jobs: test "gallery-ruby-v$version" = "$GITHUB_REF_NAME" || { echo "tag $GITHUB_REF_NAME, gem $version"; exit 1; } - run: ruby -Ilib test/gallery_test.rb working-directory: clients/gallery/ruby - - uses: rubygems/configure-rubygems-credentials@v2.2.0 + - uses: rubygems/configure-rubygems-credentials@c6ca7f4bac0e29c9bde8eeae0a0a986b27efa05f # v2.2.0 with: # The RubyGems.org account that owns the gem (needed for the first push through a pending trusted publisher). owner: "48431" diff --git a/.github/workflows/release-gallery-npm.yml b/.github/workflows/release-gallery-npm.yml index fb7358f85..553925821 100644 --- a/.github/workflows/release-gallery-npm.yml +++ b/.github/workflows/release-gallery-npm.yml @@ -25,12 +25,15 @@ jobs: run: working-directory: clients/gallery steps: - - uses: actions/checkout@v4 - - uses: pnpm/action-setup@v4 + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 with: - package_json_file: clients/gallery/package.json - - uses: actions/setup-node@v4 + persist-credentials: false + - uses: pnpm/action-setup@b906affcce14559ad1aafd4ab0e942779e9f58b1 # v4.3.0 with: + package_json_file: clients/gallery/package.json + # setup-node v4 caches only when `cache:` is set, and this publishing job sets none. + - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 + with: # zizmor: ignore[cache-poisoning] node-version: "24" registry-url: "https://registry.npmjs.org" - name: The tag matches both packages' versions diff --git a/.github/workflows/release-gallery-python.yml b/.github/workflows/release-gallery-python.yml index 4614fd4b2..838eb6445 100644 --- a/.github/workflows/release-gallery-python.yml +++ b/.github/workflows/release-gallery-python.yml @@ -18,16 +18,19 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 10 steps: - - uses: actions/checkout@v4 - - uses: pnpm/action-setup@v4 + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 with: - package_json_file: clients/gallery/package.json - - uses: actions/setup-node@v4 + persist-credentials: false + - uses: pnpm/action-setup@b906affcce14559ad1aafd4ab0e942779e9f58b1 # v4.3.0 with: + package_json_file: clients/gallery/package.json + # setup-node v4 caches only when `cache:` is set, and this publishing job sets none. + - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 + with: # zizmor: ignore[cache-poisoning] node-version: "24" - run: pnpm install --frozen-lockfile && pnpm --filter visualci-gallery build working-directory: clients/gallery - - uses: actions/setup-python@v5 + - uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0 with: python-version: "3.14" - name: The tag matches the package's version @@ -42,6 +45,6 @@ jobs: PYTHONPATH: src - run: bin/assets && python -m pip install --quiet build && python -m build working-directory: clients/gallery/python - - uses: pypa/gh-action-pypi-publish@release/v1 + - uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3 with: packages-dir: clients/gallery/python/dist diff --git a/.github/workflows/release-gem.yml b/.github/workflows/release-gem.yml index 40e2f6b5a..73cece239 100644 --- a/.github/workflows/release-gem.yml +++ b/.github/workflows/release-gem.yml @@ -20,8 +20,10 @@ jobs: run: working-directory: clients/ruby steps: - - uses: actions/checkout@v4 - - uses: ruby/setup-ruby@v1 + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 + with: + persist-credentials: false + - uses: ruby/setup-ruby@7eaac3fe3108dfb746bef3a3c1a21344d57923c7 # v1.348.0 with: ruby-version: "3.3" - name: The tag matches the gem's version @@ -29,7 +31,7 @@ jobs: run: | version=$(ruby -r ./lib/visualci/version -e 'print VisualCI::VERSION') test "ruby-v$version" = "$GITHUB_REF_NAME" || { echo "tag $GITHUB_REF_NAME, gem $version"; exit 1; } - - uses: rubygems/configure-rubygems-credentials@v2.2.0 + - uses: rubygems/configure-rubygems-credentials@c6ca7f4bac0e29c9bde8eeae0a0a986b27efa05f # v2.2.0 with: # The RubyGems.org account that owns the gem (needed for the first push through a pending trusted publisher). owner: "48431" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 35c80ff74..0fd169a70 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -8,7 +8,9 @@ # newest action, and through its default `version`, the newest CLI, without editing their workflows. name: Release CLI -on: +# workflow_run runs with main's workflow file and secrets: every job below runs only for a successful CI run of a push to +# main (or a tag push), never for a pull request's run. +on: # zizmor: ignore[dangerous-triggers] workflow_run: workflows: [CI] types: [completed] @@ -17,7 +19,7 @@ on: tags: ["v*.*.*"] permissions: - contents: write + contents: read jobs: version: @@ -28,21 +30,24 @@ jobs: sha: ${{ steps.v.outputs.sha }} release: ${{ steps.v.outputs.release }} steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 with: + persist-credentials: false ref: ${{ github.event.workflow_run.head_sha || github.sha }} - id: v env: GH_TOKEN: ${{ github.token }} + EVENT: ${{ github.event_name }} + REPO: ${{ github.repository }} run: | - if [ "${{ github.event_name }}" = push ]; then - tag="${{ github.ref_name }}" + if [ "$EVENT" = push ]; then + tag="$GITHUB_REF_NAME" else tag="v$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -1)" fi echo "tag=$tag" >> "$GITHUB_OUTPUT" echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT" - if gh release view "$tag" -R "${{ github.repository }}" >/dev/null 2>&1; then + if gh release view "$tag" -R "$REPO" >/dev/null 2>&1; then echo "$tag is already released" echo "release=false" >> "$GITHUB_OUTPUT" else @@ -63,26 +68,32 @@ jobs: runs-on: ${{ matrix.os }} timeout-minutes: 40 steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 with: + persist-credentials: false ref: ${{ needs.version.outputs.sha }} - name: musl tools if: contains(matrix.target, 'musl') run: sudo apt-get update && sudo apt-get install -y musl-tools - - run: rustup target add ${{ matrix.target }} - - uses: Swatinem/rust-cache@v2 - with: - key: ${{ matrix.target }} - - run: cargo build --release --locked -p visualci-cli --target ${{ matrix.target }} + - run: rustup target add "$TARGET" + env: + TARGET: ${{ matrix.target }} + # No build cache: the binaries users download are built from a clean target/, so a poisoned cache entry can't + # reach them. + - run: cargo build --release --locked -p visualci-cli --target "$TARGET" + env: + TARGET: ${{ matrix.target }} - name: Package + env: + TARGET: ${{ matrix.target }} run: | # No version in the name, so https://github.com/DocSpring/visualci/releases/latest/download/visualci-.tar.gz # always names the latest one (install.sh downloads that, or the release $VISUALCI_VERSION names). - dir=visualci-${{ matrix.target }} - mkdir "$dir" && cp target/${{ matrix.target }}/release/visualci "$dir/" && cp LICENSE* "$dir/" 2>/dev/null || true + dir=visualci-$TARGET + mkdir "$dir" && cp "target/$TARGET/release/visualci" "$dir/" && cp LICENSE* "$dir/" 2>/dev/null || true tar czf "$dir.tar.gz" "$dir" shasum -a 256 "$dir.tar.gz" > "$dir.tar.gz.sha256" - - uses: actions/upload-artifact@v4 + - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 with: name: ${{ matrix.target }} path: visualci-*.tar.gz* @@ -90,8 +101,11 @@ jobs: release: needs: [version, build] runs-on: ubuntu-latest + # The GitHub release and the floating major tag. + permissions: + contents: write steps: - - uses: actions/download-artifact@v4 + - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0 with: merge-multiple: true # A CLI may need what its commit adds to the server (the CLI has no fallbacks before launch), so it's published only @@ -119,9 +133,10 @@ jobs: exit 1 - env: GH_TOKEN: ${{ github.token }} - run: | - gh release create "${{ needs.version.outputs.tag }}" visualci-*.tar.gz* -R "${{ github.repository }}" \ - --target "${{ needs.version.outputs.sha }}" --generate-notes + TAG: ${{ needs.version.outputs.tag }} + SHA: ${{ needs.version.outputs.sha }} + REPO: ${{ github.repository }} + run: gh release create "$TAG" visualci-*.tar.gz* -R "$REPO" --target "$SHA" --generate-notes # The floating major tag (v0) follows the newest release. Created with the workflow's token, so it starts no # workflow of its own (and the tag trigger above only matches vX.Y.Z). - env: @@ -148,8 +163,9 @@ jobs: contents: read id-token: write steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 with: + persist-credentials: false ref: ${{ github.event.workflow_run.head_sha || github.sha }} - id: version run: | @@ -164,7 +180,7 @@ jobs: fi - id: auth if: steps.version.outputs.publish == 'true' - uses: rust-lang/crates-io-auth-action@v1 + uses: rust-lang/crates-io-auth-action@3268eb413133e2960fa4ae0e963ca76380c54cd9 # v1.0.6 - if: steps.version.outputs.publish == 'true' env: CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }} @@ -181,8 +197,9 @@ jobs: contents: read id-token: write steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 with: + persist-credentials: false ref: ${{ github.event.workflow_run.head_sha || github.sha }} - id: version run: | @@ -205,7 +222,7 @@ jobs: echo "crates=${publish# }" >> "$GITHUB_OUTPUT" - id: auth if: steps.version.outputs.crates != '' - uses: rust-lang/crates-io-auth-action@v1 + uses: rust-lang/crates-io-auth-action@3268eb413133e2960fa4ae0e963ca76380c54cd9 # v1.0.6 - if: steps.version.outputs.crates != '' env: CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }} diff --git a/.github/zizmor.yml b/.github/zizmor.yml new file mode 100644 index 000000000..8348835db --- /dev/null +++ b/.github/zizmor.yml @@ -0,0 +1,7 @@ +# zizmor (GitHub Actions security lint), run by lefthook and CI's workflows job. Ignores are inline +# (`# zizmor: ignore[audit]` with the reason beside it) except these. +rules: + # CI runs this repository's own GitHub Action and Playwright action from the checkout (`uses: ./...`) on purpose: it + # tests the action at this commit. + self-repository: + disable: true diff --git a/.hadolint.yaml b/.hadolint.yaml new file mode 100644 index 000000000..72f2947eb --- /dev/null +++ b/.hadolint.yaml @@ -0,0 +1,7 @@ +# hadolint (Dockerfile lint), run by CI's security job and the pre-commit hook. Fails on warnings and errors. +failure-threshold: warning +ignored: + # Pin apt package versions: Debian's archive drops a superseded version, so a pinned `pkg=1.2-3` stops installing at + # the next security update. The base image is pinned by digest instead (CI's build-contexts, .github/mirror.txt), + # and the app's image takes Debian's security updates on every build. + - DL3008 diff --git a/.oxlintrc.json b/.oxlintrc.json new file mode 100644 index 000000000..50304a526 --- /dev/null +++ b/.oxlintrc.json @@ -0,0 +1,18 @@ +// oxlint (JS/TS lint), run by the pre-commit hook and CI's security job with --deny-warnings. Turn a rule off for a +// file here only with the reason beside it. +{ + "$schema": "https://raw.githubusercontent.com/oxc-project/oxc/main/npm/oxlint/configuration_schema.json", + "ignorePatterns": ["**/node_modules/**", "**/dist/**", "**/dist-ssr/**", "**/dist-site/**", "target/**", "tmp/**"], + "overrides": [ + { + // The URL checks reject control characters (\x00-\x20, \x7f) on purpose. + "files": ["clients/gallery/js/src/model.ts"], + "rules": { "no-control-regex": "off" } + }, + { + // Sprockets needs its manifest to exist; this example's has only a comment. + "files": ["clients/gallery/ruby/examples/rails/app/assets/config/manifest.js"], + "rules": { "unicorn/no-empty-file": "off" } + } + ] +} diff --git a/.trivyignore.yaml b/.trivyignore.yaml new file mode 100644 index 000000000..9c70261df --- /dev/null +++ b/.trivyignore.yaml @@ -0,0 +1,10 @@ +# Trivy ignores, for CI's audit job (dependency lockfiles) and the image scan. Each entry says why it doesn't apply +# and expires within six months (expired_at), when it fails again and gets another look. +vulnerabilities: + - id: CVE-2026-25537 + paths: ["Cargo.lock"] + statement: >- + jsonwebtoken 9.3.1 skips nbf/exp validation for a claim of the wrong JSON type. app/ only signs JWTs (the GitHub + App's, forge/github_app.rs) and never decodes or validates one with this crate. Reviewed 5 Dec 2026 (sc-9611); + the upgrade to 10.3+ is its own story. + expired_at: 2027-06-05 diff --git a/AGENTS.md b/AGENTS.md index 19b5d2394..be1727ba9 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -14,6 +14,30 @@ design is in `docs/design.md`; read it before changing the architecture, and upd 3. Merge with `gh pr merge --squash --delete-branch` once every check is green. If GitHub refuses because VisualCI is pending, that's the review you skipped. Never bypass the ruleset. (1 Dec 2026, unreviewed builds let a CSS break from three merges reach production.) +- **Git hooks format your commits: install them once per clone** with `mise install && lefthook install` (the hooks + live in the clone's shared `.git/hooks`, so its worktrees all get them; `lefthook.yml` lists them). The pre-commit + hook runs the formatters on the staged files and stages what they change. CI has no format check (Nathan, 5 Dec + 2026, sc-9611), so a commit made without the hooks lands unformatted: never commit with `--no-verify`. +- **Workflows, secrets, spelling, JS/TS and shell scripts are checked** by CI's `security` job and the pre-commit + hook: actionlint, zizmor, Betterleaks, typos (`_typos.toml`), oxlint (`.oxlintrc.json`) and ShellCheck + (`scripts/ci/shellcheck.sh`); mise.toml pins them. Allow a word or turn a lint rule off for a file only in those + files, with the reason beside it. Pin every action by commit SHA with its version in a comment (`pinact run` does + it). Ignore a zizmor finding only inline (`# zizmor: ignore[audit]`) with the reason beside it; allow a made-up + value in `.betterleaks.toml` only with a description of what it is. A real secret that reached a commit is revoked, + not allowlisted. +- **Dependencies are audited** by the Audit workflow (on pull requests and daily on main): cargo-deny for the Rust + workspaces (a `deny.toml` beside each manifest: advisories, licences, sources) and Trivy for every lockfile. Fix a + finding by upgrading. An ignore says why it doesn't apply: in `deny.toml` with a `reason`, in `.trivyignore.yaml` + with a `statement` and an `expired_at` at most six months out. A new dependency licence goes into `deny.toml`'s + allow list only after a look (no copyleft in the CLI or the images). In `deny.toml`, ignores and licences nothing + uses any more fail the job: remove them. +- **Images are linted and scanned.** hadolint checks the Dockerfiles (`.hadolint.yaml`), and Trivy scans the built + images in CI's images job: fixable HIGH/CRITICAL vulnerabilities and forbidden licences fail a pull request (on main + they only report, and the Audit workflow scans the live app image daily). The Dockerfiles' `FROM` lines keep plain + tags: CI replaces each with the digest-pinned mirror copy (`build-contexts`, `.github/mirror.txt`), whose digests + are linux/amd64 only, so pinning them in `FROM` would break local builds on arm64. The app's runtime stage takes + Debian's security updates on every build. Editing `docker/renderer.Dockerfile` rebuilds the renderer (fresh + packages, which can move pixels): bump `docker/renderer.version` and check renders when you do. - **Hold the merge lock from the final rebase to the merge.** A PR must be up to date with `main` before it merges, so a merge by one agent sends every other agent's PR back through CI. Take Fleetlayer's lock, one per repository, around the last rebase, the CI run and the merge, in one script, and only for one PR at a time: diff --git a/Cargo.lock b/Cargo.lock index 499d46e36..78b1636dc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3455,9 +3455,9 @@ checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" [[package]] name = "pin-project-lite" -version = "0.2.18" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c938015719552d665fd0553b90d96cd7ff58e83e4c061ca99e6bb78865a72752" +checksum = "f120c8d5021b34abd2f2ffd7ee96687cbcd6c54a3e68d86b6169f4a5cd480ffe" [[package]] name = "pkcs1" diff --git a/_typos.toml b/_typos.toml new file mode 100644 index 000000000..e4e5afde8 --- /dev/null +++ b/_typos.toml @@ -0,0 +1,36 @@ +# typos (spelling), run by the pre-commit hook (`typos -w` fixes what it's sure of) and CI's security job. Allow a +# word here only with the reason beside it. + +[default] +extend-ignore-re = [ + # Misspelled on purpose: tests and docs that check an unknown setting or field is caught (envschema's "did you + # mean", visualci.yml's unknown fields). + "APP_S3_REGOIN", + "APP_WAITLSIT", + "MYAPP_DATABSE_POOL", + "\"thresold\"", + "\"thresold: ", + # Possessives in Rust identifiers (close_the_branchs_builds, each_repositorys_collaborators); still typos in prose. + "\\w+_(branchs|repositorys)_\\w+", +] + +[files] +# Binary files: typos skips them when it walks the tree, but checks (and -w rewrites) any file named on the command +# line unless it's excluded here (the hook passes --force-exclude). +extend-exclude = ["*.png", "*.jpg", "*.jpeg", "*.gif", "*.webp", "*.ico", "*.pdf", "*.woff", "*.woff2", "*.ttf", "*.otf", "*.zip", "*.gz"] + +[default.extend-identifiers] +# The plural of PNG, which typos splits into PN + Gs. +PNGs = "PNGs" +# A PDF dictionary key (/DecodeParms). +DecodeParms = "DecodeParms" + +[default.extend-words] +# Postgres's block range index. +brin = "brin" +# PDF's /FlateDecode compression. +flate = "flate" +# Test text: "café" with the accent escaped. +caf = "caf" +# A correct spelling too. +unparseable = "unparseable" diff --git a/clients/gallery/rust/deny.toml b/clients/gallery/rust/deny.toml new file mode 100644 index 000000000..24099798d --- /dev/null +++ b/clients/gallery/rust/deny.toml @@ -0,0 +1,35 @@ +# cargo-deny for the visualci-gallery crate (published on crates.io), run by CI's audit job with +# `-D advisory-not-detected -D license-not-encountered` like the root's: an entry that no longer matches fails. + +[graph] +all-features = true + +[advisories] +yanked = "deny" + +[licenses] +# What its dependency graph uses today, all permissive. +allow = [ + "0BSD", + "Apache-2.0", + "Apache-2.0 WITH LLVM-exception", + "BSD-3-Clause", + "CDLA-Permissive-2.0", + "ISC", + "MIT", + "Unicode-3.0", + "Unlicense", + "Zlib", +] +confidence-threshold = 0.8 + +[licenses.private] +ignore = true + +[bans] +multiple-versions = "allow" + +[sources] +unknown-registry = "deny" +unknown-git = "deny" +allow-registry = ["https://github.com/rust-lang/crates.io-index"] diff --git a/clients/gallery/rust/examples/loco/deny.toml b/clients/gallery/rust/examples/loco/deny.toml new file mode 100644 index 000000000..3c5d50ee6 --- /dev/null +++ b/clients/gallery/rust/examples/loco/deny.toml @@ -0,0 +1,39 @@ +# cargo-deny for the gallery's Loco example (an example app, never published or shipped), run by CI's audit job with +# `-D advisory-not-detected -D license-not-encountered` like the root's. + +[graph] +all-features = true + +[advisories] +yanked = "deny" + +[licenses] +# What Loco's graph uses today. MPL-2.0 (colored, a file-level copyleft) is fine in an example nobody ships. +allow = [ + "0BSD", + "Apache-2.0", + "Apache-2.0 WITH LLVM-exception", + "BSD-2-Clause", + "BSD-3-Clause", + "BSL-1.0", + "CC0-1.0", + "CDLA-Permissive-2.0", + "ISC", + "MIT", + "MPL-2.0", + "Unicode-3.0", + "Unlicense", + "Zlib", +] +confidence-threshold = 0.8 + +[licenses.private] +ignore = true + +[bans] +multiple-versions = "allow" + +[sources] +unknown-registry = "deny" +unknown-git = "deny" +allow-registry = ["https://github.com/rust-lang/crates.io-index"] diff --git a/clients/github-action/action.yml b/clients/github-action/action.yml index 900ef3243..4b9a14fe2 100644 --- a/clients/github-action/action.yml +++ b/clients/github-action/action.yml @@ -153,19 +153,20 @@ runs: fi - if: steps.token.outputs.skipped == 'false' && github.event_name == 'workflow_run' && inputs.artifact != '' - uses: actions/download-artifact@v4 + uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0 with: name: ${{ inputs.artifact }} path: ${{ runner.temp }}/visualci-artifact run-id: ${{ github.event.workflow_run.id }} github-token: ${{ inputs.github-token }} + # zizmor flags the GITHUB_PATH writes: the directory is under RUNNER_TEMP, named by the workflow author's own inputs. - if: steps.token.outputs.skipped == 'false' shell: bash env: VERSION: ${{ inputs.version }} CLI: ${{ inputs.cli }} - run: | + run: | # zizmor: ignore[github-env] if [ -n "$CLI" ]; then dir="$RUNNER_TEMP/visualci-given" mkdir -p "$dir" && cp "$CLI" "$dir/visualci" && chmod +x "$dir/visualci" diff --git a/deny.toml b/deny.toml new file mode 100644 index 000000000..543f1540a --- /dev/null +++ b/deny.toml @@ -0,0 +1,53 @@ +# cargo-deny: known vulnerabilities (RustSec), licences, banned crates and where crates come from, for the root +# workspace. clients/gallery/rust and its Loco example have their own deny.toml (cargo-deny reads the one beside the +# manifest), since each lists only what its own graph uses. CI's audit job runs +# `cargo deny check -D advisory-not-detected -D license-not-encountered`, so an ignore or an allowed licence that no +# longer matches anything fails too: remove it. + +[graph] +all-features = true + +[advisories] +# Yanked crates fail: `cargo update -p `. +yanked = "deny" +ignore = [ + # rsa: the Marvin timing attack (no fixed release in the 0.9 series). A dev-dependency only: app/'s tests sign test + # JWTs with it; nothing that ships uses it. Reviewed 5 Dec 2026 (sc-9611). + { id = "RUSTSEC-2023-0071", reason = "dev-dependency only (app/ tests); nothing shipped decrypts or signs with it" }, +] + +[licenses] +# What the dependency graph uses today, all permissive. A new licence needs a look first: copyleft (GPL, AGPL, LGPL-only) +# doesn't go into the CLI or the server images. +allow = [ + "0BSD", + "Apache-2.0", + "Apache-2.0 WITH LLVM-exception", + "BSD-2-Clause", + "BSD-3-Clause", + "BSL-1.0", + "CC0-1.0", + "CDLA-Permissive-2.0", + "ISC", + "MIT", + "MIT-0", + "Unicode-3.0", + "Unlicense", + "Zlib", +] +confidence-threshold = 0.8 + +[licenses.private] +# Our own unpublished crates (publish = false) aren't checked against the list. +ignore = true + +[bans] +multiple-versions = "allow" +# Allowed: the only wildcards are the CLI's and renderer's path dependencies on our own crates (shipped as binaries, +# never published), and crates.io refuses a published crate with a wildcard anyway. +wildcards = "allow" + +[sources] +unknown-registry = "deny" +unknown-git = "deny" +allow-registry = ["https://github.com/rust-lang/crates.io-index"] diff --git a/docker/app.Dockerfile b/docker/app.Dockerfile index 6c34c0a29..81b490ab4 100644 --- a/docker/app.Dockerfile +++ b/docker/app.Dockerfile @@ -52,7 +52,11 @@ FROM scratch AS bin COPY --from=build /src/target/release/visualci-app /visualci-app FROM debian:trixie-slim -RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates && rm -rf /var/lib/apt/lists/* \ +# Debian's security updates on top of the pinned base image (CI scans the result with Trivy). CI passes today's date, +# so BuildKit's layer cache never keeps yesterday's packages. +ARG SECURITY_UPDATES_DATE= +RUN apt-get update && apt-get upgrade -y --no-install-recommends \ + && apt-get install -y --no-install-recommends ca-certificates && rm -rf /var/lib/apt/lists/* \ && useradd --uid 10001 --create-home visualci WORKDIR /app COPY --from=bin /visualci-app /usr/local/bin/visualci-app diff --git a/lefthook.yml b/lefthook.yml new file mode 100644 index 000000000..10b7de2fc --- /dev/null +++ b/lefthook.yml @@ -0,0 +1,41 @@ +# Git hooks, run by lefthook (mise.toml pins it): `mise install && lefthook install` once per clone. The hooks live in +# the clone's shared .git/hooks, so every worktree gets them. +# +# Formatters fix what they find and stage the result (stage_fixed). CI has no format gate: formatting is never a +# reason for a red build (Nathan, 5 Dec 2026, sc-9611). +pre-commit: + # One at a time: rustfmt and typos both rewrite staged files (and stage them), and two fixers on one file at once + # would lose an edit. The whole hook takes a few seconds. + parallel: false + commands: + # Each file through stdin: given a path, rustfmt also formats (and must parse) every module file it declares, so + # a half-written unstaged module would be rewritten or would refuse the commit. `cat >` keeps the file's mode. + rustfmt: + glob: "*.rs" + run: for f in {staged_files}; do rustfmt --emit stdout <"$f" >"$f.fmt" && cat "$f.fmt" >"$f"; s=$?; rm -f "$f.fmt"; [ $s = 0 ] || exit 1; done + stage_fixed: true + # Spelling: fixes what it's sure of and stages it; anything else fails until fixed or allowed in _typos.toml. + # --force-exclude: typos checks (and -w rewrites) every file it's given by name, images included, unless excluded. + typos: + run: typos -w --force-exclude {staged_files} + stage_fixed: true + oxlint: + glob: "*.{js,mjs,cjs,jsx,ts,mts,cts,tsx,astro,vue,svelte}" + run: oxlint --deny-warnings {staged_files} + shellcheck: + glob: "{*.sh,scripts/*,scripts/**/*,**/bin/*}" + run: scripts/ci/shellcheck.sh {staged_files} + # The workflows and actions: actionlint (with shellcheck on their scripts) and zizmor (.github/zizmor.yml). + actionlint: + glob: ".github/workflows/*.{yml,yaml}" + run: actionlint {staged_files} + zizmor: + glob: "{.github/workflows/*,.github/actions/**/*,.github/zizmor.yml,clients/github-action/action.yml}" + run: zizmor --offline --no-progress . + # The Dockerfiles (.hadolint.yaml). The renderer's two ignores wait for its next rebuild (ci.yml's security job). + hadolint: + glob: "docker/*Dockerfile" + run: hadolint docker/app.Dockerfile && hadolint --ignore DL3003 --ignore DL4006 docker/renderer.Dockerfile + # Secrets in the staged changes (.betterleaks.toml allows the made-up ones). + betterleaks: + run: betterleaks git --pre-commit --staged --no-banner --config .betterleaks.toml . diff --git a/mise.toml b/mise.toml index 4dc113077..a7396b97b 100644 --- a/mise.toml +++ b/mise.toml @@ -1,4 +1,14 @@ -# Tool versions for the frontend and scripts (mise). scripts/on-dev loads them on docspring-dev, where mise has no -# global default node. +# Tool versions for the frontend, scripts, git hooks and CI's security and audit jobs (mise). scripts/on-dev loads them on +# docspring-dev, where mise has no global default node. [tools] node = "24.21.0" +lefthook = "2.2.4" +actionlint = "1.7.12" +shellcheck = "0.12.0" +zizmor = "1.33.1" +betterleaks = "1.10.1" +cargo-deny = "0.22.3" +trivy = "0.77.0" +hadolint = "2.15.1" +typos = "1.53.0" +oxlint = "1.96.0" diff --git a/rustfmt.toml b/rustfmt.toml index c775577ee..c7b39da71 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,2 +1,5 @@ +# The lefthook pre-commit hook runs rustfmt on the staged files, which reads this file but not Cargo.toml: it needs the +# edition here. +edition = "2024" max_width = 120 use_small_heuristics = "Max" diff --git a/scripts/ci/shellcheck.sh b/scripts/ci/shellcheck.sh new file mode 100755 index 000000000..9cdc8ee2d --- /dev/null +++ b/scripts/ci/shellcheck.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash +# ShellCheck on every shell script in the repository (each tracked file whose first line is a sh/bash shebang, and +# every *.sh), at warning level and up. Run by CI's security job, and by the pre-commit hook on just the staged files it +# names (`scripts/ci/shellcheck.sh ...`). mise.toml pins ShellCheck. +# GitHub Actions' run: scripts are actionlint's (it runs ShellCheck on them), and the CircleCI orb's are +# scripts/ci/check_orb.py's. +set -euo pipefail +cd "$(git rev-parse --show-toplevel)" +files=() +while IFS= read -r -d '' f; do + [ -f "$f" ] || continue + case $f in + *.sh) files+=("$f") ;; + *) + first= + IFS= read -r first <"$f" || true + [[ $first =~ ^\#!.*[/\ ](bash|dash|sh)([[:space:]]|$) ]] && files+=("$f") + ;; + esac +done < <(if [ $# -gt 0 ]; then printf '%s\0' "$@"; else git ls-files -z; fi) +[ ${#files[@]} -gt 0 ] || exit 0 +shellcheck --severity=warning "${files[@]}" +echo "ShellCheck: ${#files[@]} scripts clean" diff --git a/scripts/ci/visual.sh b/scripts/ci/visual.sh index 0d3b8b3a4..5e7d3cf3a 100755 --- a/scripts/ci/visual.sh +++ b/scripts/ci/visual.sh @@ -112,7 +112,7 @@ EOF rm -f "$out/site/visualci.schema.json" fi # The link-preview cards the prerender drew (scripts/og.mjs), so a broken card template shows up in review. - rm -rf "$out/og" && cp -r "$root/frontend/dist/og" "$out/og" + rm -rf "$out/og" && cp -R "$root/frontend/dist/og" "$out/og" # Component snapshots, written fresh: the baselines are on VisualCI. cd "$root/frontend" find src -name __snapshots__ -type d -prune -exec rm -rf {} + diff --git a/scripts/on-dev b/scripts/on-dev index 79843d209..a99f020e9 100755 --- a/scripts/on-dev +++ b/scripts/on-dev @@ -85,7 +85,7 @@ sync() { # app/build.rs lists the migrations when database/migrations changes, but rsync keeps a new file's old mtime, so cargo # would build the old list in: touch the folder when a migration was added or removed (not on every sync, which # would rebuild the app each time). - if printf '%s\n' "$changes" | grep -qE '^([<>]f\+{9}|\*deleting) +app/database/migrations/'; then + if grep -qE '^([<>]f\+{9}|\*deleting) +app/database/migrations/' <<<"$changes"; then ssh "$host" "touch '$remote/app/database/migrations'" fi } diff --git a/scripts/screenshots/lightbox.mjs b/scripts/screenshots/lightbox.mjs index 8123d5f51..0705a2d42 100644 --- a/scripts/screenshots/lightbox.mjs +++ b/scripts/screenshots/lightbox.mjs @@ -22,7 +22,7 @@ export async function checkLightbox(browser, base) { const ctx = await browser.newContext({ baseURL: base, viewport: { width: 1440, height: 900 }, deviceScaleFactor: 2 }) try { await ctx.route('https://app.visualci.com/g/**', async (route) => { - if (/-2x\.png$/.test(new URL(route.request().url()).pathname)) await new Promise((r) => setTimeout(r, SLOW_MS)) + if (new URL(route.request().url()).pathname.endsWith('-2x.png')) await new Promise((r) => setTimeout(r, SLOW_MS)) await route.fulfill({ status: 200, contentType: 'image/png', body: PNG }).catch(() => {}) }) const page = await ctx.newPage() @@ -48,7 +48,7 @@ export async function checkLightbox(browser, base) { await page .waitForFunction(() => { const img = document.querySelector('dialog.vg-box .vg-box-view img') - return img && img.complete && /-2x\.png$/.test(img.currentSrc) + return img && img.complete && img.currentSrc.endsWith('-2x.png') }, null, { timeout: SLOW_MS + 5000 }) .catch(async () => { throw new Error(`lightbox: opening "${first.title}": its image never showed (${JSON.stringify(await shown())})`)