Skip to content

Commit e420b3a

Browse files
authored
Merge pull request #2397 from zhengtianbao/makefile-phony
✨ Tag bollerplate Makefile targets as .PHONY
2 parents f80a317 + 26a8982 commit e420b3a

File tree

10 files changed

+181
-1
lines changed

10 files changed

+181
-1
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ else
6767
GOBIN=$(shell go env GOBIN)
6868
endif
6969
70+
.PHONY: all
7071
all: build
7172
7273
##@ General
@@ -82,40 +83,51 @@ all: build
8283
# More info on the awk command:
8384
# http://linuxcommand.org/lc3_adv_awk.php
8485
86+
.PHONY: help
8587
help: ## Display this help.
8688
@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)
8789
8890
##@ Development
8991
92+
.PHONY: manifests
9093
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
9194
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
9295
96+
.PHONY: generate
9397
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
9498
$(CONTROLLER_GEN) object:headerFile={{printf "%q" .BoilerplatePath}} paths="./..."
9599
100+
.PHONY: fmt
96101
fmt: ## Run go fmt against code.
97102
go fmt ./...
98103
104+
.PHONY: vet
99105
vet: ## Run go vet against code.
100106
go vet ./...
101107
108+
.PHONY: test
102109
test: manifests generate fmt vet ## Run tests.
103110
go test ./... -coverprofile cover.out
104111
105112
##@ Build
106113
114+
.PHONY: build
107115
build: generate fmt vet ## Build manager binary.
108116
go build -o bin/manager main.go
109117
110118
# Backwards compatibility
119+
.PHONY: manager
111120
manager: build ## Build manager binary (alias for build target).
112121
122+
.PHONY: run
113123
run: manifests generate fmt vet ## Run a controller from your host.
114124
go run ./main.go
115125
126+
.PHONY: docker-build
116127
docker-build: test ## Build docker image with the manager.
117128
docker build -t ${IMG} .
118129
130+
.PHONY: docker-push
119131
docker-push: ## Push docker image with the manager.
120132
docker push ${IMG}
121133
@@ -125,19 +137,24 @@ ifndef ignore-not-found
125137
ignore-not-found = no
126138
endif
127139
140+
.PHONY: install
128141
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
129142
$(KUSTOMIZE) build config/crd | kubectl apply -f -
130143
144+
.PHONY: uninstall
131145
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
132146
$(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
133147
148+
.PHONY: deploy
134149
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
135150
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
136151
$(KUSTOMIZE) build config/default | kubectl apply -f -
137152
153+
.PHONY: undeploy
138154
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
139155
$(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
140156
157+
.PHONY: controller-gen
141158
controller-gen: ## Download controller-gen locally if necessary.
142159
ifeq (, $(shell which controller-gen))
143160
@{ \
@@ -153,6 +170,7 @@ else
153170
CONTROLLER_GEN=$(shell which controller-gen)
154171
endif
155172
173+
.PHONY: kustomize
156174
kustomize: ## Download kustomize locally if necessary.
157175
ifeq (, $(shell which kustomize))
158176
@{ \

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ endif
7676
SHELL = /usr/bin/env bash -o pipefail
7777
.SHELLFLAGS = -ec
7878
79+
.PHONY: all
7980
all: build
8081
8182
##@ General
@@ -91,37 +92,47 @@ all: build
9192
# More info on the awk command:
9293
# http://linuxcommand.org/lc3_adv_awk.php
9394
95+
.PHONY: help
9496
help: ## Display this help.
9597
@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)
9698
9799
##@ Development
98100
101+
.PHONY: manifests
99102
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
100103
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
101104
105+
.PHONY: generate
102106
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
103107
$(CONTROLLER_GEN) object:headerFile={{printf "%q" .BoilerplatePath}} paths="./..."
104108
109+
.PHONY: fmt
105110
fmt: ## Run go fmt against code.
106111
go fmt ./...
107112
113+
.PHONY: vet
108114
vet: ## Run go vet against code.
109115
go vet ./...
110116
117+
.PHONY: test
111118
test: manifests generate fmt vet envtest ## Run tests.
112119
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test ./... -coverprofile cover.out
113120
114121
##@ Build
115122
123+
.PHONY: build
116124
build: generate fmt vet ## Build manager binary.
117125
go build -o bin/manager main.go
118126
127+
.PHONY: run
119128
run: manifests generate fmt vet ## Run a controller from your host.
120129
go run ./main.go
121130
131+
.PHONY: docker-build
122132
docker-build: test ## Build docker image with the manager.
123133
docker build -t ${IMG} .
124134
135+
.PHONY: docker-push
125136
docker-push: ## Push docker image with the manager.
126137
docker push ${IMG}
127138
@@ -131,28 +142,35 @@ ifndef ignore-not-found
131142
ignore-not-found = no
132143
endif
133144
145+
.PHONY: install
134146
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
135147
$(KUSTOMIZE) build config/crd | kubectl apply -f -
136148
149+
.PHONY: uninstall
137150
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
138151
$(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
139152
153+
.PHONY: deploy
140154
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
141155
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
142156
$(KUSTOMIZE) build config/default | kubectl apply -f -
143157
158+
.PHONY: undeploy
144159
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
145160
$(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
146161
147162
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
163+
.PHONY: controller-gen
148164
controller-gen: ## Download controller-gen locally if necessary.
149165
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@{{ .ControllerToolsVersion }})
150166
151167
KUSTOMIZE = $(shell pwd)/bin/kustomize
168+
.PHONY: kustomize
152169
kustomize: ## Download kustomize locally if necessary.
153170
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v3@{{ .KustomizeVersion }})
154171
155172
ENVTEST = $(shell pwd)/bin/setup-envtest
173+
.PHONY: envtest
156174
envtest: ## Download envtest-setup locally if necessary.
157175
$(call go-get-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest)
158176

testdata/project-v2-addon/Makefile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ else
1111
GOBIN=$(shell go env GOBIN)
1212
endif
1313

14+
.PHONY: all
1415
all: build
1516

1617
##@ General
@@ -26,40 +27,51 @@ all: build
2627
# More info on the awk command:
2728
# http://linuxcommand.org/lc3_adv_awk.php
2829

30+
.PHONY: help
2931
help: ## Display this help.
3032
@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)
3133

3234
##@ Development
3335

36+
.PHONY: manifests
3437
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
3538
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
3639

40+
.PHONY: generate
3741
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
3842
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
3943

44+
.PHONY: fmt
4045
fmt: ## Run go fmt against code.
4146
go fmt ./...
4247

48+
.PHONY: vet
4349
vet: ## Run go vet against code.
4450
go vet ./...
4551

52+
.PHONY: test
4653
test: manifests generate fmt vet ## Run tests.
4754
go test ./... -coverprofile cover.out
4855

4956
##@ Build
5057

58+
.PHONY: build
5159
build: generate fmt vet ## Build manager binary.
5260
go build -o bin/manager main.go
5361

5462
# Backwards compatibility
63+
.PHONY: manager
5564
manager: build ## Build manager binary (alias for build target).
5665

66+
.PHONY: run
5767
run: manifests generate fmt vet ## Run a controller from your host.
5868
go run ./main.go
5969

70+
.PHONY: docker-build
6071
docker-build: test ## Build docker image with the manager.
6172
docker build -t ${IMG} .
6273

74+
.PHONY: docker-push
6375
docker-push: ## Push docker image with the manager.
6476
docker push ${IMG}
6577

@@ -69,19 +81,24 @@ ifndef ignore-not-found
6981
ignore-not-found = no
7082
endif
7183

84+
.PHONY: install
7285
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
7386
$(KUSTOMIZE) build config/crd | kubectl apply -f -
7487

88+
.PHONY: uninstall
7589
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
7690
$(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
7791

92+
.PHONY: deploy
7893
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
7994
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
8095
$(KUSTOMIZE) build config/default | kubectl apply -f -
8196

97+
.PHONY: undeploy
8298
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
8399
$(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
84100

101+
.PHONY: controller-gen
85102
controller-gen: ## Download controller-gen locally if necessary.
86103
ifeq (, $(shell which controller-gen))
87104
@{ \
@@ -97,6 +114,7 @@ else
97114
CONTROLLER_GEN=$(shell which controller-gen)
98115
endif
99116

117+
.PHONY: kustomize
100118
kustomize: ## Download kustomize locally if necessary.
101119
ifeq (, $(shell which kustomize))
102120
@{ \

testdata/project-v2-multigroup/Makefile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ else
1111
GOBIN=$(shell go env GOBIN)
1212
endif
1313

14+
.PHONY: all
1415
all: build
1516

1617
##@ General
@@ -26,40 +27,51 @@ all: build
2627
# More info on the awk command:
2728
# http://linuxcommand.org/lc3_adv_awk.php
2829

30+
.PHONY: help
2931
help: ## Display this help.
3032
@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)
3133

3234
##@ Development
3335

36+
.PHONY: manifests
3437
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
3538
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
3639

40+
.PHONY: generate
3741
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
3842
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
3943

44+
.PHONY: fmt
4045
fmt: ## Run go fmt against code.
4146
go fmt ./...
4247

48+
.PHONY: vet
4349
vet: ## Run go vet against code.
4450
go vet ./...
4551

52+
.PHONY: test
4653
test: manifests generate fmt vet ## Run tests.
4754
go test ./... -coverprofile cover.out
4855

4956
##@ Build
5057

58+
.PHONY: build
5159
build: generate fmt vet ## Build manager binary.
5260
go build -o bin/manager main.go
5361

5462
# Backwards compatibility
63+
.PHONY: manager
5564
manager: build ## Build manager binary (alias for build target).
5665

66+
.PHONY: run
5767
run: manifests generate fmt vet ## Run a controller from your host.
5868
go run ./main.go
5969

70+
.PHONY: docker-build
6071
docker-build: test ## Build docker image with the manager.
6172
docker build -t ${IMG} .
6273

74+
.PHONY: docker-push
6375
docker-push: ## Push docker image with the manager.
6476
docker push ${IMG}
6577

@@ -69,19 +81,24 @@ ifndef ignore-not-found
6981
ignore-not-found = no
7082
endif
7183

84+
.PHONY: install
7285
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
7386
$(KUSTOMIZE) build config/crd | kubectl apply -f -
7487

88+
.PHONY: uninstall
7589
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
7690
$(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
7791

92+
.PHONY: deploy
7893
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
7994
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
8095
$(KUSTOMIZE) build config/default | kubectl apply -f -
8196

97+
.PHONY: undeploy
8298
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
8399
$(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
84100

101+
.PHONY: controller-gen
85102
controller-gen: ## Download controller-gen locally if necessary.
86103
ifeq (, $(shell which controller-gen))
87104
@{ \
@@ -97,6 +114,7 @@ else
97114
CONTROLLER_GEN=$(shell which controller-gen)
98115
endif
99116

117+
.PHONY: kustomize
100118
kustomize: ## Download kustomize locally if necessary.
101119
ifeq (, $(shell which kustomize))
102120
@{ \

0 commit comments

Comments
 (0)