-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
131 lines (103 loc) · 3.62 KB
/
Makefile
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
# If you update this file, please follow
# https://suva.sh/posts/well-documented-makefiles
# Ensure Make is run with bash shell as some syntax below is bash-specific
SHELL := /usr/bin/env bash
.DEFAULT_GOAL := help
# Active module mode, as we use go modules to manage dependencies
export GO111MODULE := on
# Directories
BIN_DIR := bin
SAMPLES_DIR := hack/samples
SAMPLES_BIN_DIR := $(SAMPLES_DIR)/bin
TOOLS_DIR := hack/tools
TOOLS_BIN_DIR := $(TOOLS_DIR)/bin
export PATH := $(abspath $(BIN_DIR)):$(abspath $(TOOLS_BIN_DIR)):$(abspath $SAMPLES_BIN_DIR)):$(PATH)
# Tooling binaries
CONTROLLER_GEN := $(TOOLS_BIN_DIR)/controller-gen
GOLANGCI_LINT := $(TOOLS_BIN_DIR)/golangci-lint
SETUP_ENVTEST := $(TOOLS_BIN_DIR)/setup-envtest
# Allow overriding manifest generation destination directory
MANIFEST_ROOT ?= config
CRD_ROOT ?= $(MANIFEST_ROOT)/crd/bases
.PHONY: all
all: lint tools generate ## Runs tests and generates all components
## --------------------------------------
##@ Help
## --------------------------------------
help: ## Display this help
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-18s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
## --------------------------------------
##@ Tooling
## --------------------------------------
TOOLING_BINARIES := $(CONTROLLER_GEN) $(GOLANGCI_LINT) $(SETUP_ENVTEST)
tools: $(TOOLING_BINARIES) ## Build tooling binaries
.PHONY: $(TOOLING_BINARIES)
$(TOOLING_BINARIES):
make -C $(TOOLS_DIR) $(@F)
## --------------------------------------
##@ Generate
## --------------------------------------
.PHONY: modules
modules: ## Validates the modules
go mod tidy
.PHONY: modules-download
modules-download: ## Downloads and caches the modules
go mod download
.PHONY: generate
generate: ## Run all code generation targets
$(MAKE) generate-go
$(MAKE) generate-manifests
.PHONY: generate-go
generate-go: $(CONTROLLER_GEN) ## Runs Go related generate targets
$(CONTROLLER_GEN) \
paths=./api/... \
object:headerFile="$(abspath hack/boilerplate/boilerplate.go.txt)"
ifneq (0,$(GENERATE_CODE))
go generate ./...
endif
.PHONY: generate-manifests
generate-manifests: $(CONTROLLER_GEN) ## Generate manifests e.g. CRD, RBAC etc.
$(CONTROLLER_GEN) \
paths=./api/... \
crd:crdVersions=v1 \
output:crd:dir=$(CRD_ROOT) \
output:none
## --------------------------------------
##@ Samples
## --------------------------------------
.PHONY: list-ctrl
list-ctrl: ## Build list sample with controller client
$(MAKE) tools
cd $(SAMPLES_DIR); make $@
## --------------------------------------
##@ Linting
## --------------------------------------
.PHONY: lint
lint: ## Run all the lint targets
$(MAKE) lint-go-full
$(MAKE) lint-markdown
GOLANGCI_LINT_FLAGS ?= --fast=true
.PHONY: lint-go
lint-go: $(GOLANGCI_LINT) ## Lint codebase
$(GOLANGCI_LINT) run -v $(GOLANGCI_LINT_FLAGS)
.PHONY: lint-go-full
lint-go-full: GOLANGCI_LINT_FLAGS = --fast=false
lint-go-full: lint-go ## Run slower linters to detect possible issues
.PHONY: lint-markdown
lint-markdown: ## Lint the project's markdown
docker run --rm -v "$$(pwd)":/build gcr.io/cluster-api-provider-vsphere/extra/mdlint:0.17.0
## --------------------------------------
##@ Cleanup
## --------------------------------------
.PHONY: clean
clean: # Clean all generated or compiled files
$(MAKE) clean-bin
$(MAKE) clean-crd
$(MAKE) modules
.PHONY: clean-bin
clean-bin: ## Remove all generated binaries
rm -rf hack/tools/bin
rm -rf hack/samples/bin
.PHONY: clean-crd
clean-crd: ## Remove all generated crds
rm -rf config/crd