-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathgo.mk
221 lines (176 loc) · 4.79 KB
/
go.mk
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# Managed by makego. DO NOT EDIT.
# Must be set
$(call _assert_var,MAKEGO)
$(call _conditional_include,$(MAKEGO)/base.mk)
$(call _conditional_include,$(MAKEGO)/dep_golangci_lint.mk)
$(call _conditional_include,$(MAKEGO)/dep_yq.mk)
# Must be set
$(call _assert_var,GO_MODULE)
$(call _assert_var,GOLANGCI_LINT)
$(call _assert_var,TMP)
$(call _assert_var,OPEN_CMD)
# Settable
GO_BINS ?=
# Settable
GO_TEST_BINS ?=
# Settable
GO_TEST_WASM_BINS ?=
# Settable
GO_GET_PKGS ?=
# Settable
GO_MOD_VERSION ?= 1.22
# Settable
GO_MOD_TOOLCHAIN ?= 1.23.5
# Settable
GO_ALL_REPO_PKGS ?= ./cmd/... ./internal/...
# Settable
SKIP_GOLANGCI_LINT ?=
# Settable
DISALLOW_NOLINT ?=
# Runtime
GOPKGS ?= $(GO_ALL_REPO_PKGS)
# Runtime
GOLANGCILINTTIMEOUT ?= 3m0s
# Runtime GONOTESTCACHE
# Runtime COVEROPEN
COVER_HTML := $(TMP)/cover.html
COVER_TXT := $(TMP)/cover.txt
ifdef GONOTESTCACHE
GO_TEST_FLAGS := -count=1
else
GO_TEST_FLAGS :=
endif
.DEFAULT_GOAL := shortall
.PHONY: all
all: ## Run make lint and make test.
@$(MAKE) lint
@$(MAKE) test
postupgrade:: all
.PHONY: shortall
shortall: ## Run make shortlint and make shorttest.
@$(MAKE) shortlint
@$(MAKE) shorttest
.PHONY: ci
ci:
@$(MAKE) lint
@$(MAKE) test
.PHONY: postupgradegodeps
postupgradegodeps::
.PHONY: upgradegodeps
upgradegodeps:
rm -f go.mod go.sum
go mod init $(GO_MODULE)
go mod edit -go=$(GO_MOD_VERSION)
go mod edit -toolchain=go$(GO_MOD_TOOLCHAIN)
ifneq ($(GO_GET_PKGS),)
go get $(GO_GET_PKGS)
endif
go get -u -t $(GO_ALL_REPO_PKGS) $(GO_GET_PKGS)
go mod tidy -v
@$(MAKE) postupgradegodeps
preupgrade:: upgradegodeps
initmakego:: upgradegodeps
.PHONY: godeps
godeps: deps
go mod download
.PHONY: gofmtmodtidy
gofmtmodtidy:
@echo gofmt -s -w ALL_GO_FILES
@gofmt -s -w .
go mod tidy -v
format:: gofmtmodtidy
.PHONY: checknolintlint
checknolintlint: $(YQ)
ifneq ($(DISALLOW_NOLINT),)
@if grep -r --include "*.go" '//nolint'; then \
echo '//nolint directives found, surface ignores in .golangci.yml instead' >&2; \
exit 1; \
fi
else
bash $(MAKEGO)/scripts/checknolintlint.bash
endif
.PHONY: golangcilint
golangcilint: $(GOLANGCI_LINT)
ifneq ($(SKIP_GOLANGCI_LINT),)
@echo Skipping golangci-lint...
else
golangci-lint run --timeout $(GOLANGCILINTTIMEOUT)
endif
.PHONY: postlint
postlint::
.PHONY: postlonglint
postlonglint::
.PHONY: shortlint
shortlint: ## Run all linters but exclude long-running linters.
@$(MAKE) checknodiffgenerated
@$(MAKE) checknolintlint golangcilint postlint
.PHONY: lint
lint: ## Run all linters.
@$(MAKE) shortlint
@$(MAKE) postlonglint
.PHONY: prebuild
prebuild::
.PHONY: build
build: prebuild ## Run go build.
go build ./...
.PHONY: pretest
pretest::
.PHONY: test
test: pretest installtest installtestwasm ## Run all go tests.
go test $(GO_TEST_FLAGS) $(GOPKGS)
.PHONY: testrace
testrace: pretest installtest
go test -race $(GO_TEST_FLAGS) $(GOPKGS)
.PHONY: shorttest
shorttest: pretest installtest ## Run all go tests but exclude long-running tests.
go test -test.short $(GO_TEST_FLAGS) $(GOPKGS)
.PHONY: deppkgs
deppkgs:
@go list -f '{{join .Deps "\n"}}' $(GOPKGS) | xargs go list -f '{{if not .Standard}}{{.ImportPath}}{{end}}'
.PHONY: coverpkgs
coverpkgs:
@go list $(GOPKGS) | grep -v \/gen\/ | tr '\n' ',' | sed "s/,$$//"
.PHONY: cover
cover: pretest installtest
@mkdir -p $(dir $(COVER_HTML)) $(dir $(COVER_TXT))
@rm -f $(COVER_HTML) $(COVER_TXT)
go test -race -coverprofile=$(COVER_TXT) -coverpkg=$(shell GOPKGS=$(GOPKGS) $(MAKE) -s coverpkgs) $(GOPKGS)
@go tool cover -html=$(COVER_TXT) -o $(COVER_HTML)
@echo
@go tool cover -func=$(COVER_TXT) | grep total
@echo
ifndef COVEROPEN
@echo $(OPEN_CMD) $(COVER_HTML)
else
$(OPEN_CMD) $(COVER_HTML)
endif
.PHONY: install
install:: ## Install all go binaries.
define gobinfunc
.PHONY: install$(notdir $(1))
install$(notdir $(1)):
go install ./$(1)
install:: install$(notdir $(1))
endef
$(foreach gobin,$(sort $(GO_BINS)),$(eval $(call gobinfunc,$(gobin))))
$(foreach gobin,$(sort $(GO_BINS)),$(eval FILE_IGNORES := $(FILE_IGNORES) $(gobin)/$(notdir $(gobin))))
.PHONY: installtest
installtest::
define gotestbinfunc
.PHONY: installtest$(notdir $(1))
installtest$(notdir $(1)):
go install ./$(1)
installtest:: installtest$(notdir $(1))
endef
$(foreach gobin,$(sort $(GO_TEST_BINS)),$(eval $(call gotestbinfunc,$(gobin))))
$(foreach gobin,$(sort $(GO_TEST_BINS)),$(eval FILE_IGNORES := $(FILE_IGNORES) $(gobin)/$(notdir $(gobin))))
.PHONY: installtestwasm
installtestwasm::
define gotestwasmfunc
.PHONY: installtestwasm$(notdir $(1))
installtestwasm$(notdir $(1)):
GOOS=wasip1 GOARCH=wasm go build -o $(GOBIN)/$(notdir $(1)).wasm ./$(1)
installtestwasm:: installtestwasm$(notdir $(1))
endef
$(foreach gobin,$(sort $(GO_TEST_WASM_BINS)),$(eval $(call gotestwasmfunc,$(gobin))))
$(foreach gobin,$(sort $(GO_TEST_WASM_BINS)),$(eval FILE_IGNORES := $(FILE_IGNORES) $(gobin)/$(notdir $(gobin))))