@@ -6,6 +6,10 @@ CGO_ENABLED := 1
66# Enable users to override the golang used to accomodate custom installations
77GO ?= go
88
9+ # Set GOPATH from go env if not already set
10+ GOPATH ?= $(shell $(GO ) env GOPATH)
11+ export GOPATH
12+
913# Allow overriding `oc` command.
1014# Used by pr_check.py to ssh deploy inside private Hive cluster via bastion host.
1115oc: =oc
@@ -156,15 +160,29 @@ ifndef TEST_SUMMARY_FORMAT
156160 TEST_SUMMARY_FORMAT=short-verbose
157161endif
158162
159- # Checks if a GOPATH is set, or emits an error message
163+ # Ensures GOPATH is set (now auto-configured at top of Makefile)
160164check-gopath :
161- ifndef GOPATH
162- $(error GOPATH is not set)
163- endif
165+ @echo " GOPATH is set to: $( GOPATH) "
164166.PHONY : check-gopath
165167
168+ install-golang-gci :
169+ go install github.com/daixiang0/gci@v0.13.7
170+
171+ fmt-imports : install-golang-gci
172+ gci write --skip-generated -s standard -s default -s " prefix(github.com/openshift-online/maestro)" -s localmodule cmd pkg test
173+
174+ verify-fmt-imports : install-golang-gci
175+ @output=$$(gci diff --skip-generated -s standard -s default -s "prefix(github.com/openshift-online/maestro ) " -s localmodule cmd pkg test); \
176+ if [ -n " $$ output" ]; then \
177+ echo " Go import diff output is not empty: $$ output" ; \
178+ echo " Please run 'make fmt-imports' to format the golang files imports automatically." ; \
179+ exit 1; \
180+ else \
181+ echo " Go import diff output is empty" ; \
182+ fi
183+
166184# Verifies that source passes standard checks.
167- verify : check-gopath
185+ verify : check-gopath verify-fmt-imports
168186 ${GO} vet \
169187 ./cmd/... \
170188 ./pkg/...
0 commit comments