2323
2424SHELL: =/usr/bin/env bash
2525.DEFAULT_GOAL: =help
26+ ROOT_DIR =$(abspath .)
2627
2728#
2829# Go.
@@ -52,12 +53,6 @@ TOOLS_BIN_DIR := $(abspath $(TOOLS_DIR)/bin)
5253GOLANGCI_LINT := $(abspath $(TOOLS_BIN_DIR ) /golangci-lint)
5354GO_APIDIFF := $(TOOLS_BIN_DIR ) /go-apidiff
5455CONTROLLER_GEN := $(TOOLS_BIN_DIR ) /controller-gen
55- EXAMPLES_KIND_DIR := $(abspath examples/kind)
56- PROVIDERS_KIND_DIR := $(abspath providers/kind)
57- EXAMPLES_CLUSTER_API_DIR := $(abspath examples/cluster-api)
58- PROVIDERS_CLUSTER_API_DIR := $(abspath providers/cluster-api)
59- EXAMPLES_CLUSTER_INVENTORY_API_DIR := $(abspath examples/cluster-inventory-api)
60- PROVIDERS_CLUSTER_INVENTORY_API_DIR := $(abspath providers/cluster-inventory-api)
6156GO_INSTALL := ./hack/go-install.sh
6257
6358# The help will print out all targets with their descriptions organized bellow their categories. The categories are represented by `##@` and the target descriptions by `##`.
@@ -111,39 +106,53 @@ GO_MOD_CHECK_DIR := $(abspath ./hack/tools/cmd/gomodcheck)
111106GO_MOD_CHECK := $(abspath $(TOOLS_BIN_DIR ) /gomodcheck)
112107GO_MOD_CHECK_IGNORE := $(abspath .gomodcheck.yaml)
113108.PHONY : $(GO_MOD_CHECK )
114- $(GO_MOD_CHECK ) : # Build gomodcheck
109+ $(GO_MOD_CHECK ) : # Build gomodcheck.
115110 go build -C $(GO_MOD_CHECK_DIR ) -o $(GO_MOD_CHECK )
116111
117112# # --------------------------------------
118113# # Linting
119114# # --------------------------------------
120115
121116.PHONY : lint
122- lint : $(GOLANGCI_LINT ) # # Lint codebase
123- $(GOLANGCI_LINT ) run -v $(GOLANGCI_LINT_EXTRA_ARGS )
124- cd examples/kind; $(GOLANGCI_LINT ) run -v $(GOLANGCI_LINT_EXTRA_ARGS )
125- cd proviers/kind; $(GOLANGCI_LINT ) run -v $(GOLANGCI_LINT_EXTRA_ARGS )
126- cd examples/cluster-api; $(GOLANGCI_LINT ) run -v $(GOLANGCI_LINT_EXTRA_ARGS )
127- cd proviers/cluster-api; $(GOLANGCI_LINT ) run -v $(GOLANGCI_LINT_EXTRA_ARGS )
117+ lint : WHAT ?=
118+ lint : $(GOLANGCI_LINT ) # # Lint codebase.
119+ @if [ -n " $( WHAT) " ]; then \
120+ $(GOLANGCI_LINT ) run -v $(GOLANGCI_LINT_EXTRA_ARGS ) $(WHAT ) ; \
121+ else \
122+ for MOD in . $$ (git ls-files ' **/go.mod' | sed ' s,/go.mod,,' ); do \
123+ (cd $$ MOD; $( GOLANGCI_LINT) run -v $( GOLANGCI_LINT_EXTRA_ARGS) ); \
124+ done ; \
125+ fi
128126
129127.PHONY : lint-fix
130128lint-fix : $(GOLANGCI_LINT ) # # Lint the codebase and run auto-fixers if supported by the linter.
131129 GOLANGCI_LINT_EXTRA_ARGS=--fix $(MAKE ) lint
132130
131+ .PHONY : imports
132+ imports : WHAT ?=
133+ imports : $(GOLANGCI_LINT ) # # Format module imports.
134+ @if [ -n " $( WHAT) " ]; then \
135+ $(GOLANGCI_LINT ) fmt --enable gci -c $(ROOT_DIR ) /.golangci.yml $(WHAT ) ; \
136+ else \
137+ for MOD in . $$ (git ls-files ' **/go.mod' | sed ' s,/go.mod,,' ); do \
138+ (cd $$ MOD; $( GOLANGCI_LINT) fmt --enable gci -c $( ROOT_DIR) /.golangci.yml); \
139+ done ; \
140+ fi
141+
133142# # --------------------------------------
134143# # Generate
135144# # --------------------------------------
136145
137146.PHONY : modules
147+ modules : WHAT ?=
138148modules : # # Runs go mod to ensure modules are up to date.
139- go mod tidy
140- cd $(TOOLS_DIR ) ; go mod tidy
141- cd $(EXAMPLES_KIND_DIR ) ; go mod tidy
142- cd $(PROVIDERS_KIND_DIR ) ; go mod tidy
143- cd $(EXAMPLES_CLUSTER_API_DIR ) ; go mod tidy
144- cd $(PROVIDERS_CLUSTER_API_DIR ) ; go mod tidy
145- cd $(EXAMPLES_CLUSTER_INVENTORY_API_DIR ) ; go mod tidy
146- cd $(PROVIDERS_CLUSTER_INVENTORY_API_DIR ) ; go mod tidy
149+ @if [ -n " $( WHAT) " ]; then \
150+ (cd $( WHAT) ; go mod tidy); \
151+ else \
152+ for MOD in . $$ (git ls-files ' **/go.mod' | sed ' s,/go.mod,,' ); do \
153+ (cd $$ MOD; go mod tidy); \
154+ done ; \
155+ fi
147156
148157# # --------------------------------------
149158# # Cleanup / Verification
@@ -159,54 +168,42 @@ clean-bin: ## Remove all generated binaries.
159168 rm -rf hack/tools/bin
160169
161170.PHONY : clean-release
162- clean-release : # # Remove the release folder
171+ clean-release : # # Remove the release folder.
163172 rm -rf $(RELEASE_DIR )
164173
165174.PHONY : verify-modules
166- verify-modules : modules $(GO_MOD_CHECK ) # # Verify go modules are up to date
167- @if ! (git diff --quiet HEAD -- go.sum go.mod $( TOOLS_DIR) /go.mod $( TOOLS_DIR) /go.sum \
168- $(EXAMPLES_KIND_DIR ) /go.mod $(EXAMPLES_KIND_DIR ) /go.sum \
169- $(PROVIDERS_KIND_DIR ) /go.mod $(PROVIDERS_KIND_DIR ) /go.sum \
170- $(EXAMPLES_CLUSTER_API_DIR ) /go.mod $(EXAMPLES_CLUSTER_API_DIR ) /go.sum \
171- $(PROVIDERS_CLUSTER_API_DIR ) /go.mod $(PROVIDERS_CLUSTER_API_DIR ) /go.sum \
172- $(EXAMPLES_CLUSTER_INVENTORY_API_DIR ) /go.mod $(EXAMPLES_CLUSTER_INVENTORY_API_DIR ) /go.sum \
173- $(PROVIDERS_CLUSTER_INVENTORY_API_DIR ) /go.mod $(PROVIDERS_CLUSTER_INVENTORY_API_DIR ) /go.sum \
174- ); then \
175- git diff; \
176- echo " go module files are out of date, please run 'make modules'" ; exit 1; \
177- fi
175+ verify-modules : modules $(GO_MOD_CHECK ) # # Verify go modules are up to date.
176+ @for MOD in . $(TOOLS_DIR ) $$(git ls-files '**/go.mod' | sed 's,/go.mod,,' ) ; do \
177+ pushd $$ MOD > /dev/null; if ! (git diff --quiet HEAD -- go.sum go.mod); then echo " [$$ MOD] go modules are out of date, please run 'make modules'" ; exit 1; fi ; popd > /dev/null; \
178+ done ; \
179+
178180 $(GO_MOD_CHECK) $(GO_MOD_CHECK_IGNORE)
179181
180182APIDIFF_OLD_COMMIT ?= $(shell git rev-parse origin/main)
181183
182184.PHONY : apidiff
183- verify-apidiff : $(GO_APIDIFF ) # # Check for API differences
185+ verify-apidiff : $(GO_APIDIFF ) # # Check for API differences.
184186 $(GO_APIDIFF ) $(APIDIFF_OLD_COMMIT ) --print-compatible
185187
186188# # --------------------------------------
187189# # Release Tooling
188190# # --------------------------------------
189191
190192
191- .PHONY : provider- release
192- provider- release : # # Create a commit bumping the provider modules to the latest release tag and tag providers.
193- @./hack/release-providers .sh
193+ .PHONY : release-commit
194+ release-commit : # # Create a commit bumping the provider modules to the latest release tag and tag providers.
195+ @./hack/release-commit .sh
194196
195197# # --------------------------------------
196198# # Helpers
197199# # --------------------------------------
198200
199201# #@ helpers:
200202
201- go-version : # # Print the go version we use to compile our binaries and images
203+ go-version : # # Print the go version we use to compile our binaries and images.
202204 @echo $(GO_VERSION )
203205
204- WHAT ?=
205- imports :
206- @if [ -n " $( WHAT) " ]; then \
207- $(GOLANGCI_LINT ) run --enable-only=gci --fix --fast $(WHAT ) ; \
208- else \
209- for MOD in . $$ (git ls-files ' **/go.mod' | sed ' s,/go.mod,,' ); do \
210- (cd $$ MOD; $( GOLANGCI_LINT) run --enable-only=gci --fix --fast); \
211- done ; \
212- fi
206+ list-modules : # # Print the Go modules in this repository for GitHub Actions matrix.
207+ @echo -n ' [' ; \
208+ git ls-files ' **/go.mod' | sed ' s,/go.mod,,' | awk ' BEGIN {printf "\"%s\"", "."} NR > 0 {printf ",\"%s\"", $$0}' ; \
209+ echo ' ]'
0 commit comments