vendor 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/usr/bin/env bash
  2. set -e
  3. SCRIPTDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
  4. source "${SCRIPTDIR}/.validate"
  5. tidy_files=('vendor.mod' 'vendor.sum')
  6. vendor_files=("${tidy_files[@]}" 'vendor/')
  7. validate_vendor_tidy() {
  8. # run mod tidy
  9. ./hack/vendor.sh tidy
  10. # check if any files have changed
  11. git diff --quiet HEAD -- "${tidy_files[@]}"
  12. }
  13. validate_vendor_diff() {
  14. mapfile -t changed_files < <(validate_diff --diff-filter=ACMR --name-only -- "${vendor_files[@]}")
  15. if [ -n "${TEST_FORCE_VALIDATE:-}" ] || [ "${#changed_files[@]}" -gt 0 ]; then
  16. # recreate vendor/
  17. ./hack/vendor.sh vendor
  18. # check if any files have changed
  19. git diff --quiet HEAD -- "${vendor_files[@]}"
  20. else
  21. echo >&2 'INFO: no vendor changes in diff; skipping vendor check.'
  22. fi
  23. }
  24. validate_vendor_license() {
  25. while IFS= read -r module; do
  26. test -d "vendor/$module" || continue
  27. if ! compgen -G "vendor/$module/*" | grep -qEi '/(LICENSE|COPYING)[^/]*$'; then
  28. echo >&2 "WARNING: could not find copyright information for $module"
  29. fi
  30. done < <(awk '/^# /{ print $2 }' vendor/modules.txt)
  31. }
  32. if validate_vendor_tidy && validate_vendor_diff && validate_vendor_license; then
  33. echo >&2 'PASS: Vendoring has been performed correctly!'
  34. else
  35. {
  36. echo 'FAIL: Vendoring was not performed correctly!'
  37. echo
  38. echo 'The following files changed during re-vendor:'
  39. echo
  40. git diff --name-status HEAD -- "${vendor_files[@]}"
  41. echo
  42. echo 'Please revendor with hack/vendor.sh'
  43. echo
  44. git diff --diff-filter=M -- "${vendor_files[@]}"
  45. } >&2
  46. exit 1
  47. fi