Skip to content

Commit

Permalink
build: Simplify/improve verify-vendor.sh
Browse files Browse the repository at this point in the history
`verify-vendor.sh` compares the content of the `vendor` directory after
running `make vendor` with a copy which was made before running `make
vendor`.
This does not catch changes to go.mod/go.sum made by `go mod tidy` which
we forgot to commit.

This commit uses `git diff --exit-code` instead of running `diff` against the
vendor directory.

This will catch all uncommitted changes, which should be fine when `make
vendorcheck` is run.

Using `git diff` instead of `diff` allows to remove quite some code from
`verify-vendor.sh`

This fixes crc-org#4133
  • Loading branch information
cfergeau authored and praveenkumar committed May 7, 2024
1 parent 9aa3b58 commit 02fcdb5
Showing 1 changed file with 6 additions and 23 deletions.
29 changes: 6 additions & 23 deletions verify-vendor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,22 @@ set -o pipefail

export GO111MODULE=on

readonly REPO_ROOT_DIR="$(git rev-parse --show-toplevel 2> /dev/null)"
readonly TMP_DIFFROOT="$(mktemp -d "${REPO_ROOT_DIR}"/tmpdiffroot.XXXXXX)"

cleanup() {
rm -rf "${TMP_DIFFROOT}"
}

trap "cleanup" EXIT SIGINT

cleanup

if [[ -n $(git status -s vendor/) ]]; then
echo 'vendor/ directory has uncommitted changes, please check `git status vendor`'
exit 1
fi

mkdir "${TMP_DIFFROOT}"
cp -aR "${REPO_ROOT_DIR}/vendor" "${TMP_DIFFROOT}"

make vendor

echo "Diffing ${REPO_ROOT_DIR} against freshly generated codegen"
ret=0
diff --strip-trailing-cr -Naupr "${REPO_ROOT_DIR}/vendor" "${TMP_DIFFROOT}/vendor" || ret=1
go mod verify

# Restore working tree state
rm -fr "${REPO_ROOT_DIR}/vendor"
cp -aR "${TMP_DIFFROOT}"/* "${REPO_ROOT_DIR}"
echo "Diffing $(pwd)"
git diff --exit-code vendor go.mod go.sum

if [[ $ret -eq 0 ]]
if [[ $? -eq 0 ]]
then
echo "${REPO_ROOT_DIR} up to date."
echo "$(pwd) up to date."
else
echo "${REPO_ROOT_DIR} is out of date. Please run make vendor"
echo "$(pwd) is out of date. Please run make vendor"
exit 1
fi

0 comments on commit 02fcdb5

Please sign in to comment.