Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,10 @@ jobs:
s3-prefix: visualci
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_server -p visualci-cli
# The CLI (root workspace) and the app the screenshots are taken against (app/, its own workspace).
- run: cargo build --locked -p visualci-cli
- run: cargo build --locked --bin visualci-app
working-directory: app
- uses: pnpm/action-setup@v4
with:
package_json_file: server/frontend/package.json
Expand Down
106 changes: 81 additions & 25 deletions scripts/ci/visual.sh
Original file line number Diff line number Diff line change
@@ -1,57 +1,113 @@
#!/usr/bin/env bash
# VisualCI tests itself: seed a database, start the server 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 dev machine with Postgres and S3 storage (MinIO or RustFS) up.
# 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.
#
# 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
#
# Needs: target/debug/visualci-server and visualci (cargo build), server/frontend/dist (pnpm build), and
# Needs: app/target/debug/visualci-app and target/debug/visualci (cargo build), server/frontend/dist (pnpm build), and
# scripts/screenshots/node_modules with Playwright's Chromium. Settings: PORT (5151), DATABASE_URL (a database this
# script drops and recreates), S3_BUCKET, VISUAL_JSON_DIR (the request tests' JSON snapshots), VISUALCI_TOKEN.
# script drops and recreates), S3_ENDPOINT and S3_BUCKET (made if missing), VISUAL_JSON_DIR (the request tests' JSON
# snapshots), VISUALCI_TOKEN.
set -euo pipefail

root=$(cd "$(dirname "$0")/../.." && pwd)
out=$root/tmp/visual
run=$root/tmp/visual-app
port=${PORT:-5151}
export DATABASE_URL=${DATABASE_URL:-postgres://loco:loco@127.0.0.1:55433/visualci_screenshots}
export S3_BUCKET=${S3_BUCKET:-visualci-screenshots}
export LOCO_ENV=development
# The month the seeded credit usage falls in (server/src/tasks/screenshots_seed.rs NOW).
export VISUALCI_NOW=2026-11-20T15:00:00Z
server=$root/target/debug/visualci-server
s3=${S3_ENDPOINT:-http://127.0.0.1:59000}
bucket=${S3_BUCKET:-visualci-screenshots}
app=${VISUALCI_APP_BIN:-$root/app/target/debug/visualci-app}
cli=$root/target/debug/visualci

# The bucket, as production's R2 bucket exists (the app makes none): the AWS CLI where it's installed (GitHub's
# runners), else its image.
make_bucket() {
local keys=(-e AWS_ACCESS_KEY_ID=visualci -e AWS_SECRET_ACCESS_KEY=visualci-dev-secret -e AWS_DEFAULT_REGION=us-east-1)
for _ in $(seq 1 10); do
if command -v aws >/dev/null; then
if AWS_ACCESS_KEY_ID=visualci AWS_SECRET_ACCESS_KEY=visualci-dev-secret AWS_DEFAULT_REGION=us-east-1 \
aws --endpoint-url "$s3" s3api head-bucket --bucket "$bucket" >/dev/null 2>&1 ||
AWS_ACCESS_KEY_ID=visualci AWS_SECRET_ACCESS_KEY=visualci-dev-secret AWS_DEFAULT_REGION=us-east-1 \
aws --endpoint-url "$s3" s3 mb "s3://$bucket" >/dev/null 2>&1; then
return 0
fi
elif docker run --rm --network host "${keys[@]}" amazon/aws-cli:2.17.0 --endpoint-url "$s3" \
s3api head-bucket --bucket "$bucket" >/dev/null 2>&1 ||
docker run --rm --network host "${keys[@]}" amazon/aws-cli:2.17.0 --endpoint-url "$s3" \
s3 mb "s3://$bucket" >/dev/null 2>&1; then
return 0
fi
sleep 2
done
echo "couldn't make the bucket $bucket at $s3" >&2
exit 1
}

capture() {
rm -rf "$out"
mkdir -p "$out"
cd "$root/server"
rm -rf "$out" "$run"
mkdir -p "$out" "$run/storage/app" "$run/storage/framework" "$run/storage/logs"
# The app serves the built React app and the site from its public folder.
ln -sfn "$root/server/frontend/dist" "$run/public"
# A fresh database every time, so the seeded ids are the same.
local db=${DATABASE_URL##*/}
psql "${DATABASE_URL%/*}/postgres" -tAc "SELECT 1 FROM pg_database WHERE datname = '$db'" | grep -q 1 ||
psql "${DATABASE_URL%/*}/postgres" -qc "CREATE DATABASE $db"
"$server" db reset >"$out/seed.log" 2>&1 || { cat "$out/seed.log"; exit 1; }
"$server" task screenshots:seed >>"$out/seed.log" 2>&1 || { cat "$out/seed.log"; exit 1; }
PORT=$port "$server" start --binding 127.0.0.1 --no-banner >"$out/server.log" 2>&1 &
psql "${DATABASE_URL%/*}/postgres" -qc "DROP DATABASE IF EXISTS $db WITH (FORCE)"
psql "${DATABASE_URL%/*}/postgres" -qc "CREATE DATABASE $db"
make_bucket
cat >"$run/env" <<EOF
APP_ENV=local
APP_DEBUG=false
APP_URL=http://127.0.0.1:$port
APP_BASE_PATH=$run
SERVER_HOST=127.0.0.1
SERVER_PORT=$port
LOG_CHANNEL=stderr
DB_CONNECTION=pgsql
DATABASE_URL=$DATABASE_URL
CACHE_STORE=database
SESSION_DRIVER=database
QUEUE_CONNECTION=database
S3_ENDPOINT=$s3
S3_PUBLIC_ENDPOINT=$s3
S3_BUCKET=$bucket
S3_ACCESS_KEY_ID=visualci
S3_SECRET_ACCESS_KEY=visualci-dev-secret
RENDERER_TOKEN=visual-renderer-token
RENDERER_VERSION=$(cat "$root/docker/renderer.version")
DEV_LOGIN=true
VISUALCI_NOW=2026-11-20T15:00:00Z
EOF
set -a
. "$run/env"
set +a
echo "APP_KEY=$("$app" key:generate --show 2>/dev/null | tail -1)" >>"$run/env"
set -a
. "$run/env"
set +a
"$app" migrate --force >"$out/seed.log" 2>&1 || { cat "$out/seed.log"; exit 1; }
"$app" screenshots:seed >>"$out/seed.log" 2>&1 || { cat "$out/seed.log"; exit 1; }
(cd "$run" && exec "$app" serve >"$out/server.log" 2>&1) &
server_pid=$!
trap 'kill $server_pid 2>/dev/null || true' EXIT
(cd "$run" && exec "$app" queue:work >"$out/worker.log" 2>&1) &
worker_pid=$!
trap 'kill $server_pid $worker_pid 2>/dev/null || true' EXIT
for _ in $(seq 1 60); do
curl -fsS "http://127.0.0.1:$port/_ping" >/dev/null 2>&1 && break
curl -fsS "http://127.0.0.1:$port/up" >/dev/null 2>&1 && break
sleep 1
done
curl -fsS "http://127.0.0.1:$port/_ping" >/dev/null || { tail -50 "$out/server.log"; exit 1; }

curl -fsS "http://127.0.0.1:$port/up" >/dev/null || { tail -50 "$out/server.log"; exit 1; }
(cd "$root/scripts/screenshots" && node capture.mjs --base-url "http://127.0.0.1:$port" --out "$out/screenshots")
(cd "$root/scripts/screenshots" && node checks.mjs --base-url "http://127.0.0.1:$port")

# Files the site serves to agents.
mkdir -p "$out/site/docs"
curl -fsS "http://127.0.0.1:$port/llms.txt" -o "$out/site/llms.txt"
curl -fsS "http://127.0.0.1:$port/docs/quick-start.md" -o "$out/site/docs/quick-start.md"
if curl -fsS "http://127.0.0.1:$port/visualci.schema.json" -o "$out/site/visualci.schema.json" 2>/dev/null; then :; else
rm -f "$out/site/visualci.schema.json"
fi

# Component snapshots, written fresh: the baselines are on VisualCI.
cd "$root/server/frontend"
find src -name __snapshots__ -type d -prune -exec rm -rf {} +
Expand Down
4 changes: 2 additions & 2 deletions scripts/screenshots/capture.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// VisualCI's own screenshots: the landing page, the docs home and the app, against a server seeded with
// `visualci-server task screenshots:seed` (server/src/tasks/screenshots_seed.rs). Each page is taken at 1440 and 390 px
// VisualCI's own screenshots: the landing page, the docs home and the app, against app/ seeded with
// `visualci-app screenshots:seed` (app/src/domain/demo.rs). Each page is taken at 1440 and 390 px
// wide, light and dark, as `<page>/<width>-<theme>.png` under the output folder, for `visualci upload`.
//
// node capture.mjs [--base-url http://127.0.0.1:5151] [--out out/shots] [--only <substring>]
Expand Down
Loading