From 73d45032a6189d8b6c54067ec08e20733b089611 Mon Sep 17 00:00:00 2001 From: Michael Zalimeni Date: Thu, 30 Nov 2023 12:28:09 -0500 Subject: [PATCH] make: Add target for updating dependencies across all modules 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. --- Makefile | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Makefile b/Makefile index 34aeeba1d8..385cfb9b18 100644 --- a/Makefile +++ b/Makefile @@ -236,6 +236,19 @@ go-mod-tidy/%: @echo "--> Running go mod tidy ($*)" @cd $* && go mod tidy +.PHONY: go-mod-get +go-mod-get: $(foreach mod,$(GO_MODULES),go-mod-get/$(mod)) ## Run go get and 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 @, 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 + ##@ Checks .PHONY: fmt