vendor 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/usr/bin/env bash
  2. export SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
  3. source "${SCRIPTDIR}/.validate"
  4. validate_vendor_diff(){
  5. IFS=$'\n'
  6. files=( $(validate_diff --diff-filter=ACMR --name-only -- 'vendor.conf' 'vendor/' || true) )
  7. unset IFS
  8. if [ ${#files[@]} -gt 0 ]; then
  9. # We run vndr to and see if we have a diff afterwards
  10. vndr
  11. # Let see if the working directory is clean
  12. diffs="$(git status --porcelain -- vendor 2>/dev/null)"
  13. if [ "$diffs" ]; then
  14. {
  15. echo 'The result of vndr differs'
  16. echo
  17. echo "$diffs"
  18. echo
  19. echo 'Please vendor your package with github.com/LK4D4/vndr.'
  20. echo
  21. } >&2
  22. false
  23. else
  24. echo 'Congratulations! All vendoring changes are done the right way.'
  25. fi
  26. else
  27. echo 'No vendor changes in diff.'
  28. fi
  29. }
  30. # 1. make sure all the vendored packages are used
  31. # 2. make sure all the packages contain license information (just warning, because it can cause false-positive)
  32. validate_vendor_used() {
  33. pkgs=$(mawk '/^[a-zA-Z0-9]/ { print $1 }' < vendor.conf)
  34. for f in $pkgs; do
  35. if ls -d vendor/$f > /dev/null 2>&1; then
  36. found=$(find vendor/$f -iregex '.*LICENSE.*' -or -iregex '.*COPYRIGHT.*' -or -iregex '.*COPYING.*' | wc -l)
  37. if [ $found -eq 0 ]; then
  38. echo "WARNING: could not find copyright information for $f"
  39. fi
  40. else
  41. echo "WARNING: $f is vendored but unused"
  42. fi
  43. done
  44. }
  45. validate_vendor_diff
  46. validate_vendor_used