1-
2- TOOLS_MOD_DIR := ./internal/tools
3- ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST ) ) ) )
4-
5- ALL_GO_MOD_DIRS := $(shell find . -type f -name 'main.go' -exec dirname {} \; | sort)
6- ROOT_GO_MOD_DIRS := $(filter-out $(TOOLS_MOD_DIR ) , $(ALL_GO_MOD_DIRS ) )
7- ALL_COVERAGE_MOD_DIRS := $(shell find . -type f -name 'go.mod' -exec dirname {} \; | grep -E -v '^./example|^$(TOOLS_MOD_DIR ) ' | sort)
8-
9- GO = go
10- TIMEOUT = 60
11-
12- # Tools
13-
14- TOOLS = $(CURDIR ) /.tools
15-
16- $(TOOLS ) :
17- @mkdir -p $@
18- $(TOOLS ) /% : $(TOOLS_MOD_DIR ) /go.mod | $(TOOLS )
19- cd $(TOOLS_MOD_DIR ) && \
20- $(GO ) build -o $@ $(PACKAGE )
21-
22-
23- GOLANGCI_LINT = $(TOOLS ) /golangci-lint
24- $(TOOLS ) /golangci-lint : PACKAGE=github.com/golangci/golangci-lint/v2/cmd/golangci-lint
25-
26- GORELEASE = $(TOOLS ) /gorelease
27- $(GORELEASE ) : PACKAGE=golang.org/x/exp/cmd/gorelease
28-
29- GOCOVMERGE = $(TOOLS ) /gocovmerge
30- $(TOOLS ) /gocovmerge : PACKAGE=github.com/wadey/gocovmerge
31-
32- MULTIMOD = $(TOOLS ) /multimod
33- $(TOOLS ) /multimod : PACKAGE=go.opentelemetry.io/build-tools/multimod
34-
35- .PHONY : tools
36- tools : $(GOLANGCI_LINT ) $(GORELEASE ) $(GOCOVMERGE ) $(MULTIMOD )
37-
38-
39- # Build
40-
41- .PHONY : build
42-
43- build : $(ROOT_GO_MOD_DIRS:%=build/% )
44- build/% : DIR=$*
45- build/% :
46- @echo " $( GO) build $( DIR) /..." \
47- && cd $(DIR ) \
48- && $(GO ) build -o $(ROOT_DIR ) /bin/ ./...
49-
50- # Tests
51-
52- TEST_TARGETS := test-default test-short test-verbose test-race test-concurrent-safe
53- .PHONY : $(TEST_TARGETS ) test
54- test-default test-race : ARGS=-race
55- test-short : ARGS=-short
56- test-verbose : ARGS=-v -race
57- test-concurrent-safe : ARGS=-run=ConcurrentSafe -count=100 -race
58- test-concurrent-safe : TIMEOUT=120
59- $(TEST_TARGETS ) : test
60- test : $(ROOT_GO_MOD_DIRS:%=test/% )
61- test/% : DIR=$*
62- test/% :
63- @echo " $( GO) test -timeout $( TIMEOUT) s $( ARGS) $( DIR) /..." \
64- && cd $(DIR ) \
65- && $(GO ) list ./... \
66- | xargs $(GO ) test -timeout $(TIMEOUT ) s $(ARGS )
67-
68-
69- COVERAGE_MODE = atomic
70- COVERAGE_PROFILE = coverage.out
71- .PHONY : test-coverage
72- test-coverage : $(GOCOVMERGE )
73- @set -e; \
74- printf " " > coverage.txt; \
75- for dir in $( ALL_COVERAGE_MOD_DIRS) ; do \
76- echo " $( GO) test -v -race -coverpkg=github.com/go-tapd/tapd/... -covermode=$( COVERAGE_MODE) -coverprofile=" $(COVERAGE_PROFILE ) " $$ {dir}/..." ; \
77- (cd " $$ {dir}" && \
78- $(GO ) list ./... \
79- | xargs $(GO ) test -coverpkg=./... -covermode=$(COVERAGE_MODE ) -coverprofile=" $( COVERAGE_PROFILE) " && \
80- $(GO ) tool cover -html=coverage.out -o coverage.html); \
81- done ; \
82- $(GOCOVMERGE ) $$(find . -name coverage.out ) > coverage.txt
83-
84- .PHONY : golangci-lint golangci-lint-fix
85- golangci-lint-fix : ARGS=--fix
86- golangci-lint-fix : golangci-lint
87- golangci-lint : $(ROOT_GO_MOD_DIRS:%=golangci-lint/% )
88- golangci-lint/% : DIR=$*
89- golangci-lint/% : $(GOLANGCI_LINT )
90- @echo ' golangci-lint $(if $(ARGS),$(ARGS) ,)$(DIR)' \
91- && cd $(DIR ) \
92- && $(GOLANGCI_LINT ) run --allow-serial-runners $(ARGS )
93-
94- .PHONY : go-mod-tidy
95- go-mod-tidy : $(ALL_GO_MOD_DIRS:%=go-mod-tidy/% )
96- go-mod-tidy/% : DIR=$*
97- go-mod-tidy/% :
98- @echo " $( GO) mod tidy in $( DIR) " \
99- && cd $(DIR ) \
100- && $(GO ) mod tidy -compat=1.22.0
101-
102- .PHONY : lint-modules
103- lint-modules : go-mod-tidy
1+ .PHONY : init
2+ init :
3+ go install mvdan.cc/gofumpt@latest
4+ go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest
1045
1056.PHONY : lint
106- lint : lint-modules golangci-lint
107-
108- .PHONY : check-clean-work-tree
109- check-clean-work-tree :
110- @if ! git diff --quiet; then \
111- echo ; \
112- echo ' Working tree is not clean, did you forget to run "make precommit"?' ; \
113- echo ; \
114- git status; \
115- exit 1; \
116- fi
117-
118- .PHONY : gorelease
119- gorelease : $(ROOT_GO_MOD_DIRS:%=gorelease/% )
120- gorelease/% : DIR=$*
121- gorelease/% :| $(GORELEASE )
122- @echo " gorelease in $( DIR) :" \
123- && cd $(DIR ) \
124- && $(GORELEASE ) \
125- || echo " "
126-
127- .PHONY : verify-mods
128- verify-mods : $(MULTIMOD )
129- $(MULTIMOD ) verify
130-
131- .PHONY : prerelease
132- prerelease : verify-mods
133- @[ " ${MODSET} " ] || ( echo " >> env var MODSET is not set" ; exit 1 )
134- $(MULTIMOD ) prerelease -m ${MODSET}
135-
136- COMMIT ?= "HEAD"
137- .PHONY : add-tags
138- add-tags : verify-mods
139- @[ " ${MODSET} " ] || ( echo " >> env var MODSET is not set" ; exit 1 )
140- $(MULTIMOD ) tag -m ${MODSET} -c ${COMMIT}
7+ lint :
8+ golangci-lint run
9+ @echo " ✅ Linting completed"
10+
11+ .PHONY : fix
12+ fix :
13+ golangci-lint run --fix
14+ @echo " ✅ Lint fixing completed"
15+
16+ .PHONY : test
17+ test :
18+ go test ./... -race
19+ @echo " ✅ Testing completed"
20+
21+ .PHONY : fmt
22+ fmt :
23+ gofmt -w -e " vendor" .
24+ @echo " ✅ Formatting completed"
25+
26+ .PHONY : fumpt
27+ fumpt :
28+ gofumpt -w -e " vendor" .
29+ @echo " ✅ Formatting completed"
30+
31+ .PHONY : nilaway-install
32+ nilaway-install :
33+ go install go.uber.org/nilaway/cmd/nilaway@latest
34+
35+ .PHONY : nilaway
36+ nilaway :
37+ nilaway ./...
38+ @echo " ✅ Nilaway completed"
0 commit comments