@@ -36,12 +36,13 @@ export GO111MODULE=on
3636
3737# Tools.
3838TOOLS_DIR := hack/tools
39- TOOLS_BIN_DIR := $(TOOLS_DIR ) /bin
39+ TOOLS_BIN_DIR := $(abspath $( TOOLS_DIR ) /bin)
4040GOLANGCI_LINT := $(abspath $(TOOLS_BIN_DIR ) /golangci-lint)
4141GO_APIDIFF := $(TOOLS_BIN_DIR ) /go-apidiff
4242CONTROLLER_GEN := $(TOOLS_BIN_DIR ) /controller-gen
4343ENVTEST_DIR := $(abspath tools/setup-envtest)
4444SCRATCH_ENV_DIR := $(abspath examples/scratch-env)
45+ GO_INSTALL := ./hack/go-install.sh
4546
4647# The help will print out all targets with their descriptions organized bellow their categories. The categories are represented by `##@` and the target descriptions by `##`.
4748# The awk commands is responsible to read the entire set of makefiles included in this invocation, looking for lines of the file as xyz: ## something, and then pretty-format the target and help. Then, if there's a line with ##@ something, that gets pretty-printed as a category.
@@ -67,16 +68,29 @@ test-tools: ## tests the tools codebase (setup-envtest)
6768# # Binaries
6869# # --------------------------------------
6970
70- $(GO_APIDIFF ) : $(TOOLS_DIR ) /go.mod # Build go-apidiff from tools folder.
71- cd $(TOOLS_DIR ) && go build -tags=tools -o bin/go-apidiff github.com/joelanford/go-apidiff
71+ GO_APIDIFF_VER := v0.8.2
72+ GO_APIDIFF_BIN := go-apidiff
73+ GO_APIDIFF := $(abspath $(TOOLS_BIN_DIR ) /$(GO_APIDIFF_BIN ) -$(GO_APIDIFF_VER ) )
74+ GO_APIDIFF_PKG := github.com/joelanford/go-apidiff
7275
73- $(CONTROLLER_GEN ) : $( TOOLS_DIR ) /go.mod # Build controller-gen from tools folder.
74- cd $(TOOLS_DIR ) && go build -tags=tools -o bin/controller-gen sigs.k8s.io/controller-tools/cmd/controller-gen
76+ $(GO_APIDIFF ) : # Build go-apidiff from tools folder.
77+ GOBIN= $( TOOLS_BIN_DIR ) $(GO_INSTALL ) $( GO_APIDIFF_PKG ) $( GO_APIDIFF_BIN ) $( GO_APIDIFF_VER )
7578
76- $(GOLANGCI_LINT ) : .github/workflows/golangci-lint.yml # Download golanci-lint using hack script into tools folder.
77- hack/ensure-golangci-lint.sh \
78- -b $(TOOLS_BIN_DIR ) \
79- $(shell cat .github/workflows/golangci-lint.yml | grep "version: v" | sed 's/.* version: //')
79+ CONTROLLER_GEN_VER := v0.14.0
80+ CONTROLLER_GEN_BIN := controller-gen
81+ CONTROLLER_GEN := $(abspath $(TOOLS_BIN_DIR ) /$(CONTROLLER_GEN_BIN ) -$(CONTROLLER_GEN_VER ) )
82+ CONTROLLER_GEN_PKG := sigs.k8s.io/controller-tools/cmd/controller-gen
83+
84+ $(CONTROLLER_GEN ) : # Build controller-gen from tools folder.
85+ GOBIN=$(TOOLS_BIN_DIR ) $(GO_INSTALL ) $(CONTROLLER_GEN_PKG ) $(CONTROLLER_GEN_BIN ) $(CONTROLLER_GEN_VER )
86+
87+ GOLANGCI_LINT_BIN := golangci-lint
88+ GOLANGCI_LINT_VER := $(shell cat .github/workflows/golangci-lint.yml | grep [[:space:]]version: | sed 's/.* version: //')
89+ GOLANGCI_LINT := $(abspath $(TOOLS_BIN_DIR ) /$(GOLANGCI_LINT_BIN ) -$(GOLANGCI_LINT_VER ) )
90+ GOLANGCI_LINT_PKG := github.com/golangci/golangci-lint/cmd/golangci-lint
91+
92+ $(GOLANGCI_LINT ) : # Build golangci-lint from tools folder.
93+ GOBIN=$(TOOLS_BIN_DIR ) $(GO_INSTALL ) $(GOLANGCI_LINT_PKG ) $(GOLANGCI_LINT_BIN ) $(GOLANGCI_LINT_VER )
8094
8195# # --------------------------------------
8296# # Linting
@@ -126,6 +140,12 @@ verify-modules: modules ## Verify go modules are up to date
126140echo " go module files are out of date, please run 'make modules'" ; exit 1; \
127141fi
128142
143+ APIDIFF_OLD_COMMIT ?= $(shell git rev-parse origin/main)
144+
145+ .PHONY : apidiff
146+ verify-apidiff : $(GO_APIDIFF ) # # Check for API differences
147+ $(GO_APIDIFF ) $(APIDIFF_OLD_COMMIT ) --print-compatible
148+
129149.PHONY : verify-generate
130150verify-generate : generate # # Verify generated files are up to date
131151@if ! (git diff --quiet HEAD); then \
0 commit comments