vendor 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/usr/bin/env bash
  2. SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
  3. source "${SCRIPTDIR}/.validate"
  4. validate_vendor_diff(){
  5. IFS=$'\n'
  6. # shellcheck disable=SC2207
  7. files=( $(validate_diff --diff-filter=ACMR --name-only -- 'vendor.conf' 'vendor/' || true) )
  8. unset IFS
  9. if [ -n "${TEST_FORCE_VALIDATE:-}" ] || [ ${#files[@]} -gt 0 ]; then
  10. # recreate vendor/
  11. ./hack/vendor.sh
  12. # check if any files have changed
  13. diffs="$(git status --porcelain -- vendor 2>/dev/null)"
  14. mfiles="$(echo "$diffs" | awk '/^ M / {print $2}')"
  15. if [ "$diffs" ]; then
  16. {
  17. echo 'The result of vndr differs'
  18. echo
  19. echo "$diffs"
  20. echo
  21. echo 'Please vendor your package with hack/vendor.sh.'
  22. echo
  23. if [ -n "$mfiles" ] ; then
  24. git diff -- "$mfiles"
  25. fi
  26. } >&2
  27. false
  28. else
  29. echo 'Congratulations! All vendoring changes are done the right way.'
  30. fi
  31. else
  32. echo 'No vendor changes in diff.'
  33. fi
  34. }
  35. # 1. make sure all the vendored packages are used
  36. # 2. make sure all the packages contain license information (just warning, because it can cause false-positive)
  37. validate_vendor_used() {
  38. for f in $(mawk '/^[a-zA-Z0-9]/ { print $1 }' vendor.conf); do
  39. if [ -d "vendor/$f" ]; then
  40. if ! echo "vendor/$f"/* | grep -qiEc '/(LICENSE|COPYING)'; then
  41. echo "WARNING: could not find copyright information for $f"
  42. fi
  43. else
  44. echo "WARNING: $f is vendored but unused"
  45. fi
  46. done
  47. }
  48. validate_vendor_diff
  49. validate_vendor_used