Skip to content
This repository was archived by the owner on Dec 6, 2024. It is now read-only.

Commit 23df4ae

Browse files
committed
prow.sh: use vendor directory if available
This avoids dependencies on the Go module cache or the upstream code hosting.
1 parent a53bd4c commit 23df4ae

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

Diff for: build.make

+7-4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
# including build.make.
2323
REGISTRY_NAME=quay.io/k8scsi
2424

25+
# Can be set to -mod=vendor to ensure that the "vendor" directory is used.
26+
GOFLAGS_VENDOR=
27+
2528
# Revision that gets built into each binary via the main.version
2629
# string. Uses the `git describe` output based on the most recent
2730
# version tag with a short revision suffix or, if nothing has been
@@ -64,9 +67,9 @@ ARCH := $(if $(GOARCH),$(GOARCH),$(shell go env GOARCH))
6467

6568
build-%: check-go-version-go
6669
mkdir -p bin
67-
CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-X main.version=$(REV) -extldflags "-static"' -o ./bin/$* ./cmd/$*
70+
CGO_ENABLED=0 GOOS=linux go build $(GOFLAGS_VENDOR) -a -ldflags '-X main.version=$(REV) -extldflags "-static"' -o ./bin/$* ./cmd/$*
6871
if [ "$$ARCH" = "amd64" ]; then \
69-
CGO_ENABLED=0 GOOS=windows go build -a -ldflags '-X main.version=$(REV) -extldflags "-static"' -o ./bin/$*.exe ./cmd/$* ; \
72+
CGO_ENABLED=0 GOOS=windows go build $(GOFLAGS_VENDOR) -a -ldflags '-X main.version=$(REV) -extldflags "-static"' -o ./bin/$*.exe ./cmd/$* ; \
7073
fi
7174

7275
container-%: build-%
@@ -103,13 +106,13 @@ test: check-go-version-go
103106
test: test-go
104107
test-go:
105108
@ echo; echo "### $@:"
106-
go test `go list ./... | grep -v -e 'vendor' -e '/test/e2e$$' $(TEST_GO_FILTER_CMD)` $(TESTARGS)
109+
go test $(GOFLAGS_VENDOR) `go list $(GOFLAGS_VENDOR) ./... | grep -v -e 'vendor' -e '/test/e2e$$' $(TEST_GO_FILTER_CMD)` $(TESTARGS)
107110

108111
.PHONY: test-vet
109112
test: test-vet
110113
test-vet:
111114
@ echo; echo "### $@:"
112-
go vet `go list ./... | grep -v vendor $(TEST_VET_FILTER_CMD)`
115+
go test $(GOFLAGS_VENDOR) `go list $(GOFLAGS_VENDOR) ./... | grep -v vendor $(TEST_VET_FILTER_CMD)`
113116

114117
.PHONY: test-fmt
115118
test: test-fmt

Diff for: prow.sh

+9-3
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ get_versioned_variable () {
8585
echo "$value"
8686
}
8787

88+
# If we have a vendor directory, then use it. We must be careful to only
89+
# use this for "make" invocations inside the project's repo itself because
90+
# setting it globally can break other go usages (like "go get <some command>"
91+
# which is disabled with GOFLAGS=-mod=vendor).
92+
configvar GOFLAGS_VENDOR "$( [ -d vendor ] && echo '-mod=vendor' )" "Go flags for using the vendor directory"
93+
8894
# Go versions can be specified seperately for different tasks
8995
# If the pre-installed Go is missing or a different
9096
# version, the required version here will get installed
@@ -928,7 +934,7 @@ main () {
928934
images=
929935
if ${CSI_PROW_BUILD_JOB}; then
930936
# A successful build is required for testing.
931-
run_with_go "${CSI_PROW_GO_VERSION_BUILD}" make all || die "'make all' failed"
937+
run_with_go "${CSI_PROW_GO_VERSION_BUILD}" make all "GOFLAGS_VENDOR=${GOFLAGS_VENDOR}" || die "'make all' failed"
932938
# We don't want test failures to prevent E2E testing below, because the failure
933939
# might have been minor or unavoidable, for example when experimenting with
934940
# changes in "release-tools" in a PR (that fails the "is release-tools unmodified"
@@ -938,13 +944,13 @@ main () {
938944
warn "installing 'dep' failed, cannot test vendoring"
939945
ret=1
940946
fi
941-
if ! run_with_go "${CSI_PROW_GO_VERSION_BUILD}" make -k test 2>&1 | make_test_to_junit; then
947+
if ! run_with_go "${CSI_PROW_GO_VERSION_BUILD}" make -k test "GOFLAGS_VENDOR=${GOFLAGS_VENDOR}" 2>&1 | make_test_to_junit; then
942948
warn "'make test' failed, proceeding anyway"
943949
ret=1
944950
fi
945951
fi
946952
# Required for E2E testing.
947-
run_with_go "${CSI_PROW_GO_VERSION_BUILD}" make container || die "'make container' failed"
953+
run_with_go "${CSI_PROW_GO_VERSION_BUILD}" make container "GOFLAGS_VENDOR=${GOFLAGS_VENDOR}" || die "'make container' failed"
948954
fi
949955

950956
if tests_need_kind; then

0 commit comments

Comments
 (0)