Last active
March 20, 2020 11:55
-
-
Save nazwhale/b352ee9ed43d97f5f2a298fe66db3d53 to your computer and use it in GitHub Desktop.
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
# .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