Skip to content

Commit fbe3511

Browse files
committed
scripts: default to using .go-version's version for tests and builds
Manual cherrypick of e094139 Additionally, provide ability to opt-out of the .go-version and use a custom one via env vars: FORCE_HOST_GO and GO_VERSION. Co-authored by: Madhav Jivrajani <[email protected]> Signed-off-by: joshjms <[email protected]>
1 parent 26d9c99 commit fbe3511

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

scripts/test_lib.sh

+19
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,22 @@ function log_info {
5252
>&2 echo "$@"
5353
>&2 echo -n -e "${COLOR_NONE}"
5454
}
55+
56+
function determine_go_version {
57+
# Borrowing from how Kubernetes does this:
58+
# https://github.com/kubernetes/kubernetes/blob/17854f0e0a153b06f9d0db096e2cd8ab2fa89c11/hack/lib/golang.sh#L510-L520
59+
#
60+
# default GO_VERSION to content of .go-version
61+
GO_VERSION="${GO_VERSION:-"$(cat "./.go-version")"}"
62+
if [ "${GOTOOLCHAIN:-auto}" != 'auto' ]; then
63+
# no-op, just respect GOTOOLCHAIN
64+
:
65+
elif [ -n "${FORCE_HOST_GO:-}" ]; then
66+
export GOTOOLCHAIN='local'
67+
else
68+
GOTOOLCHAIN="go${GO_VERSION}"
69+
export GOTOOLCHAIN
70+
fi
71+
}
72+
73+
determine_go_version

0 commit comments

Comments
 (0)