@@ -126,32 +126,67 @@ test-fmt:
126
126
# - the fabricated merge commit leaves go.mod, go.sum and vendor dir unchanged
127
127
# - release-tools also didn't change (changing rules or Go version might lead to
128
128
# a different result and thus must be tested)
129
+ # - import statements not changed (because if they change, go.mod might have to be updated)
130
+ #
131
+ # "git diff" is intelligent enough to annotate changes inside the "import" block in
132
+ # the start of the diff hunk:
133
+ #
134
+ # diff --git a/rpc/common.go b/rpc/common.go
135
+ # index bb4a5c4..5fa4271 100644
136
+ # --- a/rpc/common.go
137
+ # +++ b/rpc/common.go
138
+ # @@ -21,7 +21,6 @@ import (
139
+ # "fmt"
140
+ # "time"
141
+ #
142
+ # - "google.golang.org/grpc"
143
+ # "google.golang.org/grpc/codes"
144
+ # "google.golang.org/grpc/status"
145
+ #
146
+ # We rely on that to find such changes.
147
+ #
148
+ # Vendoring is optional when using go.mod.
129
149
.PHONY : test-vendor
130
150
test : test-vendor
131
151
test-vendor :
132
152
@ echo ; echo " ### $@ :"
133
- @ if [ -f Gopkg.toml ]; then \
153
+ @ set -x ; if [ -f Gopkg.toml ]; then \
134
154
echo " Repo uses 'dep' for vendoring." ; \
135
155
case " $$ (dep version 2>/dev/null | grep 'version *:')" in \
136
156
* v0.[56789]* ) dep check && echo " vendor up-to-date" || false ;; \
137
157
* ) echo " skipping check, dep >= 0.5 required" ;; \
138
158
esac ; \
139
- else \
140
- echo " Repo uses 'go mod' for vendoring ." ; \
159
+ elif [ -f go.mod ] ; then \
160
+ echo " Repo uses 'go mod'." ; \
141
161
if [ " $$ {JOB_NAME}" ] && \
142
162
( [ "$${JOB_TYPE}" != "presubmit" ] || \
143
- [ $$(git diff "${PULL_BASE_SHA}..HEAD" -- go.mod go.sum vendor release-tools | wc -l) -eq 0 ] ); then \
144
- echo "Skipping vendor check because the Prow pre-submit job does not change vendoring."; \
145
- elif ! GO111MODULE=on go mod vendor; then \
163
+ [ $$( (git diff "${PULL_BASE_SHA}..HEAD" -- go.mod go.sum vendor release-tools; \
164
+ git diff "${PULL_BASE_SHA}..HEAD" | grep -e '^@@.*@@ import (' -e '^[+-]import') | \
165
+ wc -l) -eq 0 ] ); then \
166
+ echo "Skipping vendor check because the Prow pre-submit job does not affect dependencies."; \
167
+ elif ! GO111MODULE=on go mod tidy; then \
146
168
echo "ERROR: vendor check failed."; \
147
169
false; \
148
- elif [ $$(git status --porcelain -- vendor | wc -l) -gt 0 ]; then \
149
- echo "ERROR: vendor directory *not* up-to-date, it did get modified by 'GO111MODULE=on go mod vendor':"; \
150
- git status -- vendor; \
151
- git diff -- vendor; \
170
+ elif [ $$(git status --porcelain -- go.mod go.sum | wc -l) -gt 0 ]; then \
171
+ echo "ERROR: go module files *not* up-to-date, they did get modified by 'GO111MODULE=on go mod tidy':"; \
172
+ git diff -- go.mod go.sum; \
152
173
false; \
174
+ elif [ -d vendor ]; then \
175
+ if ! GO111MODULE=on go mod vendor; then \
176
+ echo "ERROR: vendor check failed."; \
177
+ false; \
178
+ elif [ $$(git status --porcelain -- vendor | wc -l) -gt 0 ]; then \
179
+ echo "ERROR: vendor directory *not* up-to-date, it did get modified by 'GO111MODULE=on go mod vendor':"; \
180
+ git status -- vendor; \
181
+ git diff -- vendor; \
182
+ false; \
183
+ else \
184
+ echo "Go dependencies and vendor directory up-to-date."; \
185
+ fi; \
186
+ else \
187
+ echo "Go dependencies up-to-date."; \
153
188
fi; \
154
- fi;
189
+ fi
155
190
156
191
.PHONY : test-subtree
157
192
test : test-subtree
0 commit comments