diff --git a/.github/actions/playwright/action.yml b/.github/actions/playwright/action.yml new file mode 100644 index 00000000..adffa523 --- /dev/null +++ b/.github/actions/playwright/action.yml @@ -0,0 +1,70 @@ +# Playwright's Chromium and the system packages it needs (scripts/screenshots), with those packages' .deb files kept in +# the GitHub Actions cache. GitHub's Azure apt mirror sometimes serves them at ~50 kB/s, and 6% of runs spent 8 to 17 +# minutes in `playwright install --with-deps` (Dec 2026). The same packages are installed either way, so the fonts the +# screenshots are taken with don't change: apt only reads the .deb files from the cache instead of the mirror, and +# downloads whatever the cache lacks. +name: Playwright +description: pnpm install in scripts/screenshots and Playwright's Chromium with its system packages, from a .deb cache. + +inputs: + save: + description: Save the .deb cache when its packages changed (main only). + required: false + default: "false" + +runs: + using: composite + steps: + # One cache per Ubuntu release and architecture: the packages differ between them. + - id: prefix + shell: bash + run: | + . /etc/os-release + echo "key=playwright-debs-$ID-$VERSION_ID-$(dpkg --print-architecture)-" >>"$GITHUB_OUTPUT" + - id: restore + uses: actions/cache/restore@v4 + with: + path: ~/.cache/playwright-debs + key: ${{ steps.prefix.outputs.key }}none + restore-keys: ${{ steps.prefix.outputs.key }} + # apt-get (which Playwright runs under sudo) keeps the packages it downloads in the cache's folder. + - shell: bash + run: | + dir=$HOME/.cache/playwright-debs + mkdir -p "$dir/partial" + printf 'Dir::Cache::Archives "%s/";\nAPT::Keep-Downloaded-Packages "true";\nBinary::apt-get::APT::Keep-Downloaded-Packages "true";\n' "$dir" | + sudo tee /etc/apt/apt.conf.d/99playwright-debs >/dev/null + sudo rm -f /etc/apt/apt.conf.d/docker-clean + echo "$(find "$dir" -name '*.deb' | wc -l) cached .deb files" + - shell: bash + working-directory: scripts/screenshots + run: pnpm install --frozen-lockfile && pnpm exec playwright install --with-deps chromium + # apt's settings go back, and the folder becomes the runner's, even when the install failed. + - if: always() + shell: bash + run: | + dir=$HOME/.cache/playwright-debs + sudo rm -f /etc/apt/apt.conf.d/99playwright-debs + sudo chown -R "$(id -u):$(id -g)" "$dir" + rm -rf "$dir/partial" "$dir/lock" + # Only the versions installed now are kept, so the cache doesn't grow with every package update. + - id: debs + shell: bash + run: | + dir=$HOME/.cache/playwright-debs + for f in "$dir"/*.deb; do + [ -e "$f" ] || continue + pkg=$(dpkg-deb -f "$f" Package) + ver=$(dpkg-deb -f "$f" Version) + [ "$(dpkg-query -W -f '${Version}' "$pkg" 2>/dev/null)" = "$ver" ] || rm -f "$f" + done + 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 "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 + with: + path: ~/.cache/playwright-debs + key: ${{ steps.debs.outputs.key }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 37079da8..9fde44a0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -65,7 +65,7 @@ jobs: 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 job uses. + # 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 @@ -148,11 +148,9 @@ jobs: - 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. A changed - # snapshot doesn't fail this job: the GitHub check waits for review. Pull requests from forks have no token and skip - # the upload. - visual: - needs: [app] + # 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 @@ -168,7 +166,7 @@ jobs: steps: - uses: actions/checkout@v4 with: - # The CLI sends parent commits, so the build finds its baseline. + # 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. @@ -205,9 +203,56 @@ jobs: working-directory: frontend - run: pnpm install --frozen-lockfile && pnpm build working-directory: frontend - - run: pnpm install --frozen-lockfile && pnpm exec playwright install --with-deps chromium - working-directory: scripts/screenshots + - 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 @@ -216,7 +261,7 @@ jobs: - uses: ./clients/github-action with: token: ${{ secrets.VISUALCI_TOKEN }} - cli: target/debug/visualci + cli: tmp/visualci upload: | tmp/visual/screenshots --prefix screenshots/ --platform chrome-linux tmp/visual/site --prefix site/ @@ -225,12 +270,6 @@ jobs: app/tests/golden/api --prefix json/api/ --format json app/tests/golden/mcp --prefix json/mcp/ --format json tmp/email-snapshots --prefix emails/ --keep-extension - - if: failure() - uses: actions/upload-artifact@v4 - with: - name: visual - path: tmp/visual - retention-days: 7 # 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` @@ -287,8 +326,9 @@ jobs: working-directory: frontend env: GITHUB_TOKEN: ${{ github.token }} - - run: pnpm install --frozen-lockfile && pnpm exec playwright install --with-deps chromium - working-directory: scripts/screenshots + - 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 diff --git a/scripts/ci/visual.sh b/scripts/ci/visual.sh index a9958781..454cda3f 100755 --- a/scripts/ci/visual.sh +++ b/scripts/ci/visual.sh @@ -2,7 +2,7 @@ # VisualCI tests itself: seed a database, start the app (app/, the Laravel Rust app production runs) against it, take # screenshots of the landing page, the docs home and the app, and send them to VisualCI in one build with the Vitest # component snapshots, the request tests' JSON snapshots and a few files the site serves to agents. CI runs it in the -# `visual` job (.github/workflows/ci.yml); it also runs on a build box with Postgres and S3 storage (RustFS) up. +# `visual-capture` and `visual` jobs (ci.yml); it also runs on a build box with Postgres and S3 storage (RustFS) up. # # scripts/ci/visual.sh capture seed, serve, take screenshots and component snapshots into tmp/visual # scripts/ci/visual.sh upload send tmp/visual (and $VISUAL_JSON_DIR) to VisualCI as one build, and finalize it