Skip to main content

max / goingson

1.4 KB · 40 lines History Blame Raw
1 #!/bin/bash
2 # Test-target compile gate: blocks a push whose test targets do not build.
3 #
4 # Activate in a fresh clone (one-time):
5 # git config core.hooksPath scripts/githooks
6 #
7 # Bypass for a work-in-progress push: git push --no-verify
8 #
9 # `cargo check` and `cargo clippy` both compile only the lib and bin targets, so
10 # a break confined to `tests/` or a `#[cfg(test)]` module is clean under both and
11 # lands unnoticed (the sqlx 0.9 upgrade shipped exactly that way). `--no-run`
12 # builds every test target without running them, which is the cheap half of the
13 # suite and enough to catch a compile break. Tests still run separately.
14 #
15 # `--workspace` is load-bearing: default-members is src-tauri alone, so a bare
16 # `cargo test --no-run` would skip core, db-sqlite, go-mcp, and got.
17 set -euo pipefail
18
19 ROOT="$(git rev-parse --show-toplevel)"
20 cd "$ROOT"
21
22 # Refs arrive on stdin as "<local ref> <local sha> <remote ref> <remote sha>".
23 # A branch deletion has an all-zero local sha and no tree to build.
24 pushing=0
25 while read -r _local_ref local_sha _remote_ref _remote_sha; do
26 case "$local_sha" in
27 *[!0]*) pushing=1 ;;
28 esac
29 done
30 [ "$pushing" -eq 1 ] || exit 0
31
32 echo "pre-push: building test targets (cargo test --no-run --workspace)..."
33 if ! cargo test --no-run --workspace; then
34 echo "pre-push: test targets failed to build."
35 echo "pre-push: push aborted (use --no-verify to bypass)."
36 exit 1
37 fi
38
39 echo "pre-push: test targets build clean."
40