File: vendor

package info (click to toggle)
docker.io 28.5.2%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 69,048 kB
  • sloc: sh: 5,867; makefile: 863; ansic: 184; python: 162; asm: 159
file content (64 lines) | stat: -rwxr-xr-x 1,956 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env bash

set -e

SCRIPTDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "${SCRIPTDIR}/.validate"

modules_files=('man/go.mod' 'vendor.mod')
tidy_files=("${modules_files[@]}" 'man/go.sum' 'vendor.sum')
vendor_files=("${tidy_files[@]}" 'vendor/')

validate_tidy_modules() {
	# check that all go.mod files exist in HEAD; go.sum files are generated by 'go mod tidy'
	# so we don't need to check for their existence beforehand
	for f in "${modules_files[@]}"; do
		if [ ! -f "$f" ]; then
			echo >&2 "ERROR: missing $f"
			return 1
		fi
	done
	# run mod tidy
	./hack/vendor.sh tidy
	# check if any files have changed
	git diff --quiet HEAD -- "${tidy_files[@]}" && [ -z "$(git ls-files --others --exclude-standard)" ]
}

validate_vendor_diff() {
	# recreate vendor/
	./hack/vendor.sh vendor
	# check if any files have changed
	git diff --quiet HEAD -- "${vendor_files[@]}" && [ -z "$(git ls-files --others --exclude-standard)" ]
}

validate_vendor_license() {
	while IFS= read -r module; do
		test -d "vendor/$module" || continue
		if ! compgen -G "vendor/$module/*" | grep -qEi '/(LICENSE|COPYING)[^/]*$'; then
			echo >&2 "WARNING: could not find copyright information for $module"
		fi
	done < <(awk '/^# /{ print $2 }' vendor/modules.txt)
}

if validate_tidy_modules && validate_vendor_diff && validate_vendor_license; then
	echo >&2 'PASS: Vendoring has been performed correctly!'
else
	{
		echo 'FAIL: Vendoring was not performed correctly!'
		echo
		if [ -n "$(git ls-files --others --exclude-standard)" ]; then
			echo 'The following files are missing:'
			git ls-files --others --exclude-standard
			echo
		fi
		if [ -n "$(git diff --name-status HEAD -- "${vendor_files[@]}")" ]; then
			echo 'The following files changed during re-vendor:'
			git diff --name-status HEAD -- "${vendor_files[@]}"
			echo
		fi
		echo 'Please revendor with hack/vendor.sh'
		echo
		git diff --diff-filter=M -- "${vendor_files[@]}"
	} >&2
	exit 1
fi