|
57 | 57 | TESTARGS =
|
58 | 58 | endif
|
59 | 59 |
|
| 60 | +ARCH := $(if $(GOARCH),$(GOARCH),$(shell go env GOARCH)) |
| 61 | + |
60 | 62 | # Specific packages can be excluded from each of the tests below by setting the *_FILTER_CMD variables
|
61 | 63 | # to something like "| grep -v 'github.com/kubernetes-csi/project/pkg/foobar'". See usage below.
|
62 | 64 |
|
63 | 65 | build-%:
|
64 | 66 | mkdir -p bin
|
65 | 67 | CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-X main.version=$(REV) -extldflags "-static"' -o ./bin/$* ./cmd/$*
|
| 68 | + if [ "$$ARCH" = "amd64" ]; then \ |
| 69 | + CGO_ENABLED=0 GOOS=windows go build -a -ldflags '-X main.version=$(REV) -extldflags "-static"' -o ./bin/$*.exe ./cmd/$* ; \ |
| 70 | + fi |
66 | 71 |
|
67 | 72 | container-%: build-%
|
68 | 73 | docker build -t $*:latest -f $(shell if [ -e ./cmd/$*/Dockerfile ]; then echo ./cmd/$*/Dockerfile; else echo Dockerfile; fi) --label revision=$(REV) .
|
@@ -118,14 +123,74 @@ test-fmt:
|
118 | 123 | fi
|
119 | 124 |
|
120 | 125 | # This test only runs when dep >= 0.5 is installed, which is the case for the CI setup.
|
| 126 | +# When using 'go mod', we allow the test to be skipped in the Prow CI under some special |
| 127 | +# circumstances, because it depends on accessing all remote repos and thus |
| 128 | +# running it all the time would defeat the purpose of vendoring: |
| 129 | +# - not handling a PR or |
| 130 | +# - the fabricated merge commit leaves go.mod, go.sum and vendor dir unchanged |
| 131 | +# - release-tools also didn't change (changing rules or Go version might lead to |
| 132 | +# a different result and thus must be tested) |
| 133 | +# - import statements not changed (because if they change, go.mod might have to be updated) |
| 134 | +# |
| 135 | +# "git diff" is intelligent enough to annotate changes inside the "import" block in |
| 136 | +# the start of the diff hunk: |
| 137 | +# |
| 138 | +# diff --git a/rpc/common.go b/rpc/common.go |
| 139 | +# index bb4a5c4..5fa4271 100644 |
| 140 | +# --- a/rpc/common.go |
| 141 | +# +++ b/rpc/common.go |
| 142 | +# @@ -21,7 +21,6 @@ import ( |
| 143 | +# "fmt" |
| 144 | +# "time" |
| 145 | +# |
| 146 | +# - "google.golang.org/grpc" |
| 147 | +# "google.golang.org/grpc/codes" |
| 148 | +# "google.golang.org/grpc/status" |
| 149 | +# |
| 150 | +# We rely on that to find such changes. |
| 151 | +# |
| 152 | +# Vendoring is optional when using go.mod. |
121 | 153 | .PHONY: test-vendor
|
122 | 154 | test: test-vendor
|
123 | 155 | test-vendor:
|
124 | 156 | @ 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 |
| 157 | + @ if [ -f Gopkg.toml ]; then \ |
| 158 | + echo "Repo uses 'dep' for vendoring."; \ |
| 159 | + case "$$(dep version 2>/dev/null | grep 'version *:')" in \ |
| 160 | + *v0.[56789]*) dep check && echo "vendor up-to-date" || false;; \ |
| 161 | + *) echo "skipping check, dep >= 0.5 required";; \ |
| 162 | + esac; \ |
| 163 | + elif [ -f go.mod ]; then \ |
| 164 | + echo "Repo uses 'go mod'."; \ |
| 165 | + if [ "$${JOB_NAME}" ] && \ |
| 166 | + ( [ "$${JOB_TYPE}" != "presubmit" ] || \ |
| 167 | + [ $$( (git diff "${PULL_BASE_SHA}..HEAD" -- go.mod go.sum vendor release-tools; \ |
| 168 | + git diff "${PULL_BASE_SHA}..HEAD" | grep -e '^@@.*@@ import (' -e '^[+-]import') | \ |
| 169 | + wc -l) -eq 0 ] ); then \ |
| 170 | + echo "Skipping vendor check because the Prow pre-submit job does not affect dependencies."; \ |
| 171 | + elif ! GO111MODULE=on go mod tidy; then \ |
| 172 | + echo "ERROR: vendor check failed."; \ |
| 173 | + false; \ |
| 174 | + elif [ $$(git status --porcelain -- go.mod go.sum | wc -l) -gt 0 ]; then \ |
| 175 | + echo "ERROR: go module files *not* up-to-date, they did get modified by 'GO111MODULE=on go mod tidy':"; \ |
| 176 | + git diff -- go.mod go.sum; \ |
| 177 | + false; \ |
| 178 | + elif [ -d vendor ]; then \ |
| 179 | + if ! GO111MODULE=on go mod vendor; then \ |
| 180 | + echo "ERROR: vendor check failed."; \ |
| 181 | + false; \ |
| 182 | + elif [ $$(git status --porcelain -- vendor | wc -l) -gt 0 ]; then \ |
| 183 | + echo "ERROR: vendor directory *not* up-to-date, it did get modified by 'GO111MODULE=on go mod vendor':"; \ |
| 184 | + git status -- vendor; \ |
| 185 | + git diff -- vendor; \ |
| 186 | + false; \ |
| 187 | + else \ |
| 188 | + echo "Go dependencies and vendor directory up-to-date."; \ |
| 189 | + fi; \ |
| 190 | + else \ |
| 191 | + echo "Go dependencies up-to-date."; \ |
| 192 | + fi; \ |
| 193 | + fi |
129 | 194 |
|
130 | 195 | .PHONY: test-subtree
|
131 | 196 | test: test-subtree
|
|
0 commit comments