Skip to content

Commit

Permalink
build(make): use GOBIN from mod file
Browse files Browse the repository at this point in the history
inspired by `go-version-file` input from `actions/setup-go` action.

Signed-off-by: Dwi Siswanto <[email protected]>
  • Loading branch information
dwisiswant0 committed Jun 7, 2024
1 parent 9519384 commit ec7cd92
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
.DEFAULT_GOAL := help

GO_MOD_VERSION := $(shell grep -Po '^go \K([0-9]+\.[0-9]+(\.[0-9]+)?)$$' go.mod)
GO := go${GO_MOD_VERSION}
BENCH_TARGET := .
COVER_COUNT := 1

ifeq ($(shell which ${GO}),)
GO = go
endif

help: ## Displays this help message.
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)

test: vet ## Runs the tests and vetting
go test -v -race -count=1 ./...
$(GO) test -v -race -count=1 ./...

vet: ## Run vetting checks
go vet ./...
$(GO) vet ./...

semgrep: ## Run semgrep
semgrep --config auto
Expand All @@ -24,23 +30,23 @@ report: ## Run goreportcard
test-all: semgrep lint test report ## Run the tests, vetting, and golangci-lint, and semgrep

tidy: ## Tidy up the modules
go mod tidy
$(GO) mod tidy

ci: tidy vet ## Run the tidy, vet, and tests checks (specific for CI)
go test -cover -race -count=1 ./...
$(GO) test -cover -race -count=1 ./...

cover: FILE := coverage.txt
cover: ## Run coverage
go test -race -coverprofile=$(FILE) -covermode=atomic -count=$(COVER_COUNT) $(TARGET)
go tool cover -func=$(FILE)
$(GO) test -race -coverprofile=$(FILE) -covermode=atomic -count=$(COVER_COUNT) $(TARGET)
$(GO) tool cover -func=$(FILE)

cover-all: ## Run coverage but recursive
cover-all: COVER_COUNT := 2
cover-all: TARGET := ./...
cover-all: cover

bench: ## Run benchmarking
go test -run "^$$" -bench "$(BENCH_TARGET)" -cpu=4 $(ARGS)
$(GO) test -run "^$$" -bench "$(BENCH_TARGET)" -cpu=4 $(ARGS)

bench-initialize: ## Run benchmarking for initializing
bench-initialize: BENCH_TARGET := ^BenchmarkInitialize
Expand Down

0 comments on commit ec7cd92

Please sign in to comment.