feat: add pre-commit and pre-push git hooks

Pre-commit runs go vet, golangci-lint (optional), and fast tests.
Pre-push runs full test suite and build verification.
Installable via `make hooks`.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Algis Dumbris
2026-03-13 20:17:15 +02:00
co-authored by Claude Opus 4.6
parent fcb8da613c
commit 7de0114927
3 changed files with 55 additions and 1 deletions
+9 -1
View File
@@ -1,4 +1,4 @@
.PHONY: build test dev web clean lint
.PHONY: build test dev web clean lint hooks
BINARY := synapbus
MODULE := github.com/smart-mcp-proxy/synapbus
@@ -29,4 +29,12 @@ clean:
lint:
golangci-lint run ./...
hooks:
@echo "Installing git hooks..."
@mkdir -p scripts/hooks
@chmod +x scripts/hooks/pre-commit scripts/hooks/pre-push
@ln -sf ../../scripts/hooks/pre-commit .git/hooks/pre-commit
@ln -sf ../../scripts/hooks/pre-push .git/hooks/pre-push
@echo "✅ Git hooks installed"
.DEFAULT_GOAL := build
+31
View File
@@ -0,0 +1,31 @@
#!/usr/bin/env bash
# Pre-commit hook: fast quality checks on staged Go files
set -e
echo "🔍 Pre-commit checks..."
# Check if any Go files are staged
STAGED_GO_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep '\.go$' || true)
if [ -z "$STAGED_GO_FILES" ]; then
echo "✅ No Go files staged, skipping checks"
exit 0
fi
# 1. go vet
echo " Running go vet..."
CGO_ENABLED=0 go vet ./... || { echo "❌ go vet failed"; exit 1; }
# 2. golangci-lint (skip if not installed)
if command -v golangci-lint &> /dev/null; then
echo " Running golangci-lint..."
golangci-lint run --new-from-rev=HEAD~1 ./... || { echo "❌ golangci-lint failed"; exit 1; }
else
echo " ⚠️ golangci-lint not found, skipping (install: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest)"
fi
# 3. Fast unit tests (short mode)
echo " Running fast tests..."
CGO_ENABLED=0 go test -short -count=1 ./... || { echo "❌ tests failed"; exit 1; }
echo "✅ All pre-commit checks passed"
+15
View File
@@ -0,0 +1,15 @@
#!/usr/bin/env bash
# Pre-push hook: full validation before pushing
set -e
echo "🔍 Pre-push checks..."
# 1. Full test suite
echo " Running full test suite..."
CGO_ENABLED=0 go test -count=1 -timeout 120s ./... || { echo "❌ tests failed"; exit 1; }
# 2. Build verification
echo " Verifying build..."
CGO_ENABLED=0 go build -o /dev/null ./cmd/synapbus/ || { echo "❌ build failed"; exit 1; }
echo "✅ All pre-push checks passed"