Skip to content
This repository was archived by the owner on Jul 30, 2021. It is now read-only.

Commit 92d52e7

Browse files
authored
Merge pull request #257 from vincepri/makefile-like-others
🏃Align Makefile with other CAP* repos
2 parents e09e034 + b465d57 commit 92d52e7

File tree

3 files changed

+59
-59
lines changed

3 files changed

+59
-59
lines changed

Makefile

Lines changed: 58 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -66,34 +66,36 @@ all: manager
6666
help: ## Display this help
6767
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-22s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
6868

69+
## --------------------------------------
70+
## Testing
71+
## --------------------------------------
72+
6973
.PHONY: test
70-
test: generate fmt vet lint ## Run tests
74+
test: generate lint ## Run tests
7175
go test ./... -coverprofile cover.out
7276

77+
## --------------------------------------
78+
## Binaries
79+
## --------------------------------------
80+
7381
.PHONY: manager
74-
manager: generate fmt vet ## Build manager binary
82+
manager: generate lint ## Build manager binary
7583
go build -o bin/manager main.go
7684

77-
.PHONY: run
78-
run: generate fmt vet ## Run against the configured Kubernetes cluster in ~/.kube/config
79-
go run ./main.go
80-
81-
.PHONY: install
82-
install: generate ## Install CRDs into a cluster
83-
kubectl apply -f config/crd/bases
85+
# Build controller-gen
86+
$(CONTROLLER_GEN): $(TOOLS_DIR)/go.mod
87+
cd $(TOOLS_DIR) && go build -o $(CONTROLLER_GEN_BIN) sigs.k8s.io/controller-tools/cmd/controller-gen
8488

85-
.PHONY: deploy
86-
deploy: generate ## Deploy controller in the configured Kubernetes cluster in ~/.kube/config
87-
kubectl apply -f config/crd/bases
88-
kubectl kustomize config/default | kubectl apply -f -
89+
# Build golangci-lint
90+
$(GOLANGCI_LINT): $(TOOLS_DIR)/go.mod
91+
cd $(TOOLS_DIR) && go build -o $(GOLANGCI_LINT_BIN) github.com/golangci/golangci-lint/cmd/golangci-lint
8992

90-
.PHONY: fmt
91-
fmt: ## Run go fmt against code
92-
go fmt ./...
93+
$(RELEASE_NOTES) : $(TOOLS_DIR)/go.mod
94+
cd $(TOOLS_DIR) && go build -o $(RELEASE_NOTES_BIN) -tags tools sigs.k8s.io/cluster-api/hack/tools/release
9395

94-
.PHONY: vet
95-
vet: ## Run go vet against code
96-
go vet ./...
96+
## --------------------------------------
97+
## Linting
98+
## --------------------------------------
9799

98100
.PHONY: lint
99101
lint: $(GOLANGCI_LINT) ## Lint quickly using `golangci-lint --fast=true`
@@ -103,6 +105,10 @@ lint: $(GOLANGCI_LINT) ## Lint quickly using `golangci-lint --fast=true`
103105
lint-full: $(GOLANGCI_LINT) ## Lint thoroughly using `golangci-lint --fase=false`
104106
$(GOLANGCI_LINT) run -v --fast=false
105107

108+
## --------------------------------------
109+
## Generate / Manifests
110+
## --------------------------------------
111+
106112
.PHONY: generate
107113
generate: $(CONTROLLER_GEN) ## Generate code
108114
$(MAKE) generate-manifests
@@ -116,13 +122,10 @@ generate-deepcopy: $(CONTROLLER_GEN) ## Generate deepcopy files
116122
generate-manifests: $(CONTROLLER_GEN) ## Generate manifests e.g. CRD, RBAC etc
117123
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:dir=$(CRD_ROOT) output:webhook:dir=$(WEBHOOK_ROOT) output:rbac:dir=$(RBAC_ROOT)
118124

119-
# Build controller-gen
120-
$(CONTROLLER_GEN): $(TOOLS_DIR)/go.mod
121-
cd $(TOOLS_DIR) && go build -o $(CONTROLLER_GEN_BIN) sigs.k8s.io/controller-tools/cmd/controller-gen
122-
123-
# Build golangci-lint
124-
$(GOLANGCI_LINT): $(TOOLS_DIR)/go.mod
125-
cd $(TOOLS_DIR) && go build -o $(GOLANGCI_LINT_BIN) github.com/golangci/golangci-lint/cmd/golangci-lint
125+
.PHONY: modules
126+
modules: ## Runs go mod to ensure modules are up to date.
127+
go mod tidy
128+
cd $(TOOLS_DIR); go mod tidy
126129

127130
## --------------------------------------
128131
## Docker
@@ -177,9 +180,6 @@ RELEASE_DIR := out
177180
$(RELEASE_DIR):
178181
mkdir -p $(RELEASE_DIR)/
179182

180-
$(RELEASE_NOTES) : $(TOOLS_DIR)/go.mod
181-
cd $(TOOLS_DIR) && go build -o $(RELEASE_NOTES_BIN) -tags tools sigs.k8s.io/cluster-api/hack/tools/release
182-
183183
.PHONY: release
184184
release: clean-release ## Builds and push container images using the latest git tag for the commit.
185185
@if [ -z "${RELEASE_TAG}" ]; then echo "RELEASE_TAG is not set"; exit 1; fi
@@ -197,20 +197,43 @@ release-manifests: $(RELEASE_DIR) ## Builds the manifests to publish with a rele
197197

198198
.PHONY: release-staging
199199
release-staging: ## Builds and push container images to the staging bucket.
200-
REGISTRY=$(STAGING_REGISTRY) $(MAKE) docker-build-all docker-push-all release-tag-latest
200+
REGISTRY=$(STAGING_REGISTRY) $(MAKE) docker-build-all docker-push-all release-alias-tag
201+
202+
RELEASE_ALIAS_TAG=$(shell if [ "$(PULL_BASE_REF)" = "master" ]; then echo "latest"; else echo "$(PULL_BASE_REF)"; fi)
203+
204+
.PHONY: release-alias-tag
205+
release-alias-tag: # Adds the tag to the last build tag.
206+
gcloud container images add-tag $(CONTROLLER_IMG):$(TAG) $(CONTROLLER_IMG):$(RELEASE_ALIAS_TAG)
201207

202208
.PHONY: release-notes
203209
release-notes: $(RELEASE_NOTES)
204210
$(RELEASE_NOTES)
205211

206-
.PHONY: release-tag-latest
207-
release-tag-latest: ## Adds the latest tag to the last build tag.
208-
## TODO(vincepri): Only do this when we're on master.
209-
gcloud container images add-tag $(CONTROLLER_IMG):$(TAG) $(CONTROLLER_IMG):latest
210-
211212
## --------------------------------------
212213
## Cleanup / Verification
213214
## --------------------------------------
215+
216+
.PHONY: clean
217+
clean: ## Remove all generated files
218+
$(MAKE) clean-release
219+
214220
.PHONY: clean-release
215221
clean-release: ## Remove the release folder
216222
rm -rf $(RELEASE_DIR)
223+
224+
## --------------------------------------
225+
## Others / Utilities
226+
## --------------------------------------
227+
228+
.PHONY: run
229+
run: generate lint ## Run against the configured Kubernetes cluster in ~/.kube/config
230+
go run ./main.go
231+
232+
.PHONY: install
233+
install: generate ## Install CRDs into a cluster
234+
kubectl apply -f config/crd/bases
235+
236+
.PHONY: deploy
237+
deploy: generate ## Deploy controller in the configured Kubernetes cluster in ~/.kube/config
238+
kubectl apply -f config/crd/bases
239+
kubectl kustomize config/default | kubectl apply -f -

cloudbuild.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ steps:
88
env:
99
- DOCKER_CLI_EXPERIMENTAL=enabled
1010
- TAG=$_GIT_TAG
11-
- ADDITIONAL_TAG=$_PULL_BASE_REF
11+
- PULL_BASE_REF=$_PULL_BASE_REF
1212
args:
1313
- release-staging
1414
substitutions:

0 commit comments

Comments
 (0)