Skip to content

Commit 0399988

Browse files
authored
Merge pull request kubernetes-csi#19 from pohly/go-mod-vendor
build.make: allow repos to use 'go mod' for vendoring
2 parents 0bee749 + 066143d commit 0399988

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

build.make

+29-4
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,39 @@ test-fmt:
118118
fi
119119

120120
# This test only runs when dep >= 0.5 is installed, which is the case for the CI setup.
121+
# When using 'go mod', we allow the test to be skipped in the Prow CI under some special
122+
# circumstances, because it depends on accessing all remote repos and thus
123+
# running it all the time would defeat the purpose of vendoring:
124+
# - not handling a PR or
125+
# - the fabricated merge commit leaves go.mod, go.sum and vendor dir unchanged
126+
# - release-tools also didn't change (changing rules or Go version might lead to
127+
# a different result and thus must be tested)
121128
.PHONY: test-vendor
122129
test: test-vendor
123130
test-vendor:
124131
@ echo; echo "### $@:"
125-
@ case "$$(dep version 2>/dev/null | grep 'version *:')" in \
126-
*v0.[56789]*) dep check && echo "vendor up-to-date" || false;; \
127-
*) echo "skipping check, dep >= 0.5 required";; \
128-
esac
132+
@ if [ -f Gopkg.toml ]; then \
133+
echo "Repo uses 'dep' for vendoring."; \
134+
case "$$(dep version 2>/dev/null | grep 'version *:')" in \
135+
*v0.[56789]*) dep check && echo "vendor up-to-date" || false;; \
136+
*) echo "skipping check, dep >= 0.5 required";; \
137+
esac; \
138+
else \
139+
echo "Repo uses 'go mod' for vendoring."; \
140+
if [ "$${JOB_NAME}" ] && \
141+
( [ "$${JOB_TYPE}" != "presubmit" ] || \
142+
[ $$(git diff "${PULL_BASE_SHA}..HEAD" -- go.mod go.sum vendor release-tools | wc -l) -eq 0 ] ); then \
143+
echo "Skipping vendor check because the Prow pre-submit job does not change vendoring."; \
144+
elif ! GO111MODULE=on go mod vendor; then \
145+
echo "ERROR: vendor check failed."; \
146+
false; \
147+
elif [ $$(git status --porcelain -- vendor | wc -l) -gt 0 ]; then \
148+
echo "ERROR: vendor directory *not* up-to-date, it did get modified by 'GO111MODULE=on go mod vendor':"; \
149+
git status -- vendor; \
150+
git diff -- vendor; \
151+
false; \
152+
fi; \
153+
fi;
129154

130155
.PHONY: test-subtree
131156
test: test-subtree

0 commit comments

Comments
 (0)