1+
2+ .PHONY : go-module-version
3+ go-module-version : go-check git-check
4+ @echo " go get $( shell $( GO) list ./cmd/addon-operator) @$( shell $( GIT) rev-parse HEAD) "
5+
6+ .PHONY : lint
7+ lint : golangci-lint # # Run linter.
8+ @$(GOLANGCI_LINT ) run --fix
9+
10+ .PHONY : test
11+ test : go-check
12+ @$(GO ) test --race --cover ./...
13+
14+ # # Run all generate-* jobs in bulk.
15+ .PHONY : generate
16+ generate : update-k8s-version update-workflows-go-version update-workflows-golangci-lint-version update-workflows-ginkgo-version
17+
18+
19+ # #@ Dependencies
20+
21+ WHOAMI ?= $(shell whoami)
22+
23+ # # Location to install dependencies to
24+ LOCALBIN ?= $(shell pwd) /bin
25+ $(LOCALBIN ) :
26+ mkdir -p $(LOCALBIN )
27+
28+ # # Tool Binaries
129GO =$(shell which go)
230GIT =$(shell which git)
31+ GOLANGCI_LINT = $(LOCALBIN ) /golangci-lint
32+ YQ = $(LOCALBIN ) /yq
33+
34+ # # TODO: remap in yaml file (version.yaml or smthng)
35+ # # Tool Versions
36+ # GO_BUILDER_VERSION must be without 'v' prefix
37+ GO_BUILDER_VERSION = 1.25.5
38+ GOLANGCI_LINT_VERSION = v2.8.0
39+ YQ_VERSION ?= v4.50.1
40+
41+
42+ .PHONY : update-k8s-version
43+ update-k8s-version : go-check
44+ @kubernetesVer=$(shell $(GO ) list -m k8s.io/api | cut -d' ' -f 2) ; \
45+ kubectlVer=$$(echo $$kubernetesVer | sed 's/v0/v1/' ) ; \
46+ echo " Updating kubectl version in Dockerfile to match k8s.io/api version: $$ kubectlVer" ; \
47+ sed -i " s/ARG kubectlVersion=.*/ARG kubectlVersion=$$ kubectlVer/" Dockerfile; \
48+ echo " kubectl version in Dockerfile updated to: $$ kubectlVer"
49+
50+ .PHONY : update-workflows-go-version
51+ update-workflows-go-version : yq
52+ for file in $$ (find .github/workflows -name " *.yaml" ); do \
53+ if grep -q " actions/setup-go" $$ file; then \
54+ $(YQ ) -i ' (.jobs[]?.steps[]? | select(.uses | test("actions/setup-go")) | .with."go-version") = "$(GO_BUILDER_VERSION)"' $$ file; \
55+ fi ; \
56+ done
57+ echo " Updated go-version in workflow files to $( GO_BUILDER_VERSION) "
58+
59+ .PHONY : update-workflows-golangci-lint-version
60+ update-workflows-golangci-lint-version : yq
61+ $(YQ ) -i ' (.jobs.run_linter.steps[] | select(.name == "Run golangci-lint") | .run) |= sub("v\\d+\\.\\d+\\.\\d+", "$(GOLANGCI_LINT_VERSION)")' .github/workflows/lint.yaml
62+ echo " Updated golangci-lint version in lint.yaml to $( GOLANGCI_LINT_VERSION) "
63+
64+ .PHONY : update-workflows-ginkgo-version
65+ update-workflows-ginkgo-version : yq
66+ @ginkgoVer=$(shell $(GO ) list -m github.com/onsi/ginkgo/v2 | cut -d' ' -f 2) ; \
67+ $(YQ ) -i ' (.jobs.integration_tests.steps[] | select(.name == "Install ginkgo") | .run) |= sub("@latest", "@$$ginkgoVer")' .github/workflows/tests-labeled.yaml; \
68+ echo " Updated ginkgo version in tests-labeled.yaml to $$ ginkgoVer"
69+
70+ # # Installed tools check
371
472.PHONY : go-check
573go-check :
@@ -9,13 +77,35 @@ go-check:
977git-check :
1078 $(call error-if-empty,$(GIT ) ,git)
1179
12- .PHONY : go-module-version
13- go-module-version : go-check git-check
14- @echo " go get $( shell $( GO) list ./cmd/addon-operator) @$( shell $( GIT) rev-parse HEAD) "
80+ # # Tool installations
81+
82+ .PHONY : golangci-lint
83+ golangci-lint : $(GOLANGCI_LINT ) # # Download golangci-lint locally if necessary.
84+ $(GOLANGCI_LINT ) : $(LOCALBIN )
85+ $(call go-install-tool,$(GOLANGCI_LINT ) ,github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION ) )
86+
87+ .PHONY : yq
88+ yq : $(YQ ) # # Download yq locally if necessary.
89+ $(YQ ) : $(LOCALBIN )
90+ $(call go-install-tool,$(YQ ) ,github.com/mikefarah/yq/v4,$(YQ_VERSION ) )
91+
92+
93+ # go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
94+ # $1 - target path with name of binary
95+ # $2 - package url which can be installed
96+ # $3 - specific version of package
97+ define go-install-tool
98+ @[ -f "$(1 ) -$(3 ) " ] || { \
99+ set -e; \
100+ package=$(2 ) @$(3 ) ;\
101+ echo "Downloading $${package}" ;\
102+ rm -f $(1 ) || true ;\
103+ GOBIN=$(LOCALBIN ) GOTOOLCHAIN=$(GO_TOOLCHAIN_AUTOINSTALL_VERSION ) go install $${package} ;\
104+ mv $(1 ) $(1 ) -$(3 ) ;\
105+ } ;\
106+ ln -sf $(1 ) -$(3 ) $(1 )
107+ endef
15108
16- .PHONY : test
17- test : go-check
18- @$(GO ) test --race --cover ./...
19109
20110define error-if-empty
21111@if [[ -z $(1 ) ]]; then echo "$(2 ) not installed"; false; fi
0 commit comments