hack/validate/vendor: add more checks

Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
This commit is contained in:
Akihiro Suda 2017-02-16 07:22:24 +00:00
parent d26cf30a60
commit 051b9a434f
1 changed files with 43 additions and 22 deletions

View File

@ -3,28 +3,49 @@
export SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" export SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "${SCRIPTDIR}/.validate" source "${SCRIPTDIR}/.validate"
IFS=$'\n' validate_vendor_diff(){
files=( $(validate_diff --diff-filter=ACMR --name-only -- 'vendor.conf' 'vendor/' || true) ) IFS=$'\n'
unset IFS files=( $(validate_diff --diff-filter=ACMR --name-only -- 'vendor.conf' 'vendor/' || true) )
unset IFS
if [ ${#files[@]} -gt 0 ]; then if [ ${#files[@]} -gt 0 ]; then
# We run vndr to and see if we have a diff afterwards # We run vndr to and see if we have a diff afterwards
vndr vndr
# Let see if the working directory is clean # Let see if the working directory is clean
diffs="$(git status --porcelain -- vendor 2>/dev/null)" diffs="$(git status --porcelain -- vendor 2>/dev/null)"
if [ "$diffs" ]; then if [ "$diffs" ]; then
{ {
echo 'The result of vndr differs' echo 'The result of vndr differs'
echo echo
echo "$diffs" echo "$diffs"
echo echo
echo 'Please vendor your package with github.com/LK4D4/vndr.' echo 'Please vendor your package with github.com/LK4D4/vndr.'
echo echo
} >&2 } >&2
false false
else
echo 'Congratulations! All vendoring changes are done the right way.'
fi
else else
echo 'Congratulations! All vendoring changes are done the right way.' echo 'No vendor changes in diff.'
fi fi
else }
echo 'No vendor changes in diff.'
fi # 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() {
pkgs=$(mawk '/^[a-zA-Z0-9]/ { print $1 }' < vendor.conf)
for f in $pkgs; do
if ls -d vendor/$f > /dev/null 2>&1; then
found=$(find vendor/$f -iregex '.*LICENSE.*' -or -iregex '.*COPYRIGHT.*' -or -iregex '.*COPYING.*' | wc -l)
if [ $found -eq 0 ]; then
echo "WARNING: could not find copyright information for $f"
fi
else
echo "WARNING: $f is vendored but unused"
fi
done
}
validate_vendor_diff
validate_vendor_used