2017-02-13 19:01:54 +00:00
|
|
|
#!/usr/bin/env bash
|
2016-01-07 18:57:15 +00:00
|
|
|
|
2019-10-29 02:24:17 +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
|
|
|
|
2017-02-16 07:22:24 +00:00
|
|
|
validate_vendor_diff(){
|
|
|
|
IFS=$'\n'
|
2020-07-15 11:45:41 +00:00
|
|
|
# shellcheck disable=SC2207
|
2017-02-16 07:22:24 +00:00
|
|
|
files=( $(validate_diff --diff-filter=ACMR --name-only -- 'vendor.conf' 'vendor/' || true) )
|
|
|
|
unset IFS
|
2016-01-07 18:57:15 +00:00
|
|
|
|
2019-10-07 13:20:03 +00:00
|
|
|
if [ -n "${TEST_FORCE_VALIDATE:-}" ] || [ ${#files[@]} -gt 0 ]; then
|
2018-08-28 19:53:33 +00:00
|
|
|
# recreate vendor/
|
2020-07-15 11:45:41 +00:00
|
|
|
./hack/vendor.sh
|
2018-02-02 18:43:36 +00:00
|
|
|
# check if any files have changed
|
2017-02-16 07:22:24 +00:00
|
|
|
diffs="$(git status --porcelain -- vendor 2>/dev/null)"
|
2019-10-29 02:18:23 +00:00
|
|
|
mfiles="$(echo "$diffs" | awk '/^ M / {print $2}')"
|
2019-01-10 01:23:38 +00:00
|
|
|
if [ "$diffs" ]; then
|
2017-02-16 07:22:24 +00:00
|
|
|
{
|
|
|
|
echo 'The result of vndr differs'
|
|
|
|
echo
|
|
|
|
echo "$diffs"
|
|
|
|
echo
|
|
|
|
echo 'Please vendor your package with github.com/LK4D4/vndr.'
|
|
|
|
echo
|
2019-10-29 02:18:23 +00:00
|
|
|
if [ -n "$mfiles" ] ; then
|
|
|
|
git diff -- "$mfiles"
|
|
|
|
fi
|
2017-02-16 07:22:24 +00:00
|
|
|
} >&2
|
|
|
|
false
|
|
|
|
else
|
|
|
|
echo 'Congratulations! All vendoring changes are done the right way.'
|
|
|
|
fi
|
2016-01-07 18:57:15 +00:00
|
|
|
else
|
2017-02-16 07:22:24 +00:00
|
|
|
echo 'No vendor changes in diff.'
|
2016-01-07 18:57:15 +00:00
|
|
|
fi
|
2017-02-16 07:22:24 +00: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 17:53:46 +00:00
|
|
|
for f in $(mawk '/^[a-zA-Z0-9]/ { print $1 }' vendor.conf); do
|
|
|
|
if [ -d "vendor/$f" ]; then
|
2020-02-10 13:36:22 +00:00
|
|
|
if ! echo "vendor/$f"/* | grep -qiEc '/(LICENSE|COPYING)'; then
|
2017-02-16 07:22:24 +00:00
|
|
|
echo "WARNING: could not find copyright information for $f"
|
2018-02-02 18:43:36 +00:00
|
|
|
fi
|
2017-02-16 07:22:24 +00:00
|
|
|
else
|
2018-02-02 18:43:36 +00:00
|
|
|
echo "WARNING: $f is vendored but unused"
|
2017-02-16 07:22:24 +00:00
|
|
|
fi
|
2018-02-02 18:43:36 +00:00
|
|
|
done
|
2017-02-16 07:22:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
validate_vendor_diff
|
|
|
|
validate_vendor_used
|