From 011f26915202a6c5c93e5ecc8b3ed0590fdafb4f Mon Sep 17 00:00:00 2001 From: npeter83 Date: Fri, 16 Oct 2026 00:13:47 +0200 Subject: [PATCH] chore(gate): every lane reports how long it took, and a run can log the times for comparison --- frontend/src/lib/gates.snapshot.json | 30 ++++++++++++++++++++---- scripts/check.sh | 35 ++++++++++++++++++++++++---- 2 files changed, 57 insertions(+), 8 deletions(-) diff --git a/frontend/src/lib/gates.snapshot.json b/frontend/src/lib/gates.snapshot.json index 44a7ff48..a478db2d 100644 --- a/frontend/src/lib/gates.snapshot.json +++ b/frontend/src/lib/gates.snapshot.json @@ -1307,21 +1307,39 @@ "export MSYS_NO_PATHCONV=1 # Git Bash: do not rewrite the in-container paths below", "TESTCOMPOSE=backend/docker-compose.test.yml", "failed=()", + "timings=()", + "ms() { date +%s%3N; }", + "secs() { awk -v t=\"$1\" 'BEGIN { printf \"%.1f\", t / 1000 }'; }", + "took=\"\"", + "timed() { # timed — sets $took (no subshell: it must add to $timings)", + " took=\"$(secs $(($(ms) - $3)))\"", + " timings+=(\"$(printf '%8s s %s' \"$took\" \"$1\")$([ \"$2\" = red ] && echo ' (red)')\")", + " if [ -n \"${GATE_TIMES_FILE:-}\" ]; then", + " printf '%s\\t%s\\t%s\\t%s\\t%s\\t%s\\n' \"$(date -u +%FT%TZ)\" \"$mode\" \"$1\" \"$took\" \"$2\" \\", + " \"$(git rev-parse --short 'HEAD^{tree}' 2>/dev/null)\" >>\"$GATE_TIMES_FILE\"", + " fi", + " return 0", + "}", "lane() { # lane — run it, remember a failure, never stop", - " local name=\"$1\"", + " local name=\"$1\" t0 result=ok", " shift", + " t0=\"$(ms)\"", " if [ \"$brief\" = 0 ]; then", " echo \">> $name…\"", - " \"$@\" || failed+=(\"$name\")", + " \"$@\" || { failed+=(\"$name\"); result=red; }", + " timed \"$name\" \"$result\" \"$t0\"", + " echo \"<< $name: $took s\"", " return 0", " fi", " local out", " out=\"$(mktemp)\"", " if \"$@\" >\"$out\" 2>&1; then", - " echo \">> $name: ok\"", + " timed \"$name\" ok \"$t0\"", + " echo \">> $name: ok ($took s)\"", " else", " failed+=(\"$name\")", - " echo \">> $name: FAILED\"", + " timed \"$name\" red \"$t0\"", + " echo \">> $name: FAILED ($took s)\"", " brief_excerpt \"$out\"", " fi", " rm -f \"$out\"", @@ -1361,6 +1379,7 @@ " return 1", "}", "frontend() { (cd frontend && \"$@\"); }", + "gate_t0=\"$(ms)\"", "lane \"ruff\" ruff_check", "lane \"ruff format --check\" ruff_format", "lane \"basedpyright (new errors only)\" basedpyright", @@ -1387,6 +1406,9 @@ " lane \"pip-audit (backend lock)\" pip_audit", " lane \"npm audit (production dependencies)\" frontend npm audit --omit=dev --audit-level=high", "fi", + "echo \">> lane times:\"", + "printf '%s\\n' \"${timings[@]}\"", + "echo \"$(printf '%8s' \"$(secs $(($(ms) - gate_t0)))\") s total\"", "if [ ${#failed[@]} -eq 0 ]; then", " echo \">> gate ($mode): green ✓\"", " exit 0", diff --git a/scripts/check.sh b/scripts/check.sh index 1b66cf98..41e1217e 100644 --- a/scripts/check.sh +++ b/scripts/check.sh @@ -9,6 +9,8 @@ # bash scripts/check.sh lint the static lanes only: no tests, no build, no audits # … --brief (either mode) a lane's output only when it fails, and only its first # error lines — for an agent, whose context the full log would flood +# GATE_TIMES_FILE= … also append each lane's time as a TSV row (UTC, mode, lane, seconds, +# ok|red, HEAD's tree) — to compare runs; every run prints the times anyway # # Each lane runs even when an earlier one failed, and the summary names every red one: a gate that # stops at the first failure hides the second until the first is fixed. The backend lanes run in the @@ -29,21 +31,42 @@ done export MSYS_NO_PATHCONV=1 # Git Bash: do not rewrite the in-container paths below TESTCOMPOSE=backend/docker-compose.test.yml failed=() +timings=() +ms() { date +%s%3N; } +secs() { awk -v t="$1" 'BEGIN { printf "%.1f", t / 1000 }'; } +# How long each lane took: a line after the lane, a table at the end, and — when GATE_TIMES_FILE names a +# file — one tab-separated row per lane appended to it (UTC time, mode, lane, seconds, ok|red, tree), so +# runs can be compared. The script writes no file unless asked to. +took="" +timed() { # timed — sets $took (no subshell: it must add to $timings) + took="$(secs $(($(ms) - $3)))" + timings+=("$(printf '%8s s %s' "$took" "$1")$([ "$2" = red ] && echo ' (red)')") + if [ -n "${GATE_TIMES_FILE:-}" ]; then + printf '%s\t%s\t%s\t%s\t%s\t%s\n' "$(date -u +%FT%TZ)" "$mode" "$1" "$took" "$2" \ + "$(git rev-parse --short 'HEAD^{tree}' 2>/dev/null)" >>"$GATE_TIMES_FILE" + fi + return 0 +} lane() { # lane — run it, remember a failure, never stop - local name="$1" + local name="$1" t0 result=ok shift + t0="$(ms)" if [ "$brief" = 0 ]; then echo ">> $name…" - "$@" || failed+=("$name") + "$@" || { failed+=("$name"); result=red; } + timed "$name" "$result" "$t0" + echo "<< $name: $took s" return 0 fi local out out="$(mktemp)" if "$@" >"$out" 2>&1; then - echo ">> $name: ok" + timed "$name" ok "$t0" + echo ">> $name: ok ($took s)" else failed+=("$name") - echo ">> $name: FAILED" + timed "$name" red "$t0" + echo ">> $name: FAILED ($took s)" brief_excerpt "$out" fi rm -f "$out" @@ -102,6 +125,7 @@ basedpyright() { frontend() { (cd frontend && "$@"); } +gate_t0="$(ms)" lane "ruff" ruff_check lane "ruff format --check" ruff_format lane "basedpyright (new errors only)" basedpyright @@ -139,6 +163,9 @@ if [ "$mode" = all ]; then lane "npm audit (production dependencies)" frontend npm audit --omit=dev --audit-level=high fi +echo ">> lane times:" +printf '%s\n' "${timings[@]}" +echo "$(printf '%8s' "$(secs $(($(ms) - gate_t0)))") s total" if [ ${#failed[@]} -eq 0 ]; then echo ">> gate ($mode): green ✓" exit 0