mirror of
https://github.com/chenasraf/sofmani.git
synced 2026-05-17 17:28:04 +00:00
build: use lefthook for git hooks
This commit is contained in:
30
Makefile
30
Makefile
@@ -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
16
lefthook.yml
Normal 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 ./...
|
||||
Reference in New Issue
Block a user