| Abhay Kumar | a61c522 | 2025-11-10 07:32:50 +0000 | [diff] [blame] | 1 | # Directory containing the Makefile. |
| 2 | PROJECT_ROOT = $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) |
| William Kurkian | ea86948 | 2019-04-09 15:16:11 -0400 | [diff] [blame] | 3 | |
| Abhay Kumar | a61c522 | 2025-11-10 07:32:50 +0000 | [diff] [blame] | 4 | export GOBIN ?= $(PROJECT_ROOT)/bin |
| 5 | export PATH := $(GOBIN):$(PATH) |
| 6 | |
| 7 | GOVULNCHECK = $(GOBIN)/govulncheck |
| William Kurkian | ea86948 | 2019-04-09 15:16:11 -0400 | [diff] [blame] | 8 | BENCH_FLAGS ?= -cpuprofile=cpu.pprof -memprofile=mem.pprof -benchmem |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 9 | |
| 10 | # Directories containing independent Go modules. |
| Abhay Kumar | a61c522 | 2025-11-10 07:32:50 +0000 | [diff] [blame] | 11 | MODULE_DIRS = . ./exp ./benchmarks ./zapgrpc/internal/test |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 12 | |
| Abhay Kumar | a61c522 | 2025-11-10 07:32:50 +0000 | [diff] [blame] | 13 | # Directories that we want to track coverage for. |
| 14 | COVER_DIRS = . ./exp |
| William Kurkian | ea86948 | 2019-04-09 15:16:11 -0400 | [diff] [blame] | 15 | |
| 16 | .PHONY: all |
| 17 | all: lint test |
| 18 | |
| William Kurkian | ea86948 | 2019-04-09 15:16:11 -0400 | [diff] [blame] | 19 | .PHONY: lint |
| Abhay Kumar | a61c522 | 2025-11-10 07:32:50 +0000 | [diff] [blame] | 20 | lint: golangci-lint tidy-lint license-lint |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 21 | |
| Abhay Kumar | a61c522 | 2025-11-10 07:32:50 +0000 | [diff] [blame] | 22 | .PHONY: golangci-lint |
| 23 | golangci-lint: |
| 24 | @$(foreach mod,$(MODULE_DIRS), \ |
| 25 | (cd $(mod) && \ |
| 26 | echo "[lint] golangci-lint: $(mod)" && \ |
| 27 | golangci-lint run --path-prefix $(mod)) &&) true |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 28 | |
| Abhay Kumar | a61c522 | 2025-11-10 07:32:50 +0000 | [diff] [blame] | 29 | .PHONY: tidy |
| 30 | tidy: |
| 31 | @$(foreach dir,$(MODULE_DIRS), \ |
| 32 | (cd $(dir) && go mod tidy) &&) true |
| 33 | |
| 34 | .PHONY: tidy-lint |
| 35 | tidy-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 |
| 44 | license-lint: |
| 45 | ./checklicense.sh |
| 46 | |
| 47 | $(GOVULNCHECK): |
| 48 | cd tools && go install golang.org/x/vuln/cmd/govulncheck |
| William Kurkian | ea86948 | 2019-04-09 15:16:11 -0400 | [diff] [blame] | 49 | |
| 50 | .PHONY: test |
| 51 | test: |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 52 | @$(foreach dir,$(MODULE_DIRS),(cd $(dir) && go test -race ./...) &&) true |
| William Kurkian | ea86948 | 2019-04-09 15:16:11 -0400 | [diff] [blame] | 53 | |
| 54 | .PHONY: cover |
| 55 | cover: |
| Abhay Kumar | a61c522 | 2025-11-10 07:32:50 +0000 | [diff] [blame] | 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 |
| William Kurkian | ea86948 | 2019-04-09 15:16:11 -0400 | [diff] [blame] | 60 | |
| 61 | .PHONY: bench |
| 62 | BENCH ?= . |
| 63 | bench: |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 64 | @$(foreach dir,$(MODULE_DIRS), ( \ |
| 65 | cd $(dir) && \ |
| 66 | go list ./... | xargs -n1 go test -bench=$(BENCH) -run="^$$" $(BENCH_FLAGS) \ |
| 67 | ) &&) true |
| William Kurkian | ea86948 | 2019-04-09 15:16:11 -0400 | [diff] [blame] | 68 | |
| 69 | .PHONY: updatereadme |
| 70 | updatereadme: |
| 71 | rm -f README.md |
| 72 | cat .readme.tmpl | go run internal/readme/readme.go > README.md |
| khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 73 | |
| Abhay Kumar | a61c522 | 2025-11-10 07:32:50 +0000 | [diff] [blame] | 74 | .PHONY: vulncheck |
| 75 | vulncheck: $(GOVULNCHECK) |
| 76 | $(GOVULNCHECK) ./... |