diff --git a/.github/scripts/go-mod-tidy-check.sh b/.github/scripts/go-mod-tidy-check.sh index 2a9c3ca4..41bc6391 100755 --- a/.github/scripts/go-mod-tidy-check.sh +++ b/.github/scripts/go-mod-tidy-check.sh @@ -1,19 +1,13 @@ #!/usr/bin/env bash set -eu -BACKUPS_DIR=$(mktemp -d "TEMP-backups-XXXXXXXXX") -GIT_HEAD_STATE_DIR=$(mktemp -d "TEMP-git-head-state-XXXXXXXXX") +ORIGINAL_STATE_DIR=$(mktemp -d "TEMP-original-state-XXXXXXXXX") TIDY_STATE_DIR=$(mktemp -d "TEMP-tidy-state-XXXXXXXXX") -trap "cp -v ${BACKUPS_DIR}/* ./ && rm -fR ${BACKUPS_DIR} ${GIT_HEAD_STATE_DIR} ${TIDY_STATE_DIR}" EXIT +trap "cp -v ${ORIGINAL_STATE_DIR}/* ./ && rm -fR ${ORIGINAL_STATE_DIR} ${TIDY_STATE_DIR}" EXIT -echo "Backing up files from working tree..." -cp -v go.mod go.sum "${BACKUPS_DIR}" - -echo "Capturing state of go.mod and go.sum from git HEAD..." -git checkout go.mod go.sum -cp -v go.mod go.sum "${GIT_HEAD_STATE_DIR}" -echo "" +echo "Capturing original state of files..." +cp -v go.mod go.sum "${ORIGINAL_STATE_DIR}" echo "Capturing state of go.mod and go.sum after running go mod tidy..." go mod tidy @@ -23,8 +17,8 @@ echo "" set +e # Detect difference between the git HEAD state and the go mod tidy state -DIFF_MOD=$(diff -u "${GIT_HEAD_STATE_DIR}/go.mod" "${TIDY_STATE_DIR}/go.mod") -DIFF_SUM=$(diff -u "${GIT_HEAD_STATE_DIR}/go.sum" "${TIDY_STATE_DIR}/go.sum") +DIFF_MOD=$(diff -u "${ORIGINAL_STATE_DIR}/go.mod" "${TIDY_STATE_DIR}/go.mod") +DIFF_SUM=$(diff -u "${ORIGINAL_STATE_DIR}/go.sum" "${TIDY_STATE_DIR}/go.sum") if [[ -n "${DIFF_MOD}" || -n "${DIFF_SUM}" ]]; then echo "go.mod diff:" @@ -32,6 +26,6 @@ if [[ -n "${DIFF_MOD}" || -n "${DIFF_SUM}" ]]; then echo "go.sum diff:" echo "${DIFF_SUM}" echo "" - printf "FAILED! go.mod and/or go.sum are NOT tidy on current git head; please run 'go mod tidy' and commit the change.\n\n" + printf "FAILED! go.mod and/or go.sum are NOT tidy; please run 'go mod tidy'.\n\n" exit 1 fi