sigs.k8s.io/controller-runtime@v0.18.2/Makefile (about) 1 #!/usr/bin/env bash 2 3 # Copyright 2020 The Kubernetes Authors. 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 17 # If you update this file, please follow 18 # https://suva.sh/posts/well-documented-makefiles 19 20 ## -------------------------------------- 21 ## General 22 ## -------------------------------------- 23 24 SHELL:=/usr/bin/env bash 25 .DEFAULT_GOAL:=help 26 27 # Use GOPROXY environment variable if set 28 GOPROXY := $(shell go env GOPROXY) 29 ifeq ($(GOPROXY),) 30 GOPROXY := https://proxy.golang.org 31 endif 32 export GOPROXY 33 34 # Active module mode, as we use go modules to manage dependencies 35 export GO111MODULE=on 36 37 # Tools. 38 TOOLS_DIR := hack/tools 39 TOOLS_BIN_DIR := $(abspath $(TOOLS_DIR)/bin) 40 GOLANGCI_LINT := $(abspath $(TOOLS_BIN_DIR)/golangci-lint) 41 GO_APIDIFF := $(TOOLS_BIN_DIR)/go-apidiff 42 CONTROLLER_GEN := $(TOOLS_BIN_DIR)/controller-gen 43 ENVTEST_DIR := $(abspath tools/setup-envtest) 44 SCRATCH_ENV_DIR := $(abspath examples/scratch-env) 45 GO_INSTALL := ./hack/go-install.sh 46 47 # The help will print out all targets with their descriptions organized bellow their categories. The categories are represented by `##@` and the target descriptions by `##`. 48 # 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. 49 # More info over the usage of ANSI control characters for terminal formatting: https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters 50 # More info over awk command: http://linuxcommand.org/lc3_adv_awk.php 51 .PHONY: help 52 help: ## Display this help 53 @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) 54 55 ## -------------------------------------- 56 ## Testing 57 ## -------------------------------------- 58 59 .PHONY: test 60 test: test-tools ## Run the script check-everything.sh which will check all. 61 TRACE=1 ./hack/check-everything.sh 62 63 .PHONY: test-tools 64 test-tools: ## tests the tools codebase (setup-envtest) 65 cd tools/setup-envtest && go test ./... 66 67 ## -------------------------------------- 68 ## Binaries 69 ## -------------------------------------- 70 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 75 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) 78 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) 94 95 ## -------------------------------------- 96 ## Linting 97 ## -------------------------------------- 98 99 .PHONY: lint 100 lint: $(GOLANGCI_LINT) ## Lint codebase 101 $(GOLANGCI_LINT) run -v $(GOLANGCI_LINT_EXTRA_ARGS) 102 cd tools/setup-envtest; $(GOLANGCI_LINT) run -v $(GOLANGCI_LINT_EXTRA_ARGS) 103 104 .PHONY: lint-fix 105 lint-fix: $(GOLANGCI_LINT) ## Lint the codebase and run auto-fixers if supported by the linter. 106 GOLANGCI_LINT_EXTRA_ARGS=--fix $(MAKE) lint 107 108 ## -------------------------------------- 109 ## Generate 110 ## -------------------------------------- 111 112 .PHONY: modules 113 modules: ## Runs go mod to ensure modules are up to date. 114 go mod tidy 115 cd $(TOOLS_DIR); go mod tidy 116 cd $(ENVTEST_DIR); go mod tidy 117 cd $(SCRATCH_ENV_DIR); go mod tidy 118 119 ## -------------------------------------- 120 ## Cleanup / Verification 121 ## -------------------------------------- 122 123 .PHONY: clean 124 clean: ## Cleanup. 125 $(GOLANGCI_LINT) cache clean 126 $(MAKE) clean-bin 127 128 .PHONY: clean-bin 129 clean-bin: ## Remove all generated binaries. 130 rm -rf hack/tools/bin 131 132 .PHONY: verify-modules 133 verify-modules: modules ## Verify go modules are up to date 134 @if !(git diff --quiet HEAD -- go.sum go.mod $(TOOLS_DIR)/go.mod $(TOOLS_DIR)/go.sum $(ENVTEST_DIR)/go.mod $(ENVTEST_DIR)/go.sum $(SCRATCH_ENV_DIR)/go.sum); then \ 135 git diff; \ 136 echo "go module files are out of date, please run 'make modules'"; exit 1; \ 137 fi 138 139 APIDIFF_OLD_COMMIT ?= $(shell git rev-parse origin/main) 140 141 .PHONY: apidiff 142 verify-apidiff: $(GO_APIDIFF) ## Check for API differences 143 $(GO_APIDIFF) $(APIDIFF_OLD_COMMIT) --print-compatible 144 145