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