Skip to content

Commit

Permalink
Backport of add make target script into release/1.2.x (#3600)
Browse files Browse the repository at this point in the history
backport of commit 24f69ca

Co-authored-by: Michael Wilkerson <mwilkerson@hashicorp.com>
  • Loading branch information
1 parent c84c5a9 commit 58a3ee0
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,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
Expand Down
33 changes: 33 additions & 0 deletions control-plane/build-support/scripts/mod_tidy.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 58a3ee0

Please sign in to comment.