Skip to content

Commit 59e5574

Browse files
committed
Merge commit '6c3ca18778a11813b865534ca37ee67f8c400b20' into tidy-go-mod
2 parents 0479e0e + 6c3ca18 commit 59e5574

File tree

2 files changed

+80
-11
lines changed

2 files changed

+80
-11
lines changed

release-tools/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,37 @@ Kubernetes releases:
106106

107107
CSI_PROW_KUBERNETES_VERSION=1.13.3 ./.prow.sh
108108
CSI_PROW_KUBERNETES_VERSION=latest ./.prow.sh
109+
110+
Dependencies and vendoring
111+
--------------------------
112+
113+
Most projects will (eventually) use `go mod` to manage
114+
dependencies. `dep` is also still supported by `csi-release-tools`,
115+
but not documented here because it's not recommended anymore.
116+
117+
The usual instructions for using [go
118+
modules](https://github.com/golang/go/wiki/Modules) apply. Here's a cheat sheet
119+
for some of the relevant commands:
120+
- list available updates: `GO111MODULE=on go list -u -m all`
121+
- update or add a single dependency: `GO111MODULE=on go get <package>`
122+
- update all dependencies to their next minor or patch release:
123+
`GO111MODULE=on go get ./...` (add `-u=patch` to limit to patch
124+
releases)
125+
- lock onto a specific version: `GO111MODULE=on go get <package>@<version>`
126+
- clean up `go.mod`: `GO111MODULE=on go mod tidy`
127+
- update vendor directory: `GO111MODULE=on go mod vendor`
128+
129+
`GO111MODULE=on` can be left out when using Go >= 1.13 or when the
130+
source is checked out outside of `$GOPATH`.
131+
132+
`go mod tidy` must be used to ensure that the listed dependencies are
133+
really still needed. Changing import statements or a tentative `go
134+
get` can result in stale dependencies.
135+
136+
The `test-vendor` verifies that it was used when run locally or in a
137+
pre-merge CI job. If a `vendor` directory is present, it will also
138+
verify that it's content is up-to-date.
139+
140+
The `vendor` directory is optional. It is still present in projects
141+
because it avoids downloading sources during CI builds. If this is no
142+
longer deemed necessary, then a project can also remove the directory.

release-tools/build.make

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -126,32 +126,67 @@ test-fmt:
126126
# - the fabricated merge commit leaves go.mod, go.sum and vendor dir unchanged
127127
# - release-tools also didn't change (changing rules or Go version might lead to
128128
# 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.
129149
.PHONY: test-vendor
130150
test: test-vendor
131151
test-vendor:
132152
@ echo; echo "### $@:"
133-
@ if [ -f Gopkg.toml ]; then \
153+
@ set -x; if [ -f Gopkg.toml ]; then \
134154
echo "Repo uses 'dep' for vendoring."; \
135155
case "$$(dep version 2>/dev/null | grep 'version *:')" in \
136156
*v0.[56789]*) dep check && echo "vendor up-to-date" || false;; \
137157
*) echo "skipping check, dep >= 0.5 required";; \
138158
esac; \
139-
else \
140-
echo "Repo uses 'go mod' for vendoring."; \
159+
elif [ -f go.mod ]; then \
160+
echo "Repo uses 'go mod'."; \
141161
if [ "$${JOB_NAME}" ] && \
142162
( [ "$${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 \
146168
echo "ERROR: vendor check failed."; \
147169
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; \
152173
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."; \
153188
fi; \
154-
fi;
189+
fi
155190

156191
.PHONY: test-subtree
157192
test: test-subtree

0 commit comments

Comments
 (0)