diff --git a/devtools/check_go_mod_tidy.sh b/devtools/check_go_mod_tidy.sh new file mode 100644 index 0000000000..66bff81250 --- /dev/null +++ b/devtools/check_go_mod_tidy.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Helper script to check whether `go mod tidy` introduces changes. + +ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +cd "${ROOT_DIR}" + +if [ ! -f go.mod ]; then + echo "go.mod not found in repository root." + exit 1 +fi + +echo "Running go mod tidy (dry check)..." + +# Save a snapshot of go.mod and go.sum +cp go.mod /tmp/go.mod.before +cp go.sum /tmp/go.sum.before + +go mod tidy + +changed= +if ! diff -q go.mod /tmp/go.mod.before >/dev/null 2>&1; then + changed=1 +fi + +if ! diff -q go.sum /tmp/go.sum.before >/dev/null 2>&1; then + changed=1 +fi + +if [ -n "${changed}" ]; then + echo "⚠️ go mod tidy introduced changes." + echo "Please review and commit them if appropriate." +else + echo "✅ go mod tidy did not change go.mod or go.sum." +fi + +# Restore original files to avoid modifying the working tree. +mv /tmp/go.mod.before go.mod +mv /tmp/go.sum.before go.sum