Skip to content

Instantly share code, notes, and snippets.

@nazwhale
Last active March 20, 2020 11:55
Show Gist options
  • Save nazwhale/b352ee9ed43d97f5f2a298fe66db3d53 to your computer and use it in GitHub Desktop.
Save nazwhale/b352ee9ed43d97f5f2a298fe66db3d53 to your computer and use it in GitHub Desktop.
# .git/hooks/pre-commit
#
# So that the "pre-commit checks passed!" message is said by a random animal:
# brew install cowsay && brew install lolcat
goFmtScript="./bin/_run_go_fmt"
staticAnalysisScript="./bin/_run_static_analysis"
boldEcho () {
echo "\033[1m\n$1\033[0m"
}
### Lets go...
cd $GOPATH/src/github.com/monzo/wearedev
boldEcho '🎬 Action!' | lolcat
sleep 0.5
# Get services changed, return early if none found
SERVICES=$(aps --include-dependencies=false | awk '{print "./" $1 "/..."}')
if [[ -z "$SERVICES" ]]; then
echo "👌 nothing to test"
sleep 0.5
exit 0
fi
boldEcho "Services changed"
for s in "$SERVICES"; do
echo "$s"
done
# Run checks
boldEcho "rpcmap"
rpcmap -generate ${SERVICES} || exit 1
echo "✅ The map is cool"
boldEcho "svcchecker"
go run tools/svcchecker/cmd/svcchecker/*.go ${SERVICES} || exit 1
echo "✅ The services are checkered"
boldEcho "Go test"
go test ${SERVICES} || exit 1
echo "✅ Tests passed"
boldEcho "Go fmt"
${goFmtScript} || exit 1
echo "✅ gofmt complete"
boldEcho "Go vet"
go vet ${SERVICES} || exit 1
echo "✅ govet complete"
# Animal time
zoo=(turtle dragon-and-cow koala elephant turkey bud-frogs sheep moose)
lenZoo=${#zoo}
randZooIndex=$((1 + RANDOM % lenZoo))
animal=${zoo[randZooIndex]}
boldEcho "Pre-commit checks passed!" | cowsay -f ${animal} | lolcat
sleep 0.5
cd - > /dev/null
boldEcho 'Let'\''s commit...'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment