Debian Codegraph @

engine/hack/validate/vendor

raw symbols SCIP
1 #!/usr/bin/env bash
2
3 set -e
4
5 SCRIPTDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6 source "${SCRIPTDIR}/.validate"
7
8 modules_files=('man/go.mod' 'vendor.mod')
9 tidy_files=("${modules_files[@]}" 'man/go.sum' 'vendor.sum')
10 vendor_files=("${tidy_files[@]}" 'vendor/')
11
12 validate_tidy_modules() {
13 # check that all go.mod files exist in HEAD; go.sum files are generated by 'go mod tidy'
14 # so we don't need to check for their existence beforehand
15 for f in "${modules_files[@]}"; do
16 if [ ! -f "$f" ]; then
17 echo >&2 "ERROR: missing $f"
18 return 1
19 fi
20 done
21 # run mod tidy
22 ./hack/vendor.sh tidy
23 # check if any files have changed
24 git diff --quiet HEAD -- "${tidy_files[@]}" && [ -z "$(git ls-files --others --exclude-standard)" ]
25 }
26
27 validate_vendor_diff() {
28 # recreate vendor/
29 ./hack/vendor.sh vendor
30 # check if any files have changed
31 git diff --quiet HEAD -- "${vendor_files[@]}" && [ -z "$(git ls-files --others --exclude-standard)" ]
32 }
33
34 validate_vendor_license() {
35 while IFS= read -r module; do
36 test -d "vendor/$module" || continue
37 if ! compgen -G "vendor/$module/*" | grep -qEi '/(LICENSE|COPYING)[^/]*$'; then
38 echo >&2 "WARNING: could not find copyright information for $module"
39 fi
40 done < <(awk '/^# /{ print $2 }' vendor/modules.txt)
41 }
42
43 if validate_tidy_modules && validate_vendor_diff && validate_vendor_license; then
44 echo >&2 'PASS: Vendoring has been performed correctly!'
45 else
46 {
47 echo 'FAIL: Vendoring was not performed correctly!'
48 echo
49 if [ -n "$(git ls-files --others --exclude-standard)" ]; then
50 echo 'The following files are missing:'
51 git ls-files --others --exclude-standard
52 echo
53 fi
54 if [ -n "$(git diff --name-status HEAD -- "${vendor_files[@]}")" ]; then
55 echo 'The following files changed during re-vendor:'
56 git diff --name-status HEAD -- "${vendor_files[@]}"
57 echo
58 fi
59 echo 'Please revendor with hack/vendor.sh'
60 echo
61 git diff --diff-filter=M -- "${vendor_files[@]}"
62 } >&2
63 exit 1
64 fi