Last active
June 2, 2020 20:02
-
-
Save hdonnay/db0735938d869b65be6ecc9fc95db549 to your computer and use it in GitHub Desktop.
a pre-push git hook that runs smoke tests and memoizes the results in git
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -e | |
imgs="registry.access.redhat.com/ubi8/ubi:8.0-122 docker.io/library/ubuntu docker.io/mitmproxy/mitmproxy:4.0.1" | |
pod='claircore-dev' | |
pause=20 | |
export GIT_NOTES_REF=refs/notes/pre-push | |
cleanup() { | |
exe="$1" | |
out="$2" | |
ct="$3" | |
w="$4" | |
test -f "$out" && { | |
git notes add -F "$out" | |
rm "$out" | |
} | |
rm -f "$exe" | |
printf "pausing pod\n" | |
podman pod pause "${pod}" >/dev/null | |
kill "$w" | |
} | |
remote="$1" | |
if [ "$remote" = origin ] || [ -z "$remote" ]; then | |
if git notes list HEAD >/dev/null 2>&1; then | |
printf '# cached run:\n' | |
git --no-pager notes show | |
exit 0 | |
fi | |
out="$(mktemp)" | |
exe="$(mktemp)" | |
ct="$(mktemp)" | |
trap 'test "$?" -ne 0 && rm "$out"; cleanup "$exe" "$out" "$ct" "$w"' EXIT | |
tail -f "$out" & | |
w="$!" | |
exec >"$out" | |
if podman pod ps -qf "name=$pod" | grep -q .; then | |
go mod vendor | |
podman pod unpause "$pod" >/dev/null | |
for name in libindexhttp libvulnhttp; do | |
if podman ps -qf "name=${name}" >/dev/null 2>&1; then | |
printf 'restarting %s\n' "$name" | |
podman restart "${name}">/dev/null | |
else | |
printf '%s not running???\n' "$name" | |
exit 1 | |
fi | |
done | |
else | |
printf 'spinning up testing pod\n' | |
pause=60 | |
make podman-dev-up | |
fi | |
printf 'feeling sleepy (%d sec)\n' "$pause" | |
sleep "$pause" | |
printf 'running integration tests\n' | |
go test -tags integration ./... | |
printf 'attempting to run "cctool report" against images:\n' | |
for i in $imgs; do printf '\t%s\n' "$i"; done | |
go build -o "$exe" ./cmd/cctool | |
for i in $imgs; do | |
"$exe" report "$i" | tee "$ct" | |
test "$(wc -l < "$ct")" -gt 1 | |
done | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment