Skip to content

Commit 7db1811

Browse files
committed
build: Consistently format even generated files
Calling golines when generating deepcopy, etc will ensure a consistent formatting for these generated files. Also reinstated go fix as this is now properly supported in recent go versions. And finally simplify the ignore external call by using golines flag rather than a grep on the go source dirs.
1 parent da32b0f commit 7db1811

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

make/go.mk

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,23 @@ endif
137137

138138
.PHONY: lint.%
139139
lint.%: ## Runs golangci-lint for a specific module
140-
lint.%: ; $(info $(M) linting $* module)
141-
$(if $(filter-out root,$*),cd $* && )golines -w $$(GOWORK=off go list -tags e2e ./... | grep -v external | sed "s|^$$(GOWORK=off go list -m)|.|")
140+
lint.%: golines.% ; $(info $(M) linting $* module)
142141
$(if $(filter-out root,$*),cd $* && )golangci-lint run --fix --config=$(GOLANGCI_CONFIG_FILE)
143-
$(if $(filter-out root,$*),cd $* && )golines -w $$(GOWORK=off go list -tags e2e ./... | grep -v external | sed "s|^$$(GOWORK=off go list -m)|.|")
142+
$(MAKE) golines.$*
143+
144+
.PHONY: golines
145+
golines: ## Runs golines for all modules in repository
146+
ifneq ($(wildcard $(REPO_ROOT)/go.mod),)
147+
golines: golines.root
148+
endif
149+
ifneq ($(words $(GO_SUBMODULES_NO_DOCS)),0)
150+
golines: $(addprefix golines.,$(GO_SUBMODULES_NO_DOCS:/go.mod=))
151+
endif
152+
153+
.PHONY: golines.%
154+
golines.%: ## Runs golines for a specific module
155+
golines.%:
156+
$(if $(filter-out root,$*),cd $* && )golines -w --ignored-dirs external $$(GOWORK=off go list -tags e2e ./... | sed "s|^$$(GOWORK=off go list -m)|.|")
144157

145158
.PHONY: mod-tidy
146159
mod-tidy: ## Run go mod tidy for all modules
@@ -185,9 +198,9 @@ go-fix: $(addprefix go-fix.,$(GO_SUBMODULES_NO_DOCS:/go.mod=))
185198
endif
186199

187200
.PHONY: go-fix.%
188-
go-fix.%: ## Runs golangci-lint for a specific module
201+
go-fix.%: ## Runs go fix for a specific module
189202
go-fix.%: ; $(info $(M) go fixing $* module)
190-
$(if $(filter-out root,$*),cd $* && )go fix ./...
203+
$(if $(filter-out root,$*),cd $* && )go fix $$(GOWORK=off go list ./... | sed "s|^$$(GOWORK=off go list -m)|.|" | grep -v external)
191204

192205
.PHONY: go-generate
193206
go-generate: ## Runs go generate
@@ -210,7 +223,7 @@ go-generate: ; $(info $(M) running go generate)
210223
yq --inplace \
211224
--from-file=hack/update-webhook-configurations.yq \
212225
charts/cluster-api-runtime-extensions-nutanix/templates/webhooks.yaml
213-
#$(MAKE) go-fix
226+
$(MAKE) go-fix golines
214227
$(MAKE) configure-csi-providers
215228
# Update anyOf schemas for resource.Quantity fields to only accept strings
216229
# until CAPI ClusterClass variables support anyOf schemas.

make/make.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33

44
MAKEFLAGS += --no-builtin-rules
55
MAKEFLAGS += --no-builtin-variables
6+
MAKEFLAGS += --no-print-directory

0 commit comments

Comments
 (0)