2017-02-13 19:01:54 +00:00
|
|
|
#!/usr/bin/env bash
|
2016-01-07 18:57:15 +00:00
|
|
|
|
2022-11-14 21:56:53 +00:00
|
|
|
set -e
|
|
|
|
|
2022-08-26 16:31:23 +00:00
|
|
|
SCRIPTDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
2016-10-12 19:25:49 +00:00
|
|
|
source "${SCRIPTDIR}/.validate"
|
2016-01-07 18:57:15 +00:00
|
|
|
|
2022-11-14 21:56:53 +00:00
|
|
|
tidy_files=('vendor.mod' 'vendor.sum')
|
|
|
|
vendor_files=("${tidy_files[@]}" 'vendor/')
|
|
|
|
|
|
|
|
validate_vendor_tidy() {
|
|
|
|
# run mod tidy
|
|
|
|
./hack/vendor.sh tidy
|
|
|
|
# check if any files have changed
|
|
|
|
git diff --quiet HEAD -- "${tidy_files[@]}"
|
|
|
|
}
|
|
|
|
|
2022-08-26 16:31:23 +00:00
|
|
|
validate_vendor_diff() {
|
2022-11-14 21:56:53 +00:00
|
|
|
mapfile -t changed_files < <(validate_diff --diff-filter=ACMR --name-only -- "${vendor_files[@]}")
|
2016-01-07 18:57:15 +00:00
|
|
|
|
2021-12-15 19:35:04 +00:00
|
|
|
if [ -n "${TEST_FORCE_VALIDATE:-}" ] || [ "${#changed_files[@]}" -gt 0 ]; then
|
2018-08-28 19:53:33 +00:00
|
|
|
# recreate vendor/
|
2022-11-14 21:56:53 +00:00
|
|
|
./hack/vendor.sh vendor
|
2018-02-02 18:43:36 +00:00
|
|
|
# check if any files have changed
|
2022-11-14 21:56:53 +00:00
|
|
|
git diff --quiet HEAD -- "${vendor_files[@]}"
|
2016-01-07 18:57:15 +00:00
|
|
|
else
|
2022-11-14 22:20:01 +00:00
|
|
|
echo >&2 'INFO: no vendor changes in diff; skipping vendor check.'
|
2016-01-07 18:57:15 +00:00
|
|
|
fi
|
2017-02-16 07:22:24 +00:00
|
|
|
}
|
|
|
|
|
2022-11-14 21:56:53 +00:00
|
|
|
validate_vendor_license() {
|
2022-11-14 22:20:01 +00:00
|
|
|
while IFS= read -r module; do
|
|
|
|
test -d "vendor/$module" || continue
|
|
|
|
if ! compgen -G "vendor/$module/*" | grep -qEi '/(LICENSE|COPYING)[^/]*$'; then
|
|
|
|
echo >&2 "WARNING: could not find copyright information for $module"
|
2018-02-02 18:43:36 +00:00
|
|
|
fi
|
2022-11-14 22:20:01 +00:00
|
|
|
done < <(awk '/^# /{ print $2 }' vendor/modules.txt)
|
2017-02-16 07:22:24 +00:00
|
|
|
}
|
|
|
|
|
2022-11-14 21:56:53 +00:00
|
|
|
if validate_vendor_tidy && validate_vendor_diff && validate_vendor_license; then
|
2022-11-14 22:20:01 +00:00
|
|
|
echo >&2 'PASS: Vendoring has been performed correctly!'
|
2022-11-14 21:56:53 +00:00
|
|
|
else
|
|
|
|
{
|
2022-11-14 22:20:01 +00:00
|
|
|
echo 'FAIL: Vendoring was not performed correctly!'
|
|
|
|
echo
|
|
|
|
echo 'The following files changed during re-vendor:'
|
2022-11-14 21:56:53 +00:00
|
|
|
echo
|
|
|
|
git diff --name-status HEAD -- "${vendor_files[@]}"
|
|
|
|
echo
|
|
|
|
echo 'Please revendor with hack/vendor.sh'
|
|
|
|
echo
|
|
|
|
git diff --diff-filter=M -- "${vendor_files[@]}"
|
|
|
|
} >&2
|
|
|
|
exit 1
|
|
|
|
fi
|