-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathMakefile
More file actions
61 lines (50 loc) · 1.65 KB
/
Makefile
File metadata and controls
61 lines (50 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# regular expressions for excluded file patterns
EXCLUDE_COVERAGE_FILES="(/examples/)|(/\.tools/)"
# go-install-tool will 'go install' any package $2 and install it locally to $1.
# This will prevent that they are installed in the $USER/go/bin folder and different
# projects ca have different versions of the tools
PROJECT_DIR := $(shell dirname $(abspath $(firstword $(MAKEFILE_LIST))))
TOOLS_DIR ?= $(PROJECT_DIR)/.tools
# $(1) command name
# $(2) repo URL
# $(3) version
define go-install-tool
@[ -f "$(1)-$(3)" ] || { \
set -e ;\
TMP_DIR=$$(mktemp -d) ;\
cd $$TMP_DIR ;\
go mod init tmp ;\
echo "Removing any outdated version of $(1)";\
rm -f $(1)*;\
echo "Downloading $(2)@$(3)" ;\
GOBIN=$(TOOLS_DIR) GOFLAGS="-mod=mod" go install "$(2)@$(3)" ;\
touch "$(1)-$(3)";\
rm -rf $$TMP_DIR ;\
}
endef
# prereqs binary dependencies
GOLANGCI_LINT = $(TOOLS_DIR)/golangci-lint
.PHONY: prereqs
prereqs:
@echo "### Check if prerequisites are met, and installing missing dependencies"
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,v2.3.1)
.PHONY: fmt
fmt: prereqs
@echo "### Formatting code and fixing imports"
$(GOLANGCI_LINT) fmt
.PHONY: lint
lint: prereqs
@echo "### Linting code"
$(GOLANGCI_LINT) run ./... --timeout=6m
.PHONY: test
test:
@echo "### Testing code"
go test -race -mod vendor -a $$(go list ./... | grep -v /examples) -coverpkg=./... -coverprofile coverage.out
.PHONY: coverage-report
coverage-report:
@echo "### Generating coverage report"
go tool cover --func=coverage.out
.PHONY: coverage-report-html
coverage-report-html:
@echo "### Generating HTML coverage report"
go tool cover --html=coverage.out