Skip to content

Commit

Permalink
make: Add target for updating dependencies across all modules
Browse files Browse the repository at this point in the history
To enable more consistent and error-proof dependency management, add a
Make target that will set a dependency version across all submodules
that require it.

Also runs `go mod tidy`. This first ensures the dependency addition is
reverted if the module in question does not require it; it also ensures
that any additional cleanup needed in `go.mod`/`go.sum` is applied.
  • Loading branch information
zalimeni committed Feb 21, 2024
1 parent 6256298 commit 44583d3
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ KIND_VERSION= $(shell ./control-plane/build-support/scripts/read-yaml-config.sh
KIND_NODE_IMAGE= $(shell ./control-plane/build-support/scripts/read-yaml-config.sh acceptance/ci-inputs/kind-inputs.yaml .kindNodeImage)
KUBECTL_VERSION= $(shell ./control-plane/build-support/scripts/read-yaml-config.sh acceptance/ci-inputs/kind-inputs.yaml .kubectlVersion)

GO_MODULES := $(shell find . -name go.mod -exec dirname {} \; | sort)

##@ Helm Targets

.PHONY: gen-helm-docs
Expand Down Expand Up @@ -317,6 +319,19 @@ go-mod-tidy: ## Recursively run go mod tidy on all subdirectories
check-mod-tidy: ## Recursively run go mod tidy on all subdirectories and check if there are any changes
@./control-plane/build-support/scripts/mod_tidy.sh --check

.PHONY: go-mod-get
go-mod-get: $(foreach mod,$(GO_MODULES),go-mod-get/$(mod)) ## Run go get and go mod tidy in every module for the given dependency

.PHONY: go-mod-get/%
go-mod-get/%:
ifndef DEP_VERSION
$(error DEP_VERSION is undefined: set this to <dependency>@<version>, e.g. github.com/hashicorp/go-hclog@v1.5.0)
endif
@echo "--> Running go get ${DEP_VERSION} ($*)"
@cd $* && go get $(DEP_VERSION)
@echo "--> Running go mod tidy ($*)"
@cd $* && go mod tidy

##@ Release Targets

.PHONY: check-env
Expand Down

0 comments on commit 44583d3

Please sign in to comment.