@@ -118,14 +118,39 @@ test-fmt:
118
118
fi
119
119
120
120
# 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)
121
128
.PHONY : test-vendor
122
129
test : test-vendor
123
130
test-vendor :
124
131
@ 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;
129
154
130
155
.PHONY : test-subtree
131
156
test : test-subtree
0 commit comments