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'
|
2020-07-15 07:45:41 -04:00
|
|
|
# shellcheck disable=SC2207
|
2017-02-16 02:22:24 -05:00
|
|
|
files=( $(validate_diff --diff-filter=ACMR --name-only -- 'vendor.conf' 'vendor/' || true) )
|
|
|
|
unset IFS
|
2016-01-07 13:57:15 -05:00
|
|
|
|
2019-10-07 09:20:03 -04:00
|
|
|
if [ -n "${TEST_FORCE_VALIDATE:-}" ] || [ ${#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
|
2017-02-16 02:22:24 -05:00
|
|
|
diffs="$(git status --porcelain -- vendor 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
|
|
|
{
|
|
|
|
echo 'The result of vndr differs'
|
|
|
|
echo
|
|
|
|
echo "$diffs"
|
|
|
|
echo
|
|
|
|
echo 'Please vendor your package with github.com/LK4D4/vndr.'
|
|
|
|
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() {
|
2019-10-29 13:53:46 -04:00
|
|
|
for f in $(mawk '/^[a-zA-Z0-9]/ { print $1 }' vendor.conf); do
|
|
|
|
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
|
|
|
else
|
2018-02-02 13:43:36 -05:00
|
|
|
echo "WARNING: $f is vendored but unused"
|
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
|