build: use lefthook for git hooks

This commit is contained in:
2026-04-13 01:24:16 +03:00
parent d31490dbc9
commit a9b6c2ed7b
2 changed files with 20 additions and 26 deletions

View File

@@ -2,7 +2,7 @@ BIN := $(notdir $(CURDIR))
all:
@if [ ! -f ".git/hooks/pre-commit" ]; then \
$(MAKE) precommit-install; \
$(MAKE) install-hooks; \
fi
$(MAKE) build
$(MAKE) run
@@ -31,28 +31,6 @@ uninstall:
lint:
golangci-lint run ./...
.PHONY: precommit-install
precommit-install:
@echo "Installing pre-commit hooks..."
@echo "#!/bin/sh\n\nmake precommit" > .git/hooks/pre-commit
@chmod +x .git/hooks/pre-commit
@echo "Pre-commit hooks installed."
.PHONY: precommit
precommit:
@STAGED_FILES=$$(git diff --cached --name-only --diff-filter=ACM | grep -E '\.go$$'); \
if [ -z "$$STAGED_FILES" ]; then \
echo "No staged Go files to check."; \
else \
set -e; \
echo "Running pre-commit checks..."; \
echo "go fmt"; \
go fmt ./...; \
git add $$STAGED_FILES; \
echo "go vet"; \
go vet ./...; \
echo "golangci-lint"; \
golangci-lint run ./...; \
echo "go test"; \
go test -v ./...; \
fi
.PHONY: install-hooks
install-hooks:
lefthook install

16
lefthook.yml Normal file
View File

@@ -0,0 +1,16 @@
pre-commit:
parallel: true
commands:
fmt:
glob: "*.go"
run: go fmt ./...
stage_fixed: true
vet:
glob: "*.go"
run: go vet ./...
lint:
glob: "*.go"
run: golangci-lint run ./...
test:
glob: "*.go"
run: go test -v ./...