diff --git a/Makefile b/Makefile index 2340aae8..0bb814fc 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,23 @@ +golangci_lint_cmd=golangci-lint +golangci_version=v1.57.2 +gofumpt_cmd=gofumpt +gofumpt_version=v0.6.0 + VERSION := $(shell echo $(shell git describe --tags) | sed 's/^v//') COMMIT := $(shell git log -1 --format='%H') +default: help + +.PHONY: help +## help: Prints this help message +help: Makefile + @echo + @echo "Available make commands:" + @echo + @sed -n 's/^##//p' $< | column -t -s ':' | sed -e 's/^/ /' + @echo + + all: install LD_FLAGS = -X github.com/strangelove-ventures/horcrux/v3/cmd/horcrux/cmd.Version=$(VERSION) \ @@ -57,3 +74,30 @@ proto-lint: .PHONY: all lint test race msan tools clean build + +.PHONY: lint +## lint: Lint the repository +lint: + @echo "--> Running linter" + @if ! $(golangci_lint_cmd) --version 2>/dev/null | grep -q $(golangci_version); then \ + go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(golangci_version); \ + fi + @$(golangci_lint_cmd) run ./... --timeout 15m + +.PHONY: lint-fix +## lint-fix: Lint the repository and fix warnings (if applicable) +lint-fix: + @echo "--> Running linter and fixing issues" + @if ! $(golangci_lint_cmd) --version 2>/dev/null | grep -q $(golangci_version); then \ + go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(golangci_version); \ + fi + @$(golangci_lint_cmd) run ./... --fix --timeout 15m + +.PHONY: gofumpt +## gofumpt: Format the code with gofumpt +gofumpt: + @echo "--> Running gofumpt" + @if ! $(gofumpt_cmd) -version 2>/dev/null | grep -q $(gofumpt_version); then \ + go install mvdan.cc/gofumpt@$(gofumpt_version); \ + fi + @gofumpt -l -w . \ No newline at end of file