...
1# Directory containing the Makefile.
2PROJECT_ROOT = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
3
4export GOBIN ?= $(PROJECT_ROOT)/bin
5export PATH := $(GOBIN):$(PATH)
6
7GOVULNCHECK = $(GOBIN)/govulncheck
8BENCH_FLAGS ?= -cpuprofile=cpu.pprof -memprofile=mem.pprof -benchmem
9
10# Directories containing independent Go modules.
11MODULE_DIRS = . ./exp ./benchmarks ./zapgrpc/internal/test
12
13# Directories that we want to track coverage for.
14COVER_DIRS = . ./exp
15
16.PHONY: all
17all: lint test
18
19.PHONY: lint
20lint: golangci-lint tidy-lint license-lint
21
22.PHONY: golangci-lint
23golangci-lint:
24 @$(foreach mod,$(MODULE_DIRS), \
25 (cd $(mod) && \
26 echo "[lint] golangci-lint: $(mod)" && \
27 golangci-lint run --path-prefix $(mod)) &&) true
28
29.PHONY: tidy
30tidy:
31 @$(foreach dir,$(MODULE_DIRS), \
32 (cd $(dir) && go mod tidy) &&) true
33
34.PHONY: tidy-lint
35tidy-lint:
36 @$(foreach mod,$(MODULE_DIRS), \
37 (cd $(mod) && \
38 echo "[lint] tidy: $(mod)" && \
39 go mod tidy && \
40 git diff --exit-code -- go.mod go.sum) &&) true
41
42
43.PHONY: license-lint
44license-lint:
45 ./checklicense.sh
46
47$(GOVULNCHECK):
48 cd tools && go install golang.org/x/vuln/cmd/govulncheck
49
50.PHONY: test
51test:
52 @$(foreach dir,$(MODULE_DIRS),(cd $(dir) && go test -race ./...) &&) true
53
54.PHONY: cover
55cover:
56 @$(foreach dir,$(COVER_DIRS), ( \
57 cd $(dir) && \
58 go test -race -coverprofile=cover.out -coverpkg=./... ./... \
59 && go tool cover -html=cover.out -o cover.html) &&) true
60
61.PHONY: bench
62BENCH ?= .
63bench:
64 @$(foreach dir,$(MODULE_DIRS), ( \
65 cd $(dir) && \
66 go list ./... | xargs -n1 go test -bench=$(BENCH) -run="^$$" $(BENCH_FLAGS) \
67 ) &&) true
68
69.PHONY: updatereadme
70updatereadme:
71 rm -f README.md
72 cat .readme.tmpl | go run internal/readme/readme.go > README.md
73
74.PHONY: vulncheck
75vulncheck: $(GOVULNCHECK)
76 $(GOVULNCHECK) ./...
View as plain text