Skip to content

Commit

Permalink
scripts: simplify mod tidy pass
Browse files Browse the repository at this point in the history
The original go mod tidy pass implementation was done before the `--diff`
go mod option existed. This simplifies the implementation, as temporary
files are no longer needed.

Signed-off-by: Ivan Valdes <[email protected]>
  • Loading branch information
ivanvc committed Dec 11, 2024
1 parent 3cf550d commit 9d8f2fa
Showing 1 changed file with 2 additions and 25 deletions.
27 changes: 2 additions & 25 deletions scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -628,34 +628,11 @@ function release_pass {
}

function mod_tidy_for_module {
# Watch for upstream solution: https://github.com/golang/go/issues/27005
local tmpModDir
tmpModDir=$(mktemp -d -t 'tmpModDir.XXXXXX')
run cp "./go.mod" "${tmpModDir}" || return 2

# Guarantees keeping go.sum minimal
# If this is causing too much problems, we should
# stop controlling go.sum at all.
rm go.sum
run go mod tidy || return 2

set +e
local tmpFileGoModInSync
diff -C 5 "${tmpModDir}/go.mod" "./go.mod"
tmpFileGoModInSync="$?"

# Bring back initial state
mv "${tmpModDir}/go.mod" "./go.mod"

if [ "${tmpFileGoModInSync}" -ne 0 ]; then
log_error "${PWD}/go.mod is not in sync with 'go mod tidy'"
return 255
fi
set -e
run go mod tidy -diff
}

function mod_tidy_pass {
run_for_modules mod_tidy_for_module
run_for_modules generic_checker mod_tidy_for_module
}

function proto_annotations_pass {
Expand Down

0 comments on commit 9d8f2fa

Please sign in to comment.