#!/usr/bin/env bash # The documentation's whole check, as CI runs it (.github/workflows/wai-quantum-docs.yml) # and as a person runs it on a build host: # # bash wai/tools/quantum-docs/ci.sh [check_docs.py's own arguments, as --only PATH] # # 1. builds the command line and the job service from this checkout; # 2. builds the Python package's wheel with maturin (pinned) and installs it in a # fresh venv with the pinned, hashed test requirements; # 3. starts a job service here, as the service's workflow starts it; # 4. runs check_docs.py over every page docs.json names: every runnable block run, # every shown output held to the real one, every receipt verified, the Rust # blocks built, and every block that cannot run checked for what it names. # # Needs cargo (the toolchain rust-toolchain.toml names), uv and curl. Scratch goes under # $WORK (default: $RUNNER_TEMP/wai-quantum-docs, or a new temporary directory); cargo # builds into $CARGO_TARGET_DIR (default: $WORK/target). set -euo pipefail HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" WAI="$(cd "$HERE/../.." && pwd)" WORK="${WORK:-${RUNNER_TEMP:-$(mktemp -d)}/wai-quantum-docs}" mkdir -p "$WORK" export CARGO_TARGET_DIR="${CARGO_TARGET_DIR:-$WORK/target}" PY="${WAI_QUANTUM_PYTHON:-3.12}" MATURIN=1.15.0 step() { echo; echo "== $*"; } step "the command line and the job service, from this checkout" (cd "$WAI/wai-quantum-cli" && cargo build --locked --release) (cd "$WAI/wai-quantum-service" && cargo build --locked --release) CLI="$CARGO_TARGET_DIR/release/wai-quantum" SVC="$CARGO_TARGET_DIR/release/wai-quantum-service" "$CLI" --version step "the Python package (maturin $MATURIN), in a fresh venv" rm -rf "$WORK/tools" "$WORK/dist" "$WORK/venv" uv venv -q --python "$PY" "$WORK/tools" uv pip install -q --python "$WORK/tools/bin/python" "maturin==$MATURIN" (cd "$WAI/wai-quantum-py" && "$WORK/tools/bin/maturin" build --release --locked -o "$WORK/dist") uv venv -q --python "$PY" "$WORK/venv" uv pip install -q --python "$WORK/venv/bin/python" --require-hashes -r "$WAI/wai-quantum-py/tests/requirements.lock" uv pip install -q --python "$WORK/venv/bin/python" --no-deps "$(ls "$WORK"/dist/wai_quantum-*.whl)" step "a job service, started here" port=$(( 18600 + RANDOM % 500 )) cfg="$WORK/qsvc"; rm -rf "$cfg"; mkdir -p "$cfg" WAI_QSVC_KEY="$cfg/service.key" WAI_QSVC_STORE="$cfg/store" WAI_QSVC_ADDR="127.0.0.1:$port" WAI_QSVC_BUDGET_GB=4 WAI_QSVC_JOB_GB=2 WAI_QSVC_WORKERS=1 \ WAI_QSVC_MIN_FREE_PCT=0 WAI_QSVC_CLIENT_BURST=10000 "$SVC" serve > "$cfg/service.log" 2>&1 & pid=$! trap 'kill $pid 2>/dev/null || true' EXIT for _ in $(seq 1 100); do curl -fs -o /dev/null "http://127.0.0.1:$port/v1/health" && break; sleep 0.2; done curl -fs -o /dev/null "http://127.0.0.1:$port/v1/health" || { echo "::error::the job service did not start"; cat "$cfg/service.log"; exit 1; } step "every page, run" python3 "$HERE/check_docs.py" --cli "$CLI" --service "http://127.0.0.1:$port" --python "$WORK/venv/bin/python" --rust "$@"