Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align Makefile - Goimports instead of go fmt #19

Merged
merged 1 commit into from
Mar 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ CONTROLLER_GEN_VERSION ?= v0.8.0
# See https://pkg.go.dev/sigs.k8s.io/controller-runtime/tools/setup-envtest?tab=versions for the last version
ENVTEST_VERSION ?= v0.0.0-20221022092956-090611b34874
# See https://pkg.go.dev/golang.org/x/tools/cmd/goimports?tab=versions for the last version
GOIMPORTS_VERSION ?= v0.6.0
# See github.com/operator-framework/operator-registry/releases for the last version
OPM_VERSION ?= v1.26.2
# See github.com/operator-framework/operator-sdk/releases for the last version
OPERATOR_SDK_VERSION ?= v1.26.0
Expand Down Expand Up @@ -144,11 +146,11 @@ generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."

.PHONY: fmt
fmt: ## Run go fmt against code.
go fmt ./...
fmt: goimports ## Run go goimports against code - goimports = go fmt + fixing imports.
$(GOIMPORTS) -w ./main.go ./pkg ./api ./controllers

.PHONY: vet
vet: ## Run go vet against code.
vet: ## Run go vet against code - report likely mistakes in packages.
go vet ./...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ooooohhhh.... this is new! Well, for me at least 😎. ./... used to also match the vendor dir, that's why we started listing our files/dirs manually. Great to see that it doesn't anymore. Well, since Go 1.9 already?! 🙈 Just to be sure, goimports is still trying to modify files in vendor?
https://go.dev/doc/go1.9#vendor-dotdotdot

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

goimports v0.6.0 didn't work with ./..., so unless we add ./vendor then goimports won't modify the files under vendor.


.PHONY: go-tidy
Expand Down Expand Up @@ -244,6 +246,7 @@ KUSTOMIZE_DIR ?= $(LOCALBIN)/kustomize
CONTROLLER_GEN_DIR ?= $(LOCALBIN)/controller-gen
ENVTEST_DIR ?= $(LOCALBIN)/setup-envtest
GINKGO_DIR ?= $(LOCALBIN)/ginkgo
GOIMPORTS_DIR ?= $(LOCALBIN)/goimports
OPM_DIR = $(LOCALBIN)/opm
OPERATOR_SDK_DIR ?= $(LOCALBIN)/operator-sdk
SORT_IMPORTS_DIR ?= $(LOCALBIN)/sort-imports
Expand All @@ -253,6 +256,7 @@ KUSTOMIZE = $(KUSTOMIZE_DIR)/$(KUSTOMIZE_VERSION)/kustomize
CONTROLLER_GEN = $(CONTROLLER_GEN_DIR)/$(CONTROLLER_GEN_VERSION)/controller-gen
ENVTEST = $(ENVTEST_DIR)/$(ENVTEST_VERSION)/setup-envtest
GINKGO = $(GINKGO_DIR)/$(GINKGO_VERSION)/ginkgo
GOIMPORTS = $(GOIMPORTS_DIR)/$(GOIMPORTS_VERSION)/goimports
OPM = $(OPM_DIR)/$(OPM_VERSION)/opm
OPERATOR_SDK = $(OPERATOR_SDK_DIR)/$(OPERATOR_SDK_VERSION)/operator-sdk
SORT_IMPORTS = $(SORT_IMPORTS_DIR)/$(SORT_IMPORTS_VERSION)/sort-imports
Expand All @@ -273,6 +277,10 @@ envtest: ## Download envtest-setup locally if necessary.
ginkgo: ## Download ginkgo locally if necessary.
$(call go-install-tool,$(GINKGO),$(GINKGO_DIR),github.com/onsi/ginkgo/ginkgo@${GINKGO_VERSION})

.PHONY: goimports
goimports: ## Download goimports locally if necessary.
$(call go-install-tool,$(GOIMPORTS),$(GOIMPORTS_DIR),golang.org/x/tools/cmd/goimports@${GOIMPORTS_VERSION})

.PHONY: sort-imports
sort-imports: ## Download sort-imports locally if necessary.
$(call go-install-tool,$(SORT_IMPORTS),$(SORT_IMPORTS_DIR),github.com/slintes/sort-imports@$(SORT_IMPORTS_VERSION))
Expand Down Expand Up @@ -302,7 +310,7 @@ bundle: manifests operator-sdk kustomize ## Generate bundle manifests and metada
$(OPERATOR_SDK) bundle validate ./bundle

.PHONY: bundle-build
bundle-build: bundle-update ## Build the bundle image.
bundle-build: bundle bundle-update ## Build the bundle image.
docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) .

.PHONY: bundle-push
Expand Down