diff --git a/Makefile b/Makefile index b7e0b05..e09733d 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: check lint test fmt build clean docker docker-test devserver devserver-stop +.PHONY: check lint test fmt fmt-check build clean docker docker-test devserver devserver-stop hooks VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev") LDFLAGS := -X main.Version=$(VERSION) @@ -21,10 +21,10 @@ lint: @echo "Running linter..." golangci-lint run -# Run tests +# Run tests (30-second timeout) test: @echo "Running tests..." - go test -v ./... + go test -timeout 30s -v ./... # Build the binary build: ./bin/pixad @@ -58,3 +58,10 @@ devserver: docker devserver-stop devserver-stop: -docker stop pixad-dev 2>/dev/null -docker rm pixad-dev 2>/dev/null + +# Install pre-commit hook +hooks: + @printf '#!/bin/sh\nset -e\n' > .git/hooks/pre-commit + @printf 'go mod tidy\ngo fmt ./...\ngit diff --exit-code -- go.mod go.sum || { echo "go mod tidy changed files; please stage and retry"; exit 1; }\n' >> .git/hooks/pre-commit + @printf 'make check\n' >> .git/hooks/pre-commit + @chmod +x .git/hooks/pre-commit