Skip to content

Commit f7a5201

Browse files
authored
Merge pull request #1947 from droctothorpe/makefile-updates
✨ Add help dialog to makefile template
2 parents 1cd45e2 + a7fc753 commit f7a5201

File tree

6 files changed

+201
-154
lines changed

6 files changed

+201
-154
lines changed

Makefile

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,17 @@ endif
2828

2929
##@ General
3030

31-
# The help will print out all targets with their descriptions organized bellow their categories. The categories are represented by `##@` and the target descriptions by `##`.
32-
# The awk commands is responsable 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.
33-
# More info over the usage of ANSI control characters for terminal formatting: https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
34-
# More info over awk command: http://linuxcommand.org/lc3_adv_awk.php
31+
# The help target prints out all targets with their descriptions organized
32+
# beneath their categories. The categories are represented by '##@' and the
33+
# target descriptions by '##'. The awk commands is responsible for reading the
34+
# entire set of makefiles included in this invocation, looking for lines of the
35+
# file as xyz: ## something, and then pretty-format the target and help. Then,
36+
# if there's a line with ##@ something, that gets pretty-printed as a category.
37+
# More info on the usage of ANSI control characters for terminal formatting:
38+
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
39+
# More info on the awk command:
40+
# http://linuxcommand.org/lc3_adv_awk.php
41+
3542
.PHONY: help
3643
help: ## Display this help
3744
@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)

pkg/plugins/golang/v3/scaffolds/internal/templates/makefile.go

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -72,70 +72,78 @@ endif
7272
7373
all: manager
7474
75-
# Run tests
75+
##@ Targets
76+
77+
# The help target prints out all targets with their descriptions organized
78+
# beneath their categories. The categories are represented by '##@' and the
79+
# target descriptions by '##'. The awk commands is responsible for reading the
80+
# entire set of makefiles included in this invocation, looking for lines of the
81+
# file as xyz: ## something, and then pretty-format the target and help. Then,
82+
# if there's a line with ##@ something, that gets pretty-printed as a category.
83+
# More info on the usage of ANSI control characters for terminal formatting:
84+
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
85+
# More info on the awk command:
86+
# http://linuxcommand.org/lc3_adv_awk.php
87+
88+
.PHONY: help
89+
help: ## Display this help.
90+
@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)
91+
7692
ENVTEST_ASSETS_DIR=$(shell pwd)/testbin
77-
test: generate fmt vet manifests
93+
test: generate fmt vet manifests ## Run tests.
7894
mkdir -p ${ENVTEST_ASSETS_DIR}
7995
test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/{{ .ControllerRuntimeVersion }}/hack/setup-envtest.sh
8096
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./... -coverprofile cover.out
8197
82-
# Build manager binary
83-
manager: generate fmt vet
98+
manager: generate fmt vet ## Build manager binary.
8499
go build -o bin/manager main.go
85100
86-
# Run against the configured Kubernetes cluster in ~/.kube/config
87-
run: generate fmt vet manifests
101+
run: generate fmt vet manifests ## Run a controller from your host.
88102
go run ./main.go
89103
90-
# Install CRDs into a cluster
91-
install: manifests kustomize
104+
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
92105
$(KUSTOMIZE) build config/crd | kubectl apply -f -
93106
94-
# Uninstall CRDs from a cluster
95-
uninstall: manifests kustomize
107+
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config.
96108
$(KUSTOMIZE) build config/crd | kubectl delete -f -
97109
98-
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
99-
deploy: manifests kustomize
110+
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
100111
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
101112
$(KUSTOMIZE) build config/default | kubectl apply -f -
102113
103-
# UnDeploy controller from the configured Kubernetes cluster in ~/.kube/config
104-
undeploy:
114+
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config.
105115
$(KUSTOMIZE) build config/default | kubectl delete -f -
106116
107-
# Generate manifests e.g. CRD, RBAC etc.
108-
manifests: controller-gen
117+
118+
manifests: controller-gen ## Generate manifests e.g. CRD, RBAC, etc.
109119
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
110120
111-
# Run go fmt against code
112-
fmt:
121+
fmt: ## Run go fmt against code.
113122
go fmt ./...
114123
115-
# Run go vet against code
116-
vet:
124+
125+
vet: ## Run go vet against code.
117126
go vet ./...
118127
119-
# Generate code
120-
generate: controller-gen
128+
generate: controller-gen ## Generate code.
121129
$(CONTROLLER_GEN) object:headerFile={{printf "%q" .BoilerplatePath}} paths="./..."
122130
123-
# Build the docker image
124-
docker-build: test
131+
132+
docker-build: test ## Build the docker image for the controller.
125133
docker build -t ${IMG} .
126134
127-
# Push the docker image
128-
docker-push:
135+
136+
docker-push: ## Push the docker image for the controller.
129137
docker push ${IMG}
130138
131-
# Download controller-gen locally if necessary
139+
132140
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
133-
controller-gen:
141+
controller-gen: ## Download controller-gen locally if necessary.
134142
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@{{ .ControllerToolsVersion }})
135143
136-
# Download kustomize locally if necessary
144+
137145
KUSTOMIZE = $(shell pwd)/bin/kustomize
138-
kustomize:
146+
kustomize: ## Download kustomize locally if necessary.
139147
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v3@{{ .KustomizeVersion }})
140148
141149
# go-get-tool will 'go get' any package $2 and install it to $1.

testdata/project-v3-addon/Makefile

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,70 +13,78 @@ endif
1313

1414
all: manager
1515

16-
# Run tests
16+
##@ Targets
17+
18+
# The help target prints out all targets with their descriptions organized
19+
# beneath their categories. The categories are represented by '##@' and the
20+
# target descriptions by '##'. The awk commands is responsible for reading the
21+
# entire set of makefiles included in this invocation, looking for lines of the
22+
# file as xyz: ## something, and then pretty-format the target and help. Then,
23+
# if there's a line with ##@ something, that gets pretty-printed as a category.
24+
# More info on the usage of ANSI control characters for terminal formatting:
25+
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
26+
# More info on the awk command:
27+
# http://linuxcommand.org/lc3_adv_awk.php
28+
29+
.PHONY: help
30+
help: ## Display this help.
31+
@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)
32+
1733
ENVTEST_ASSETS_DIR=$(shell pwd)/testbin
18-
test: generate fmt vet manifests
34+
test: generate fmt vet manifests ## Run tests.
1935
mkdir -p ${ENVTEST_ASSETS_DIR}
2036
test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.7.0/hack/setup-envtest.sh
2137
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./... -coverprofile cover.out
2238

23-
# Build manager binary
24-
manager: generate fmt vet
39+
manager: generate fmt vet ## Build manager binary.
2540
go build -o bin/manager main.go
2641

27-
# Run against the configured Kubernetes cluster in ~/.kube/config
28-
run: generate fmt vet manifests
42+
run: generate fmt vet manifests ## Run a controller from your host.
2943
go run ./main.go
3044

31-
# Install CRDs into a cluster
32-
install: manifests kustomize
45+
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
3346
$(KUSTOMIZE) build config/crd | kubectl apply -f -
3447

35-
# Uninstall CRDs from a cluster
36-
uninstall: manifests kustomize
48+
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config.
3749
$(KUSTOMIZE) build config/crd | kubectl delete -f -
3850

39-
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
40-
deploy: manifests kustomize
51+
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
4152
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
4253
$(KUSTOMIZE) build config/default | kubectl apply -f -
4354

44-
# UnDeploy controller from the configured Kubernetes cluster in ~/.kube/config
45-
undeploy:
55+
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config.
4656
$(KUSTOMIZE) build config/default | kubectl delete -f -
4757

48-
# Generate manifests e.g. CRD, RBAC etc.
49-
manifests: controller-gen
58+
59+
manifests: controller-gen ## Generate manifests e.g. CRD, RBAC, etc.
5060
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
5161

52-
# Run go fmt against code
53-
fmt:
62+
fmt: ## Run go fmt against code.
5463
go fmt ./...
5564

56-
# Run go vet against code
57-
vet:
65+
66+
vet: ## Run go vet against code.
5867
go vet ./...
5968

60-
# Generate code
61-
generate: controller-gen
69+
generate: controller-gen ## Generate code.
6270
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
6371

64-
# Build the docker image
65-
docker-build: test
72+
73+
docker-build: test ## Build the docker image for the controller.
6674
docker build -t ${IMG} .
6775

68-
# Push the docker image
69-
docker-push:
76+
77+
docker-push: ## Push the docker image for the controller.
7078
docker push ${IMG}
7179

72-
# Download controller-gen locally if necessary
80+
7381
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
74-
controller-gen:
82+
controller-gen: ## Download controller-gen locally if necessary.
7583
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/[email protected])
7684

77-
# Download kustomize locally if necessary
85+
7886
KUSTOMIZE = $(shell pwd)/bin/kustomize
79-
kustomize:
87+
kustomize: ## Download kustomize locally if necessary.
8088
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/[email protected])
8189

8290
# go-get-tool will 'go get' any package $2 and install it to $1.

testdata/project-v3-config/Makefile

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,70 +13,78 @@ endif
1313

1414
all: manager
1515

16-
# Run tests
16+
##@ Targets
17+
18+
# The help target prints out all targets with their descriptions organized
19+
# beneath their categories. The categories are represented by '##@' and the
20+
# target descriptions by '##'. The awk commands is responsible for reading the
21+
# entire set of makefiles included in this invocation, looking for lines of the
22+
# file as xyz: ## something, and then pretty-format the target and help. Then,
23+
# if there's a line with ##@ something, that gets pretty-printed as a category.
24+
# More info on the usage of ANSI control characters for terminal formatting:
25+
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
26+
# More info on the awk command:
27+
# http://linuxcommand.org/lc3_adv_awk.php
28+
29+
.PHONY: help
30+
help: ## Display this help.
31+
@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)
32+
1733
ENVTEST_ASSETS_DIR=$(shell pwd)/testbin
18-
test: generate fmt vet manifests
34+
test: generate fmt vet manifests ## Run tests.
1935
mkdir -p ${ENVTEST_ASSETS_DIR}
2036
test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.7.0/hack/setup-envtest.sh
2137
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./... -coverprofile cover.out
2238

23-
# Build manager binary
24-
manager: generate fmt vet
39+
manager: generate fmt vet ## Build manager binary.
2540
go build -o bin/manager main.go
2641

27-
# Run against the configured Kubernetes cluster in ~/.kube/config
28-
run: generate fmt vet manifests
42+
run: generate fmt vet manifests ## Run a controller from your host.
2943
go run ./main.go
3044

31-
# Install CRDs into a cluster
32-
install: manifests kustomize
45+
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
3346
$(KUSTOMIZE) build config/crd | kubectl apply -f -
3447

35-
# Uninstall CRDs from a cluster
36-
uninstall: manifests kustomize
48+
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config.
3749
$(KUSTOMIZE) build config/crd | kubectl delete -f -
3850

39-
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
40-
deploy: manifests kustomize
51+
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
4152
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
4253
$(KUSTOMIZE) build config/default | kubectl apply -f -
4354

44-
# UnDeploy controller from the configured Kubernetes cluster in ~/.kube/config
45-
undeploy:
55+
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config.
4656
$(KUSTOMIZE) build config/default | kubectl delete -f -
4757

48-
# Generate manifests e.g. CRD, RBAC etc.
49-
manifests: controller-gen
58+
59+
manifests: controller-gen ## Generate manifests e.g. CRD, RBAC, etc.
5060
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
5161

52-
# Run go fmt against code
53-
fmt:
62+
fmt: ## Run go fmt against code.
5463
go fmt ./...
5564

56-
# Run go vet against code
57-
vet:
65+
66+
vet: ## Run go vet against code.
5867
go vet ./...
5968

60-
# Generate code
61-
generate: controller-gen
69+
generate: controller-gen ## Generate code.
6270
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
6371

64-
# Build the docker image
65-
docker-build: test
72+
73+
docker-build: test ## Build the docker image for the controller.
6674
docker build -t ${IMG} .
6775

68-
# Push the docker image
69-
docker-push:
76+
77+
docker-push: ## Push the docker image for the controller.
7078
docker push ${IMG}
7179

72-
# Download controller-gen locally if necessary
80+
7381
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
74-
controller-gen:
82+
controller-gen: ## Download controller-gen locally if necessary.
7583
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/[email protected])
7684

77-
# Download kustomize locally if necessary
85+
7886
KUSTOMIZE = $(shell pwd)/bin/kustomize
79-
kustomize:
87+
kustomize: ## Download kustomize locally if necessary.
8088
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/[email protected])
8189

8290
# go-get-tool will 'go get' any package $2 and install it to $1.

0 commit comments

Comments
 (0)