Skip to content

Commit

Permalink
add make target script (#3596)
Browse files Browse the repository at this point in the history
add new make target for go mod tidy check
  • Loading branch information
wilkermichael authored Feb 9, 2024
1 parent 4600d5d commit a0a282e
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 @@ -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
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 a0a282e

Please sign in to comment.