2017-02-13 14:01:54 -05:00
|
|
|
#!/usr/bin/env bash
|
2016-01-07 13:57:15 -05:00
|
|
|
|
2016-10-12 15:25:49 -04:00
|
|
|
export SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
|
|
source "${SCRIPTDIR}/.validate"
|
2016-01-07 13:57:15 -05:00
|
|
|
|
2017-02-16 02:22:24 -05:00
|
|
|
validate_vendor_diff(){
|
|
|
|
IFS=$'\n'
|
|
|
|
files=( $(validate_diff --diff-filter=ACMR --name-only -- 'vendor.conf' 'vendor/' || true) )
|
|
|
|
unset IFS
|
2016-01-07 13:57:15 -05:00
|
|
|
|
2017-02-16 02:22:24 -05:00
|
|
|
if [ ${#files[@]} -gt 0 ]; then
|
2018-08-28 15:53:33 -04:00
|
|
|
# recreate vendor/
|
2017-02-16 02:22:24 -05:00
|
|
|
vndr
|
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)"
|
|
|
|
if [ "$diffs" ]; then
|
|
|
|
{
|
|
|
|
echo 'The result of vndr differs'
|
|
|
|
echo
|
|
|
|
echo "$diffs"
|
|
|
|
echo
|
|
|
|
echo 'Please vendor your package with github.com/LK4D4/vndr.'
|
|
|
|
echo
|
|
|
|
} >&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() {
|
2018-02-02 13:43:36 -05:00
|
|
|
pkgs=$(mawk '/^[a-zA-Z0-9]/ { print $1 }' < vendor.conf)
|
|
|
|
for f in $pkgs; do
|
2017-02-16 02:22:24 -05:00
|
|
|
if ls -d vendor/$f > /dev/null 2>&1; then
|
2018-02-02 13:43:36 -05:00
|
|
|
found=$(find vendor/$f -iregex '.*LICENSE.*' -or -iregex '.*COPYRIGHT.*' -or -iregex '.*COPYING.*' | wc -l)
|
|
|
|
if [ $found -eq 0 ]; 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
|