From 24f69caf0071ec3c0c13cca524d5e16b668e4dfb Mon Sep 17 00:00:00 2001 From: Michael Wilkerson Date: Fri, 9 Feb 2024 06:47:00 -0800 Subject: [PATCH] add make target script --- Makefile | 8 +++++ .../build-support/scripts/mod_tidy.sh | 33 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100755 control-plane/build-support/scripts/mod_tidy.sh diff --git a/Makefile b/Makefile index 2e5d465318..a3ee7da944 100644 --- a/Makefile +++ b/Makefile @@ -309,6 +309,14 @@ eks-test-packages: ## eks test packages aks-test-packages: ## aks test packages @./control-plane/build-support/scripts/set_test_package_matrix.sh "acceptance/ci-inputs/aks_acceptance_test_packages.yaml" +.PHONY: go-mod-tidy +go-mod-tidy: ## Recursively run go mod tidy on all subdirectories + @./control-plane/build-support/scripts/mod_tidy.sh + +.PHONY: check-mod-tidy +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 + ##@ Release Targets .PHONY: check-env diff --git a/control-plane/build-support/scripts/mod_tidy.sh b/control-plane/build-support/scripts/mod_tidy.sh new file mode 100755 index 0000000000..467ed55aa6 --- /dev/null +++ b/control-plane/build-support/scripts/mod_tidy.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +CHECK=false + +# Check if the --check argument is passed +for arg in "$@" +do + if [ "$arg" == "--check" ] + then + CHECK=true + fi +done + +# Find directories containing a go.mod file +for dir in $(find . -type f -name go.mod -exec dirname {} \;); do + # Change into the directory + cd "$dir" || exit + + # Run go mod tidy + echo "Running go mod tidy in $dir" + go mod tidy + + # Change back to the original directory + cd - || exit +done + +# Check for differences if the --check argument was passed +if [ "$CHECK" = true ]; then + if [[ -n "$(git status --porcelain)" ]]; then + echo "differences were found in go.mod or go.sum, run go mod tidy to fix them" + exit 1 + fi +fi \ No newline at end of file