diff --git a/CLAUDE.md b/CLAUDE.md index 5ca418174..b36bd290e 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -119,12 +119,15 @@ in `docs/adr/0001-testing-strategy.md`. ### Pre-push checklist -These mirror what CI runs on every PR. Run them all before shipping a feature. +`npm run check:ci` runs everything CI runs on every PR, in order, and stops +at the first failure. It writes the full output, with each step's duration +and exit code, to `tests/tmp/check-ci.log`: ```sh npm run check # tsc, svelte-check, eslint, prettier, # cargo fmt, cargo clippy, cargo test npm run test:unit +scripts/install-binaries # skipped when already installed npm run test:e2e ``` diff --git a/package.json b/package.json index ebe805e59..6ed358f8b 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "check": "scripts/check-js && scripts/check-rs", "check-js": "scripts/check-js", "check-rs": "scripts/check-rs", + "check:ci": "scripts/check-ci", "test:unit": "TZ='UTC' vitest run", "test:e2e": "TZ='UTC' playwright test", "format": "npx prettier . --write && npx eslint --fix .", diff --git a/scripts/check-ci b/scripts/check-ci new file mode 100755 index 000000000..4a0a8b797 --- /dev/null +++ b/scripts/check-ci @@ -0,0 +1,85 @@ +#!/usr/bin/env bash +# Runs the same checks as CI and keeps the full output with per-step timings in +# tests/tmp/check-ci.log. That log lives outside tests/artifacts, which +# Playwright clears when the e2e run starts. +set -uo pipefail + +cd "$(dirname "$0")/.." || exit + +log=tests/tmp/check-ci.log +mkdir -p "$(dirname "$log")" +echo "check-ci started $(date -u +%Y-%m-%dT%H:%M:%SZ) at $(git rev-parse --short HEAD)" >"$log" + +if [ -t 1 ]; then + bold=$'\e[1m' dim=$'\e[2m' green=$'\e[32m' red=$'\e[31m' reset=$'\e[0m' +else + bold="" dim="" green="" red="" reset="" +fi + +# Prints to the terminal with styling and to the log without. +say() { + printf '%s\n' "$1" + printf '%s\n' "$2" >>"$log" +} + +width=$(tput cols 2>/dev/null || echo 80) +[ "$width" -gt 100 ] && width=100 + +# A full-width rule with a title, like "━━ check-js ━━━━━━". +rule() { + local text="━━ $1 " + local fill=$((width - ${#text})) + [ "$fill" -lt 3 ] && fill=3 + printf '%s%s' "$text" "$(printf '━%.0s' $(seq 1 "$fill"))" +} + +steps=( + "check-js|scripts/check-js" + "check-rs|scripts/check-rs" + "test:unit|npm run test:unit" + "install-binaries|scripts/install-binaries" + "test:e2e|npm run test:e2e" +) +summary=() +status=0 +total_start=$SECONDS + +for step in "${steps[@]}"; do + name=${step%%|*} + command=${step#*|} + if [ "$status" -ne 0 ]; then + summary+=("$(printf '%s- %-18s skipped%s' "$dim" "$name" "$reset")|$(printf -- '- %-18s skipped' "$name")") + continue + fi + + say "" "" + say "${bold}$(rule "$name")${reset}" "$(rule "$name")" + say "${dim} \$ $command${reset}" " \$ $command" + say "" "" + start=$SECONDS + bash -c "$command" 2>&1 | awk '{ print " " $0; fflush() }' | tee -a "$log" + status=${PIPESTATUS[0]} + took=$((SECONDS - start)) + + if [ "$status" -eq 0 ]; then + summary+=("$(printf '%s✓%s %-18s %4ss' "$green" "$reset" "$name" "$took")|$(printf '✓ %-18s %4ss' "$name" "$took")") + else + summary+=("$(printf '%s✗ %-18s %4ss exit %s%s' "$red" "$name" "$took" "$status" "$reset")|$(printf '✗ %-18s %4ss exit %s' "$name" "$took" "$status")") + fi +done + +say "" "" +say "${bold}$(rule summary)${reset}" "$(rule summary)" +say "" "" +for line in "${summary[@]}"; do + say " ${line%%|*}" " ${line#*|}" +done +say "" "" + +took=$((SECONDS - total_start)) +if [ "$status" -eq 0 ]; then + say " ${bold}${green}All checks passed in ${took}s${reset} ${dim}· log: $log${reset}" " All checks passed in ${took}s" +else + say " ${bold}${red}Checks failed after ${took}s${reset} ${dim}· log: $log${reset}" " Checks failed after ${took}s" +fi +exit "$status"