.githooks/pre-push
54 lines · 1819 bytes · executable
1#!/bin/sh
2# Run the full test suite before every push. There is no CI for this repo; this
3# hook is the only gate, so it runs everything and a failure aborts the push.
4#
5# Wired up once per clone with:
6#
7# git config core.hooksPath .githooks
8set -eu
9
10root=$(git rev-parse --show-toplevel)
11cd "$root"
12
13# The differential secret-typing tests (the privacy ship-gate) drive a real
14# interactive zsh under zsh/zpty. Check for it up front so a missing zsh fails
15# with a clear message instead of deep inside cargo test, and is never silently
16# skipped.
17echo "pre-push: zsh/zpty preflight" >&2
18zsh -c 'zmodload zsh/zpty' || {
19 echo "pre-push: needs zsh with the zsh/zpty module" >&2
20 exit 1
21}
22
23echo "pre-push: cargo test" >&2
24cargo test --locked
25
26echo "pre-push: cargo clippy" >&2
27cargo clippy --all-targets --locked -- -D warnings
28
29# The Swift packages are siblings of the cargo workspace; their tests only run
30# on macOS. Both are gated here, or a package outside the gate quietly rots.
31case "$(uname -s)" in
32Darwin)
33 echo "pre-push: swift test (macos-collector)" >&2
34 swift test --package-path "$root/macos-collector"
35
36 echo "pre-push: swift test (menubar-pet)" >&2
37 swift test --package-path "$root/menubar-pet"
38
39 # The app is only an app if the bundle assembles: LSUIElement is what
40 # keeps it out of the Dock, and a broken Info.plist is invisible until
41 # someone launches it.
42 echo "pre-push: menubar-pet bundle" >&2
43 swift build -c release --package-path "$root/menubar-pet" >/dev/null
44 bundle_dir=$(mktemp -d)
45 "$root/menubar-pet/scripts/bundle.sh" \
46 "$root/menubar-pet/.build/release/menubar-pet" "$bundle_dir" >/dev/null
47 plutil -extract LSUIElement raw \
48 "$bundle_dir/menubar-pet.app/Contents/Info.plist" >/dev/null
49 rm -rf "$bundle_dir"
50 ;;
51*)
52 echo "pre-push: not macOS, skipping swift test" >&2
53 ;;
54esac