@@ -125,6 +125,26 @@ test-fmt:
125125# - the fabricated merge commit leaves go.mod, go.sum and vendor dir unchanged
126126# - release-tools also didn't change (changing rules or Go version might lead to
127127# a different result and thus must be tested)
128+ # - import statements not changed (because if they change, go.mod might have to be updated)
129+ #
130+ # "git diff" is intelligent enough to annotate changes inside the "import" block in
131+ # the start of the diff hunk:
132+ #
133+ # diff --git a/rpc/common.go b/rpc/common.go
134+ # index bb4a5c4..5fa4271 100644
135+ # --- a/rpc/common.go
136+ # +++ b/rpc/common.go
137+ # @@ -21,7 +21,6 @@ import (
138+ # "fmt"
139+ # "time"
140+ #
141+ # - "google.golang.org/grpc"
142+ # "google.golang.org/grpc/codes"
143+ # "google.golang.org/grpc/status"
144+ #
145+ # We rely on that to find such changes.
146+ #
147+ # Vendoring is optional when using go.mod.
128148.PHONY : test-vendor
129149test : test-vendor
130150test-vendor :
@@ -135,22 +155,37 @@ test-vendor:
135155 * v0.[56789]* ) dep check && echo " vendor up-to-date" || false ;; \
136156 * ) echo " skipping check, dep >= 0.5 required" ;; \
137157 esac ; \
138- else \
139- echo " Repo uses 'go mod' for vendoring ." ; \
158+ elif [ -f go.mod ] ; then \
159+ echo " Repo uses 'go mod'." ; \
140160 if [ " $$ {JOB_NAME}" ] && \
141161 ( [ "$${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 \
162+ [ $$( (git diff "${PULL_BASE_SHA}..HEAD" -- go.mod go.sum vendor release-tools; \
163+ git diff "${PULL_BASE_SHA}..HEAD" | grep -e '^@@.*@@ import (' -e '^[+-]import') | \
164+ wc -l) -eq 0 ] ); then \
165+ echo "Skipping vendor check because the Prow pre-submit job does not affect dependencies."; \
166+ elif ! GO111MODULE=on go mod tidy; then \
145167 echo "ERROR: vendor check failed."; \
146168 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; \
169+ elif [ $$(git status --porcelain -- go.mod go.sum | wc -l) -gt 0 ]; then \
170+ echo "ERROR: go module files *not* up-to-date, they did get modified by 'GO111MODULE=on go mod tidy':"; \
171+ git diff -- go.mod go.sum; \
151172 false; \
173+ elif [ -d vendor ]; then \
174+ if ! GO111MODULE=on go mod vendor; then \
175+ echo "ERROR: vendor check failed."; \
176+ false; \
177+ elif [ $$(git status --porcelain -- vendor | wc -l) -gt 0 ]; then \
178+ echo "ERROR: vendor directory *not* up-to-date, it did get modified by 'GO111MODULE=on go mod vendor':"; \
179+ git status -- vendor; \
180+ git diff -- vendor; \
181+ false; \
182+ else \
183+ echo "Go dependencies and vendor directory up-to-date."; \
184+ fi; \
185+ else \
186+ echo "Go dependencies up-to-date."; \
152187 fi; \
153- fi;
188+ fi
154189
155190.PHONY : test-subtree
156191test : test-subtree
0 commit comments