|
26 | 26 | GOBIN=$(shell go env GOBIN)
|
27 | 27 | endif
|
28 | 28 |
|
| 29 | +## Location to install dependencies to |
| 30 | +LOCALBIN ?= $(shell pwd)/bin |
| 31 | +$(LOCALBIN): |
| 32 | + mkdir -p $(LOCALBIN) |
| 33 | + |
29 | 34 | ##@ General
|
30 | 35 |
|
31 | 36 | # The help target prints out all targets with their descriptions organized
|
@@ -124,19 +129,17 @@ yamllint:
|
124 | 129 | @files=$$(find testdata -name '*.yaml' ! -path 'testdata/*/dist/*'); \
|
125 | 130 | docker run --rm $$(tty -s && echo "-it" || echo) -v $(PWD):/data cytopia/yamllint:latest $$files -d "{extends: relaxed, rules: {line-length: {max: 120}}}" --no-warnings
|
126 | 131 |
|
127 |
| -GOLANGCI_LINT = $(shell pwd)/bin/golangci-lint |
| 132 | +.PHONY: golangci-lint |
128 | 133 | golangci-lint:
|
129 |
| - @[ -f $(GOLANGCI_LINT) ] || { \ |
130 |
| - GOBIN= $(shell pwd)/bin go install github.com/golangci/golangci-lint/v2/cmd/ [email protected] ;\ |
131 |
| - } |
| 134 | + $(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,${GOLANGCI_LINT_VERSION}) |
132 | 135 |
|
133 | 136 | .PHONY: apidiff
|
134 | 137 | apidiff: go-apidiff ## Run the go-apidiff to verify any API differences compared with origin/master
|
135 |
| - $(GOBIN)/go-apidiff master --compare-imports --print-compatible --repo-path=. |
| 138 | + $(GO_APIDIFF) master --compare-imports --print-compatible --repo-path=. |
136 | 139 |
|
137 | 140 | .PHONY: go-apidiff
|
138 | 141 | go-apidiff:
|
139 |
| - go install github.com/joelanford/go-apidiff@v0.6.1 |
| 142 | + $(call go-install-tool,$(GO_APIDIFF),github.com/joelanford/go-apidiff,$(GO_APIDIFF_VERSION)) |
140 | 143 |
|
141 | 144 | ##@ Tests
|
142 | 145 |
|
@@ -219,3 +222,27 @@ update-k8s-version: ## Update Kubernetes API version in version.go and .goreleas
|
219 | 222 | @sed -i.bak 's/KUBERNETES_VERSION=.*/KUBERNETES_VERSION=$(K8S_VERSION)/' build/.goreleaser.yml
|
220 | 223 | @# Clean up backup files
|
221 | 224 | @find . -name "*.bak" -type f -delete
|
| 225 | + |
| 226 | +## Tool Binaries |
| 227 | +GO_APIDIFF ?= $(LOCALBIN)/go-apidiff |
| 228 | +GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint |
| 229 | + |
| 230 | +## Tool Versions |
| 231 | +GO_APIDIFF_VERSION ?= v0.6.1 |
| 232 | +GOLANGCI_LINT_VERSION ?= v2.3.0 |
| 233 | + |
| 234 | +# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist |
| 235 | +# $1 - target path with name of binary |
| 236 | +# $2 - package url which can be installed |
| 237 | +# $3 - specific version of package |
| 238 | +define go-install-tool |
| 239 | +@[ -f "$(1)-$(3)" ] || { \ |
| 240 | +set -e; \ |
| 241 | +package=$(2)@$(3) ;\ |
| 242 | +echo "Downloading $${package}" ;\ |
| 243 | +rm -f $(1) || true ;\ |
| 244 | +GOBIN=$(LOCALBIN) go install $${package} ;\ |
| 245 | +mv $(1) $(1)-$(3) ;\ |
| 246 | +} ;\ |
| 247 | +ln -sf $(1)-$(3) $(1) |
| 248 | +endef |
0 commit comments