@@ -36,29 +36,6 @@ GO_VERSION ?= $(shell $(GO) version)
3636GO_VERSION_NUMBER ?= $(word 3, $(GO_VERSION))
3737PRE_GO_111 ?= $(shell echo $(GO_VERSION_NUMBER) | grep -E 'go1\.(10|[0-9])\.')
3838
39- GOVENDOR :=
40- GO111MODULE :=
41- ifeq (, $(PRE_GO_111))
42- ifneq (,$(wildcard go.mod))
43- # Enforce Go modules support just in case the directory is inside GOPATH (and for Travis CI).
44- GO111MODULE := on
45-
46- ifneq (,$(wildcard vendor))
47- # Always use the local vendor/ directory to satisfy the dependencies.
48- GOOPTS := $(GOOPTS) -mod=vendor
49- endif
50- endif
51- else
52- ifneq (,$(wildcard go.mod))
53- ifneq (,$(wildcard vendor))
54- $(warning This repository requires Go >= 1.11 because of Go modules)
55- $(warning Some recipes may not work as expected as the current Go runtime is '$(GO_VERSION_NUMBER)')
56- endif
57- else
58- # This repository isn't using Go modules (yet).
59- GOVENDOR := $(FIRST_GOPATH)/bin/govendor
60- endif
61- endif
6239PROMU := $(FIRST_GOPATH)/bin/promu
6340pkgs = ./...
6441
@@ -78,17 +55,23 @@ ifneq ($(shell which gotestsum),)
7855endif
7956endif
8057
81- PROMU_VERSION ?= 0.5 .0
58+ PROMU_VERSION ?= 0.13 .0
8259PROMU_URL := https://github.com/prometheus/promu/releases/download/v$(PROMU_VERSION)/promu-$(PROMU_VERSION).$(GO_BUILD_PLATFORM).tar.gz
8360
8461GOLANGCI_LINT :=
8562GOLANGCI_LINT_OPTS ?=
86- GOLANGCI_LINT_VERSION ?= v1.18.0
63+ GOLANGCI_LINT_VERSION ?= v1.45.2
8764# golangci-lint only supports linux, darwin and windows platforms on i386/amd64.
8865# windows isn't included here because of the path separator being different.
8966ifeq ($(GOHOSTOS),$(filter $(GOHOSTOS),linux darwin))
9067 ifeq ($(GOHOSTARCH),$(filter $(GOHOSTARCH),amd64 i386))
91- GOLANGCI_LINT := $(FIRST_GOPATH)/bin/golangci-lint
68+ # If we're in CI and there is an Actions file, that means the linter
69+ # is being run in Actions, so we don't need to run it here.
70+ ifeq (,$(CIRCLE_JOB))
71+ GOLANGCI_LINT := $(FIRST_GOPATH)/bin/golangci-lint
72+ else ifeq (,$(wildcard .github/workflows/golangci-lint.yml))
73+ GOLANGCI_LINT := $(FIRST_GOPATH)/bin/golangci-lint
74+ endif
9275 endif
9376endif
9477
@@ -118,7 +101,7 @@ endif
118101%: common-% ;
119102
120103.PHONY: common-all
121- common-all: precheck style check_license lint unused build test
104+ common-all: precheck style check_license lint yamllint unused build test
122105
123106.PHONY: common-style
124107common-style:
@@ -144,87 +127,72 @@ common-check_license:
144127.PHONY: common-deps
145128common-deps:
146129 @echo ">> getting dependencies"
147- ifdef GO111MODULE
148- GO111MODULE=$(GO111MODULE) $(GO) mod download
149- else
150- $(GO) get $(GOOPTS) -t ./...
151- endif
130+ $(GO) mod download
152131
153132.PHONY: update-go-deps
154133update-go-deps:
155134 @echo ">> updating Go dependencies"
156135 @for m in $$($(GO) list -mod=readonly -m -f '{{ if and (not .Indirect) (not .Main)}}{{.Path}}{{end}}' all); do \
157- $(GO) get $$m; \
136+ $(GO) get -d $$m; \
158137 done
159- GO111MODULE=$(GO111MODULE) $(GO) mod tidy
160- ifneq (,$(wildcard vendor))
161- GO111MODULE=$(GO111MODULE) $(GO) mod vendor
162- endif
138+ $(GO) mod tidy
163139
164140.PHONY: common-test-short
165141common-test-short: $(GOTEST_DIR)
166142 @echo ">> running short tests"
167- GO111MODULE=$(GO111MODULE) $(GOTEST) -short $(GOOPTS) $(pkgs)
143+ $(GOTEST) -short $(GOOPTS) $(pkgs)
168144
169145.PHONY: common-test
170146common-test: $(GOTEST_DIR)
171147 @echo ">> running all tests"
172- GO111MODULE=$(GO111MODULE) $(GOTEST) $(test-flags) $(GOOPTS) $(pkgs)
148+ $(GOTEST) $(test-flags) $(GOOPTS) $(pkgs)
173149
174150$(GOTEST_DIR):
175151 @mkdir -p $@
176152
177153.PHONY: common-format
178154common-format:
179155 @echo ">> formatting code"
180- GO111MODULE=$(GO111MODULE) $(GO) fmt $(pkgs)
156+ $(GO) fmt $(pkgs)
181157
182158.PHONY: common-vet
183159common-vet:
184160 @echo ">> vetting code"
185- GO111MODULE=$(GO111MODULE) $(GO) vet $(GOOPTS) $(pkgs)
161+ $(GO) vet $(GOOPTS) $(pkgs)
186162
187163.PHONY: common-lint
188164common-lint: $(GOLANGCI_LINT)
189165ifdef GOLANGCI_LINT
190166 @echo ">> running golangci-lint"
191- ifdef GO111MODULE
192167# 'go list' needs to be executed before staticcheck to prepopulate the modules cache.
193168# Otherwise staticcheck might fail randomly for some reason not yet explained.
194- GO111MODULE=$(GO111MODULE) $(GO) list -e -compiled -test=true -export=false -deps=true -find=false -tags= -- ./... > /dev/null
195- GO111MODULE=$(GO111MODULE) $(GOLANGCI_LINT) run $(GOLANGCI_LINT_OPTS) $(pkgs)
196- else
197- $(GOLANGCI_LINT) run $(pkgs)
169+ $(GO) list -e -compiled -test=true -export=false -deps=true -find=false -tags= -- ./... > /dev/null
170+ $(GOLANGCI_LINT) run $(GOLANGCI_LINT_OPTS) $(pkgs)
198171endif
172+
173+ .PHONY: common-yamllint
174+ common-yamllint:
175+ @echo ">> running yamllint on all YAML files in the repository"
176+ ifeq (, $(shell which yamllint))
177+ @echo "yamllint not installed so skipping"
178+ else
179+ yamllint .
199180endif
200181
201182# For backward-compatibility.
202183.PHONY: common-staticcheck
203184common-staticcheck: lint
204185
205186.PHONY: common-unused
206- common-unused: $(GOVENDOR)
207- ifdef GOVENDOR
208- @echo ">> running check for unused packages"
209- @$(GOVENDOR) list +unused | grep . && exit 1 || echo 'No unused packages'
210- else
211- ifdef GO111MODULE
187+ common-unused:
212188 @echo ">> running check for unused/missing packages in go.mod"
213- GO111MODULE=$(GO111MODULE) $(GO) mod tidy
214- ifeq (,$(wildcard vendor))
189+ $(GO) mod tidy
215190 @git diff --exit-code -- go.sum go.mod
216- else
217- @echo ">> running check for unused packages in vendor/"
218- GO111MODULE=$(GO111MODULE) $(GO) mod vendor
219- @git diff --exit-code -- go.sum go.mod vendor/
220- endif
221- endif
222- endif
223191
224192.PHONY: common-build
225193common-build: promu
226194 @echo ">> building binaries"
227- GO111MODULE=$(GO111MODULE) $(PROMU) build --prefix $(PREFIX) $(PROMU_BINARIES)
195+ $(PROMU) build --prefix $(PREFIX) $(PROMU_BINARIES)
228196
229197.PHONY: common-tarball
230198common-tarball: promu
@@ -245,10 +213,12 @@ common-docker-publish: $(PUBLISH_DOCKER_ARCHS)
245213$(PUBLISH_DOCKER_ARCHS): common-docker-publish-%:
246214 docker push "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:$(DOCKER_IMAGE_TAG)"
247215
216+ DOCKER_MAJOR_VERSION_TAG = $(firstword $(subst ., ,$(shell cat VERSION)))
248217.PHONY: common-docker-tag-latest $(TAG_DOCKER_ARCHS)
249218common-docker-tag-latest: $(TAG_DOCKER_ARCHS)
250219$(TAG_DOCKER_ARCHS): common-docker-tag-latest-%:
251220 docker tag "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:$(DOCKER_IMAGE_TAG)" "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:latest"
221+ docker tag "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:$(DOCKER_IMAGE_TAG)" "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:v$(DOCKER_MAJOR_VERSION_TAG)"
252222
253223.PHONY: common-docker-manifest
254224common-docker-manifest:
@@ -278,12 +248,6 @@ $(GOLANGCI_LINT):
278248 | sh -s -- -b $(FIRST_GOPATH)/bin $(GOLANGCI_LINT_VERSION)
279249endif
280250
281- ifdef GOVENDOR
282- .PHONY: $(GOVENDOR)
283- $(GOVENDOR):
284- GOOS= GOARCH= $(GO) get -u github.com/kardianos/govendor
285- endif
286-
287251.PHONY: precheck
288252precheck::
289253
0 commit comments