Skip to content

Commit

Permalink
Merge 24f69ca into backport/mw/add-go-mod-check-ci/precisely-useful-w…
Browse files Browse the repository at this point in the history
…oodcock
  • Loading branch information
hc-github-team-consul-core authored Feb 9, 2024
2 parents b9a533e + 24f69ca commit b5f6c58
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 b5f6c58

Please sign in to comment.