#!/usr/bin/sh # .git/hooks/commit-msg # Run tests, go vet, and linter before allowing commit # Set SKIPCHECK=1 to skip running this # Set NOCHECK=1 to run the checks but not fail the commit # Skip running checks [ -n "$SKIPCHECK" ] && exit 0 rc=0 # Check for missing modules in vendor echo "====> Update modules and vendor" ./tools/prepare-source.sh if [ -n "$(git status --porcelain go.mod vendor/)" ]; then echo "Need to commit new modules" rc=1 fi printf "\n====> Running go test" go test -v -race -covermode atomic -coverprofile=profile.cov ./... || rc=1 printf "\n====> Running go vet\n" # -composites=false Skips the composite literals check, allows unkeyed fields in structs go vet -composites=false -tags=integration ./... || rc=2 printf "\n====> Running linter\n" golangci-lint run --build-tags=integration ./... || rc=3 [ -z "$NOCHECK" ] || exit 0 exit $rc