From 02fcdb534691efe5878a7476bdb864caa9a3f2b9 Mon Sep 17 00:00:00 2001 From: Christophe Fergeau Date: Tue, 30 Apr 2024 10:23:59 +0200 Subject: [PATCH] build: Simplify/improve verify-vendor.sh `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 https://github.com/crc-org/crc/issues/4133 --- verify-vendor.sh | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/verify-vendor.sh b/verify-vendor.sh index 8820708188..131a17889f 100755 --- a/verify-vendor.sh +++ b/verify-vendor.sh @@ -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