Skip to content

Commit e85a01c

Browse files
MadhavJivrajanijoshjms
authored andcommitted
scripts: default to using .go-version's version for tests and builds
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]> s
1 parent 30998ef commit e85a01c

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

scripts/test_lib.sh

+24
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,27 @@ function log_info {
5252
>&2 echo "$@"
5353
>&2 echo -n -e "${COLOR_NONE}"
5454
}
55+
56+
# The version present in the .go-verion is the default version that test and build scripts will use.
57+
# However, it is possible to control the version that should be used with the help of env vars:
58+
# - FORCE_HOST_GO: if set to a non-empty value, use the version of go installed in system's $PATH.
59+
# - GO_VERSION: desired version of go to be used, might differ from what is present in .go-version.
60+
# If empty, the value defaults to the version in .go-version.
61+
function determine_go_version {
62+
# Borrowing from how Kubernetes does this:
63+
# https://github.com/kubernetes/kubernetes/blob/17854f0e0a153b06f9d0db096e2cd8ab2fa89c11/hack/lib/golang.sh#L510-L520
64+
#
65+
# default GO_VERSION to content of .go-version
66+
GO_VERSION="${GO_VERSION:-"$(cat "${ETCD_ROOT_DIR}/.go-version")"}"
67+
if [ "${GOTOOLCHAIN:-auto}" != 'auto' ]; then
68+
# no-op, just respect GOTOOLCHAIN
69+
:
70+
elif [ -n "${FORCE_HOST_GO:-}" ]; then
71+
export GOTOOLCHAIN='local'
72+
else
73+
GOTOOLCHAIN="go${GO_VERSION}"
74+
export GOTOOLCHAIN
75+
fi
76+
}
77+
78+
determine_go_version

0 commit comments

Comments
 (0)