Skip to content

Commit 893c4b0

Browse files
JoibelMasonM
andauthored
refactor: tidy tools in makefile (#14318)
Signed-off-by: Alan Clucas <[email protected]> Co-authored-by: Mason Malone <[email protected]>
1 parent ee45eac commit 893c4b0

File tree

2 files changed

+72
-47
lines changed

2 files changed

+72
-47
lines changed

Makefile

+70-47
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,33 @@ ifeq ($(PROFILE),sso)
9292
AUTH_MODE := sso
9393
endif
9494

95+
ifndef $(GOPATH)
96+
GOPATH:=$(shell go env GOPATH)
97+
export GOPATH
98+
endif
99+
100+
# Makefile managed tools
101+
TOOL_MOCKERY := $(GOPATH)/bin/mockery
102+
TOOL_CONTROLLER_GEN := $(GOPATH)/bin/controller-gen
103+
TOOL_GO_TO_PROTOBUF := $(GOPATH)/bin/go-to-protobuf
104+
TOOL_PROTOC_GEN_GOGO := $(GOPATH)/bin/protoc-gen-gogo
105+
TOOL_PROTOC_GEN_GOGOFAST := $(GOPATH)/bin/protoc-gen-gogofast
106+
TOOL_PROTOC_GEN_GRPC_GATEWAY:= $(GOPATH)/bin/protoc-gen-grpc-gateway
107+
TOOL_PROTOC_GEN_SWAGGER := $(GOPATH)/bin/protoc-gen-swagger
108+
TOOL_OPENAPI_GEN := $(GOPATH)/bin/openapi-gen
109+
TOOL_SWAGGER := $(GOPATH)/bin/swagger
110+
TOOL_GOIMPORTS := $(GOPATH)/bin/goimports
111+
TOOL_GOLANGCI_LINT := $(GOPATH)/bin/golangci-lint
112+
113+
# npm bin -g will do this on later npms than we have
114+
NVM_BIN ?= $(shell npm config get prefix)/bin
115+
TOOL_CLANG_FORMAT := /usr/local/bin/clang-format
116+
TOOL_MDSPELL := $(NVM_BIN)/mdspell
117+
TOOL_MARKDOWN_LINK_CHECK := $(NVM_BIN)/markdown-link-check
118+
TOOL_MARKDOWNLINT := $(NVM_BIN)/markdownlint
119+
TOOL_MKDOCS_DIR := $(HOME)/.venv/mkdocs
120+
TOOL_MKDOCS := $(TOOL_MKDOCS_DIR)/bin/mkdocs
121+
95122
$(info GIT_COMMIT=$(GIT_COMMIT) GIT_BRANCH=$(GIT_BRANCH) GIT_TAG=$(GIT_TAG) GIT_TREE_STATE=$(GIT_TREE_STATE) RELEASE_TAG=$(RELEASE_TAG) DEV_BRANCH=$(DEV_BRANCH) VERSION=$(VERSION))
96123
$(info KUBECTX=$(KUBECTX) K3D=$(K3D) DOCKER_PUSH=$(DOCKER_PUSH) TARGET_PLATFORM=$(TARGET_PLATFORM))
97124
$(info RUN_MODE=$(RUN_MODE) PROFILE=$(PROFILE) AUTH_MODE=$(AUTH_MODE) SECURE=$(SECURE) STATIC_FILES=$(STATIC_FILES) ALWAYS_OFFLOAD_NODE_STATUS=$(ALWAYS_OFFLOAD_NODE_STATUS) UPPERIO_DB_DEBUG=$(UPPERIO_DB_DEBUG) LOG_LEVEL=$(LOG_LEVEL) NAMESPACED=$(NAMESPACED))
@@ -106,11 +133,6 @@ ifneq ($(GIT_TAG),)
106133
override LDFLAGS += -X github.com/argoproj/argo-workflows/v3.gitTag=${GIT_TAG}
107134
endif
108135

109-
ifndef $(GOPATH)
110-
GOPATH:=$(shell go env GOPATH)
111-
export GOPATH
112-
endif
113-
114136
# -- file lists
115137
# These variables are only used as prereqs for the below targets, and we don't want to run them for other targets
116138
# because the "go list" calls are very slow
@@ -146,7 +168,7 @@ SWAGGER_FILES := pkg/apiclient/_.primary.swagger.json \
146168
pkg/apiclient/workflow/workflow.swagger.json \
147169
pkg/apiclient/workflowarchive/workflow-archive.swagger.json \
148170
pkg/apiclient/workflowtemplate/workflow-template.swagger.json
149-
PROTO_BINARIES := $(GOPATH)/bin/protoc-gen-gogo $(GOPATH)/bin/protoc-gen-gogofast $(GOPATH)/bin/goimports $(GOPATH)/bin/protoc-gen-grpc-gateway $(GOPATH)/bin/protoc-gen-swagger /usr/local/bin/clang-format
171+
PROTO_BINARIES := $(TOOL_PROTOC_GEN_GOGO) $(TOOL_PROTOC_GEN_GOGOFAST) $(TOOL_GOIMPORTS) $(TOOL_PROTOC_GEN_GRPC_GATEWAY) $(TOOL_PROTOC_GEN_SWAGGER) $(TOOL_CLANG_FORMAT)
150172

151173
# protoc,my.proto
152174
define protoc
@@ -260,7 +282,7 @@ argoexec-image:
260282
if [ $(DOCKER_PUSH) = true ] && [ $(IMAGE_NAMESPACE) != argoproj ] ; then docker push $(IMAGE_NAMESPACE)/$*:$(VERSION) ; fi
261283

262284
.PHONY: codegen
263-
codegen: types swagger manifests $(GOPATH)/bin/mockery docs/fields.md docs/cli/argo.md
285+
codegen: types swagger manifests $(TOOL_MOCKERY) docs/fields.md docs/cli/argo.md
264286
go generate ./...
265287
make --directory sdks/java USE_NIX=$(USE_NIX) generate
266288
make --directory sdks/python USE_NIX=$(USE_NIX) generate
@@ -292,17 +314,17 @@ swagger: \
292314
api/jsonschema/schema.json
293315

294316

295-
$(GOPATH)/bin/mockery: Makefile
317+
$(TOOL_MOCKERY): Makefile
296318
# update this in Nix when upgrading it here
297319
ifneq ($(USE_NIX), true)
298320
go install github.com/vektra/mockery/[email protected]
299321
endif
300-
$(GOPATH)/bin/controller-gen: Makefile
322+
$(TOOL_CONTROLLER_GEN): Makefile
301323
# update this in Nix when upgrading it here
302324
ifneq ($(USE_NIX), true)
303325
go install sigs.k8s.io/controller-tools/cmd/[email protected]
304326
endif
305-
$(GOPATH)/bin/go-to-protobuf: Makefile
327+
$(TOOL_GO_TO_PROTOBUF): Makefile
306328
# update this in Nix when upgrading it here
307329
ifneq ($(USE_NIX), true)
308330
# TODO: currently fails on v0.30.3 with
@@ -314,43 +336,43 @@ $(GOPATH)/src/github.com/gogo/protobuf: Makefile
314336
ifneq ($(USE_NIX), true)
315337
[ -e $@ ] || git clone --depth 1 https://github.com/gogo/protobuf.git -b v1.3.2 $@
316338
endif
317-
$(GOPATH)/bin/protoc-gen-gogo: Makefile
339+
$(TOOL_PROTOC_GEN_GOGO): Makefile
318340
# update this in Nix when upgrading it here
319341
ifneq ($(USE_NIX), true)
320342
go install github.com/gogo/protobuf/[email protected]
321343
endif
322-
$(GOPATH)/bin/protoc-gen-gogofast: Makefile
344+
$(TOOL_PROTOC_GEN_GOGOFAST): Makefile
323345
# update this in Nix when upgrading it here
324346
ifneq ($(USE_NIX), true)
325347
go install github.com/gogo/protobuf/[email protected]
326348
endif
327-
$(GOPATH)/bin/protoc-gen-grpc-gateway: Makefile
349+
$(TOOL_PROTOC_GEN_GRPC_GATEWAY): Makefile
328350
# update this in Nix when upgrading it here
329351
ifneq ($(USE_NIX), true)
330352
go install github.com/grpc-ecosystem/grpc-gateway/[email protected]
331353
endif
332-
$(GOPATH)/bin/protoc-gen-swagger: Makefile
354+
$(TOOL_PROTOC_GEN_SWAGGER): Makefile
333355
# update this in Nix when upgrading it here
334356
ifneq ($(USE_NIX), true)
335357
go install github.com/grpc-ecosystem/grpc-gateway/[email protected]
336358
endif
337-
$(GOPATH)/bin/openapi-gen: Makefile
359+
$(TOOL_OPENAPI_GEN): Makefile
338360
# update this in Nix when upgrading it here
339361
ifneq ($(USE_NIX), true)
340362
go install k8s.io/kube-openapi/cmd/[email protected]
341363
endif
342-
$(GOPATH)/bin/swagger: Makefile
364+
$(TOOL_SWAGGER): Makefile
343365
# update this in Nix when upgrading it here
344366
ifneq ($(USE_NIX), true)
345367
go install github.com/go-swagger/go-swagger/cmd/[email protected]
346368
endif
347-
$(GOPATH)/bin/goimports: Makefile
369+
$(TOOL_GOIMPORTS): Makefile
348370
# update this in Nix when upgrading it here
349371
ifneq ($(USE_NIX), true)
350372
go install golang.org/x/tools/cmd/[email protected]
351373
endif
352374

353-
/usr/local/bin/clang-format:
375+
$(TOOL_CLANG_FORMAT):
354376
ifeq (, $(shell which clang-format))
355377
ifeq ($(shell uname),Darwin)
356378
brew install clang-format
@@ -360,13 +382,13 @@ else
360382
endif
361383
endif
362384

363-
pkg/apis/workflow/v1alpha1/generated.proto: $(GOPATH)/bin/go-to-protobuf $(PROTO_BINARIES) $(TYPES) $(GOPATH)/src/github.com/gogo/protobuf
385+
pkg/apis/workflow/v1alpha1/generated.proto: $(TOOL_GO_TO_PROTOBUF) $(PROTO_BINARIES) $(TYPES) $(GOPATH)/src/github.com/gogo/protobuf
364386
# These files are generated on a v3/ folder by the tool. Link them to the root folder
365387
[ -e ./v3 ] || ln -s . v3
366388
# Format proto files. Formatting changes generated code, so we do it here, rather that at lint time.
367389
# Why clang-format? Google uses it.
368390
find pkg/apiclient -name '*.proto'|xargs clang-format -i
369-
$(GOPATH)/bin/go-to-protobuf \
391+
$(TOOL_GO_TO_PROTOBUF) \
370392
--go-header-file=./hack/custom-boilerplate.go.txt \
371393
--packages=github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1 \
372394
--apimachinery-packages=+k8s.io/apimachinery/pkg/util/intstr,+k8s.io/apimachinery/pkg/api/resource,k8s.io/apimachinery/pkg/runtime/schema,+k8s.io/apimachinery/pkg/runtime,k8s.io/apimachinery/pkg/apis/meta/v1,k8s.io/api/core/v1,k8s.io/api/policy/v1 \
@@ -405,7 +427,7 @@ pkg/apiclient/workflowtemplate/workflow-template.swagger.json: $(PROTO_BINARIES)
405427
$(call protoc,pkg/apiclient/workflowtemplate/workflow-template.proto)
406428

407429
# generate other files for other CRDs
408-
manifests/base/crds/full/argoproj.io_workflows.yaml: $(GOPATH)/bin/controller-gen $(TYPES) ./hack/manifests/crdgen.sh ./hack/manifests/crds.go
430+
manifests/base/crds/full/argoproj.io_workflows.yaml: $(TOOL_CONTROLLER_GEN) $(TYPES) ./hack/manifests/crdgen.sh ./hack/manifests/crds.go
409431
./hack/manifests/crdgen.sh
410432

411433
.PHONY: manifests
@@ -451,11 +473,11 @@ dist/manifests/%: manifests/%
451473
manifests-validate:
452474
kubectl apply --server-side --validate=strict --dry-run=server -f 'manifests/*.yaml'
453475

454-
$(GOPATH)/bin/golangci-lint: Makefile
476+
$(TOOL_GOLANGCI_LINT): Makefile
455477
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b `go env GOPATH`/bin v1.61.0
456478

457479
.PHONY: lint
458-
lint: ui/dist/app/index.html $(GOPATH)/bin/golangci-lint
480+
lint: ui/dist/app/index.html $(TOOL_GOLANGCI_LINT)
459481
rm -Rf v3 vendor
460482
# If you're using `woc.wf.Spec` or `woc.execWf.Status` your code probably won't work with WorkflowTemplate.
461483
# * Change `woc.wf.Spec` to `woc.execWf.Spec`.
@@ -464,7 +486,7 @@ lint: ui/dist/app/index.html $(GOPATH)/bin/golangci-lint
464486
# Tidy Go modules
465487
go mod tidy
466488
# Lint Go files
467-
$(GOPATH)/bin/golangci-lint run --fix --verbose
489+
$(TOOL_GOLANGCI_LINT) run --fix --verbose
468490
# Lint the UI
469491
if [ -e ui/node_modules ]; then yarn --cwd ui lint ; fi
470492
# Deduplicate Node modules
@@ -631,10 +653,10 @@ util/telemetry/attributes.go: $(TELEMETRY_BUILDER) util/telemetry/builder/values
631653
go run ./util/telemetry/builder --attributesGo $@
632654

633655
# swagger
634-
pkg/apis/workflow/v1alpha1/openapi_generated.go: $(GOPATH)/bin/openapi-gen $(TYPES)
656+
pkg/apis/workflow/v1alpha1/openapi_generated.go: $(TOOL_OPENAPI_GEN) $(TYPES)
635657
# These files are generated on a v3/ folder by the tool. Link them to the root folder
636658
[ -e ./v3 ] || ln -s . v3
637-
$(GOPATH)/bin/openapi-gen \
659+
$(TOOL_OPENAPI_GEN) \
638660
--go-header-file ./hack/custom-boilerplate.go.txt \
639661
--input-dirs github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1 \
640662
--output-package github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1 \
@@ -647,7 +669,7 @@ pkg/apis/workflow/v1alpha1/openapi_generated.go: $(GOPATH)/bin/openapi-gen $(TYP
647669

648670
# generates many other files (listers, informers, client etc).
649671
.PRECIOUS: pkg/apis/workflow/v1alpha1/zz_generated.deepcopy.go
650-
pkg/apis/workflow/v1alpha1/zz_generated.deepcopy.go: $(GOPATH)/bin/go-to-protobuf $(TYPES)
672+
pkg/apis/workflow/v1alpha1/zz_generated.deepcopy.go: $(TOOL_GO_TO_PROTOBUF) $(TYPES)
651673
# These files are generated on a v3/ folder by the tool. Link them to the root folder
652674
[ -e ./v3 ] || ln -s . v3
653675
bash $(GOPATH)/pkg/mod/k8s.io/[email protected]/generate-groups.sh \
@@ -672,10 +694,10 @@ pkg/apiclient/_.secondary.swagger.json: hack/api/swagger/secondaryswaggergen.go
672694
go run ./hack/api/swagger secondaryswaggergen
673695

674696
# we always ignore the conflicts, so lets automated figuring out how many there will be and just use that
675-
dist/swagger-conflicts: $(GOPATH)/bin/swagger $(SWAGGER_FILES)
697+
dist/swagger-conflicts: $(TOOL_SWAGGER) $(SWAGGER_FILES)
676698
swagger mixin $(SWAGGER_FILES) 2>&1 | grep -c skipping > dist/swagger-conflicts || true
677699

678-
dist/mixed.swagger.json: $(GOPATH)/bin/swagger $(SWAGGER_FILES) dist/swagger-conflicts
700+
dist/mixed.swagger.json: $(TOOL_SWAGGER) $(SWAGGER_FILES) dist/swagger-conflicts
679701
swagger mixin -c $(shell cat dist/swagger-conflicts) $(SWAGGER_FILES) -o dist/mixed.swagger.json
680702

681703
dist/swaggifed.swagger.json: dist/mixed.swagger.json hack/api/swagger/swaggify.sh
@@ -684,11 +706,11 @@ dist/swaggifed.swagger.json: dist/mixed.swagger.json hack/api/swagger/swaggify.s
684706
dist/kubeified.swagger.json: dist/swaggifed.swagger.json dist/kubernetes.swagger.json
685707
go run ./hack/api/swagger kubeifyswagger dist/swaggifed.swagger.json dist/kubeified.swagger.json
686708

687-
dist/swagger.0.json: $(GOPATH)/bin/swagger dist/kubeified.swagger.json
688-
swagger flatten --with-flatten minimal --with-flatten remove-unused dist/kubeified.swagger.json -o dist/swagger.0.json
709+
dist/swagger.0.json: $(TOOL_SWAGGER) dist/kubeified.swagger.json
710+
$(TOOL_SWAGGER) flatten --with-flatten minimal --with-flatten remove-unused dist/kubeified.swagger.json -o dist/swagger.0.json
689711

690-
api/openapi-spec/swagger.json: $(GOPATH)/bin/swagger dist/swagger.0.json
691-
swagger flatten --with-flatten remove-unused dist/swagger.0.json -o api/openapi-spec/swagger.json
712+
api/openapi-spec/swagger.json: $(TOOL_SWAGGER) dist/swagger.0.json
713+
$(TOOL_SWAGGER) flatten --with-flatten remove-unused dist/swagger.0.json -o api/openapi-spec/swagger.json
692714

693715
api/jsonschema/schema.json: api/openapi-spec/swagger.json hack/api/jsonschema/main.go
694716
go run ./hack/api/jsonschema
@@ -709,50 +731,51 @@ docs/cli/argo.md: $(CLI_PKG_FILES) go.sum ui/dist/app/index.html hack/docs/cli.g
709731

710732
# docs
711733

712-
/usr/local/bin/mdspell: Makefile
734+
$(TOOL_MDSPELL): Makefile
713735
# update this in Nix when upgrading it here
714736
ifneq ($(USE_NIX), true)
715737
npm list -g [email protected] > /dev/null || npm i -g [email protected]
716738
endif
717739

718740
.PHONY: docs-spellcheck
719-
docs-spellcheck: /usr/local/bin/mdspell docs/metrics.md
741+
docs-spellcheck: $(TOOL_MDSPELL) docs/metrics.md
720742
# check docs for spelling mistakes
721-
mdspell --ignore-numbers --ignore-acronyms --en-us --no-suggestions --report $(shell find docs -name '*.md' -not -name upgrading.md -not -name README.md -not -name fields.md -not -name upgrading.md -not -name executor_swagger.md -not -path '*/cli/*' -not -name tested-kubernetes-versions.md)
743+
$(TOOL_MDSPELL) --ignore-numbers --ignore-acronyms --en-us --no-suggestions --report $(shell find docs -name '*.md' -not -name upgrading.md -not -name README.md -not -name fields.md -not -name upgrading.md -not -name executor_swagger.md -not -path '*/cli/*' -not -name tested-kubernetes-versions.md)
722744
# alphabetize spelling file -- ignore first line (comment), then sort the rest case-sensitive and remove duplicates
723745
$(shell cat .spelling | awk 'NR<2{ print $0; next } { print $0 | "LC_COLLATE=C sort" }' | uniq | tee .spelling > /dev/null)
724746

725-
/usr/local/bin/markdown-link-check:
747+
$(TOOL_MARKDOWN_LINK_CHECK): Makefile
726748
# update this in Nix when upgrading it here
727749
ifneq ($(USE_NIX), true)
728750
npm list -g [email protected] > /dev/null || npm i -g [email protected]
729751
endif
730752

731753
.PHONY: docs-linkcheck
732-
docs-linkcheck: /usr/local/bin/markdown-link-check
754+
docs-linkcheck: $(TOOL_MARKDOWN_LINK_CHECK)
733755
# check docs for broken links
734-
markdown-link-check -q -c .mlc_config.json $(shell find docs -name '*.md' -not -name fields.md -not -name executor_swagger.md)
756+
$(TOOL_MARKDOWN_LINK_CHECK) -q -c .mlc_config.json $(shell find docs -name '*.md' -not -name fields.md -not -name executor_swagger.md)
735757

736-
/usr/local/bin/markdownlint:
758+
$(TOOL_MARKDOWNLINT): Makefile
737759
# update this in Nix when upgrading it here
738760
ifneq ($(USE_NIX), true)
739761
npm list -g [email protected] > /dev/null || npm i -g [email protected]
740762
endif
741763

742764

743765
.PHONY: docs-lint
744-
docs-lint: /usr/local/bin/markdownlint docs/metrics.md
766+
docs-lint: $(TOOL_MARKDOWNLINT) docs/metrics.md
745767
# lint docs
746-
markdownlint docs --fix --ignore docs/fields.md --ignore docs/executor_swagger.md --ignore docs/cli --ignore docs/walk-through/the-structure-of-workflow-specs.md --ignore docs/tested-kubernetes-versions.md
768+
$(TOOL_MARKDOWNLINT) docs --fix --ignore docs/fields.md --ignore docs/executor_swagger.md --ignore docs/cli --ignore docs/walk-through/the-structure-of-workflow-specs.md --ignore docs/tested-kubernetes-versions.md
747769

748-
/usr/local/bin/mkdocs:
770+
$(TOOL_MKDOCS): docs/requirements.txt
749771
# update this in Nix when upgrading it here
750772
ifneq ($(USE_NIX), true)
751-
python -m pip install --no-cache-dir -r docs/requirements.txt
773+
python3 -m venv $(TOOL_MKDOCS_DIR)
774+
$(TOOL_MKDOCS_DIR)/bin/pip install --no-cache-dir -r $<
752775
endif
753776

754777
.PHONY: docs
755-
docs: /usr/local/bin/mkdocs \
778+
docs: $(TOOL_MKDOCS) \
756779
docs-spellcheck \
757780
docs-lint \
758781
# TODO: This is temporarily disabled to unblock merging PRs.
@@ -765,13 +788,13 @@ docs: /usr/local/bin/mkdocs \
765788
ifeq ($(shell echo $(GIT_BRANCH) | head -c 8),release-)
766789
./hack/docs/tested-versions.sh > docs/tested-kubernetes-versions.md
767790
endif
768-
TZ=UTC mkdocs build --strict
791+
TZ=UTC $(TOOL_MKDOCS) build --strict
769792
# tell the user the fastest way to edit docs
770793
@echo "ℹ️ If you want to preview your docs, open site/index.html. If you want to edit them with hot-reload, run 'make docs-serve' to start mkdocs on port 8000"
771794

772795
.PHONY: docs-serve
773796
docs-serve: docs
774-
mkdocs serve
797+
$(TOOL_MKDOCS) serve
775798

776799
# pre-commit checks
777800

docs/requirements.txt

+2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
mkdocs-material==9.*
22
mkdocs-redirects==1.*
3+
# Update pymdown-extensions whenever needed, not pinned to anything important
4+
pymdown-extensions==10.*

0 commit comments

Comments
 (0)