Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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