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