2017-02-13 14:01:54 -05:00
|
|
|
#!/usr/bin/env bash
|
2016-01-07 13:57:15 -05:00
|
|
|
|
2019-10-28 22:24:17 -04:00
|
|
|
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
2016-10-12 15:25:49 -04:00
|
|
|
source "${SCRIPTDIR}/.validate"
|
2016-01-07 13:57:15 -05:00
|
|
|
|
2017-02-16 02:22:24 -05:00
|
|
|
validate_vendor_diff(){
|
|
|
|
IFS=$'\n'
|
2021-12-15 14:35:04 -05:00
|
|
|
check_files=( 'vendor.sum' 'vendor.mod' 'vendor/' )
|
2020-07-15 07:45:41 -04:00
|
|
|
# shellcheck disable=SC2207
|
2021-12-15 14:35:04 -05:00
|
|
|
changed_files=( $(validate_diff --diff-filter=ACMR --name-only -- "${check_files[@]}" || true) )
|
2017-02-16 02:22:24 -05:00
|
|
|
unset IFS
|
2016-01-07 13:57:15 -05:00
|
|
|
|
2021-12-15 14:35:04 -05:00
|
|
|
if [ -n "${TEST_FORCE_VALIDATE:-}" ] || [ "${#changed_files[@]}" -gt 0 ]; then
|
2018-08-28 15:53:33 -04:00
|
|
|
# recreate vendor/
|
2020-07-15 07:45:41 -04:00
|
|
|
./hack/vendor.sh
|
2018-02-02 13:43:36 -05:00
|
|
|
# check if any files have changed
|
2021-12-15 14:35:04 -05:00
|
|
|
diffs="$(git status --porcelain -- "${check_files[@]}" 2>/dev/null)"
|
2019-10-28 22:18:23 -04:00
|
|
|
mfiles="$(echo "$diffs" | awk '/^ M / {print $2}')"
|
2019-01-09 20:23:38 -05:00
|
|
|
if [ "$diffs" ]; then
|
2017-02-16 02:22:24 -05:00
|
|
|
{
|
2021-12-15 14:35:04 -05:00
|
|
|
echo 'The result of go mod vendor differs'
|
2017-02-16 02:22:24 -05:00
|
|
|
echo
|
|
|
|
echo "$diffs"
|
|
|
|
echo
|
2021-07-13 12:45:07 -04:00
|
|
|
echo 'Please vendor your package with hack/vendor.sh.'
|
2017-02-16 02:22:24 -05:00
|
|
|
echo
|
2019-10-28 22:18:23 -04:00
|
|
|
if [ -n "$mfiles" ] ; then
|
|
|
|
git diff -- "$mfiles"
|
|
|
|
fi
|
2017-02-16 02:22:24 -05:00
|
|
|
} >&2
|
|
|
|
false
|
|
|
|
else
|
|
|
|
echo 'Congratulations! All vendoring changes are done the right way.'
|
|
|
|
fi
|
2016-01-07 13:57:15 -05:00
|
|
|
else
|
2017-02-16 02:22:24 -05:00
|
|
|
echo 'No vendor changes in diff.'
|
2016-01-07 13:57:15 -05:00
|
|
|
fi
|
2017-02-16 02:22:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
# 1. make sure all the vendored packages are used
|
|
|
|
# 2. make sure all the packages contain license information (just warning, because it can cause false-positive)
|
|
|
|
validate_vendor_used() {
|
2021-12-15 14:35:04 -05:00
|
|
|
for f in $(mawk '$1 = "#" { print $2 }' 'vendor/modules.txt'); do
|
2019-10-29 13:53:46 -04:00
|
|
|
if [ -d "vendor/$f" ]; then
|
2020-02-10 08:36:22 -05:00
|
|
|
if ! echo "vendor/$f"/* | grep -qiEc '/(LICENSE|COPYING)'; then
|
2017-02-16 02:22:24 -05:00
|
|
|
echo "WARNING: could not find copyright information for $f"
|
2018-02-02 13:43:36 -05:00
|
|
|
fi
|
2017-02-16 02:22:24 -05:00
|
|
|
fi
|
2018-02-02 13:43:36 -05:00
|
|
|
done
|
2017-02-16 02:22:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
validate_vendor_diff
|
|
|
|
validate_vendor_used
|