@@ -18,7 +18,7 @@ COVERAGE_HTML=coverage.html
1818# Default target - show help
1919.DEFAULT_GOAL := help
2020
21- .PHONY : all help version build package clean test test-unit test-clean test-verbose test-race test-integration test-integration-verbose test-nats test-vault test-all test-diskfull integration integration-nats integration-vault integration-syslog integration-debug integration-diskfull bench bench-full fmt vet security gosec trivy coverage coverage-text deploy deps check ci build-examples run-examples install-tools
21+ .PHONY : all help version build package clean test test-unit test-clean test-verbose test-race test-integration test-integration-verbose test-nats test-vault test-all test-diskfull integration integration-nats integration-vault integration-syslog integration-debug integration-diskfull bench bench-full fmt vet security gosec trivy coverage coverage-text deploy deps check ci build-examples run-examples install-tools hooks-install hooks-uninstall hooks-check pre-commit pre-push
2222
2323# Show help with version
2424help :
5959 @printf " \033[36m%-25s\033[0m %s\n" " trivy" " Run trivy vulnerability scanner"
6060 @printf " \033[36m%-25s\033[0m %s\n" " coverage" " Generate HTML coverage report"
6161 @printf " \033[36m%-25s\033[0m %s\n" " coverage-text" " Show coverage summary in terminal"
62+ @printf " \033[36m%-25s\033[0m %s\n" " pre-commit" " Run all pre-commit checks (fmt, vet, build)"
63+ @printf " \033[36m%-25s\033[0m %s\n" " pre-push" " Run all pre-push checks (gosec, trivy, test)"
6264 @echo " "
6365 @echo " Performance:"
6466 @printf " \033[36m%-25s\033[0m %s\n" " bench" " Run benchmarks"
7375 @echo " Examples:"
7476 @printf " \033[36m%-25s\033[0m %s\n" " run-examples" " Run all example applications"
7577 @echo " "
78+ @echo " Git Hooks:"
79+ @printf " \033[36m%-25s\033[0m %s\n" " hooks-install" " Install git hooks for code quality"
80+ @printf " \033[36m%-25s\033[0m %s\n" " hooks-uninstall" " Remove git hooks"
81+ @printf " \033[36m%-25s\033[0m %s\n" " hooks-check" " Show current hooks configuration"
82+ @echo " "
7683 @echo " Version: $( VERSION) "
7784
7885# Show version
@@ -242,6 +249,16 @@ trivy:
242249security : gosec trivy
243250 @echo " All security checks completed!"
244251
252+ # Pre-commit checks - Run all checks required before committing
253+ pre-commit : fmt vet build
254+ @echo " "
255+ @echo " ✅ All pre-commit checks passed!"
256+
257+ # Pre-push checks - Run all checks required before pushing
258+ pre-push : gosec trivy test
259+ @echo " "
260+ @echo " ✅ All pre-push checks passed!"
261+
245262# Coverage targets
246263coverage :
247264 @echo " Generating coverage report..."
@@ -300,3 +317,52 @@ install-tools:
300317 @$(GOCMD ) install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
301318 @$(GOCMD ) install github.com/securego/gosec/v2/cmd/gosec@latest
302319 @$(GOCMD ) install golang.org/x/tools/cmd/goimports@latest
320+
321+ # Git hooks management
322+ hooks-install :
323+ @echo " Installing git hooks..."
324+ @if [ -d .git ]; then \
325+ git config core.hooksPath .githooks; \
326+ echo " ✅ Git hooks installed successfully!" ; \
327+ echo " Pre-commit: go fmt, go vet, make build" ; \
328+ echo " Pre-push: gosec, trivy, go test" ; \
329+ else \
330+ echo " ❌ Not a git repository. Please run this command from the project root." ; \
331+ exit 1; \
332+ fi
333+
334+ hooks-uninstall :
335+ @echo " Uninstalling git hooks..."
336+ @if [ -d .git ]; then \
337+ git config --unset core.hooksPath; \
338+ echo " ✅ Git hooks uninstalled successfully!" ; \
339+ else \
340+ echo " ❌ Not a git repository. Please run this command from the project root." ; \
341+ exit 1; \
342+ fi
343+
344+ hooks-check :
345+ @echo " Checking git hooks configuration..."
346+ @if [ -d .git ]; then \
347+ hooks_path=$$(git config core.hooksPath ) ; \
348+ if [ -n " $$ hooks_path" ]; then \
349+ echo " ✅ Git hooks are active" ; \
350+ echo " Hooks path: $$ hooks_path" ; \
351+ if [ -f " $$ hooks_path/pre-commit" ]; then \
352+ echo " Pre-commit hook: Installed" ; \
353+ else \
354+ echo " Pre-commit hook: Not found" ; \
355+ fi ; \
356+ if [ -f " $$ hooks_path/pre-push" ]; then \
357+ echo " Pre-push hook: Installed" ; \
358+ else \
359+ echo " Pre-push hook: Not found" ; \
360+ fi ; \
361+ else \
362+ echo " ❌ Git hooks are not active" ; \
363+ echo " Run 'make hooks-install' to activate them" ; \
364+ fi ; \
365+ else \
366+ echo " ❌ Not a git repository. Please run this command from the project root." ; \
367+ exit 1; \
368+ fi
0 commit comments