Skip to content

Commit 3c990bc

Browse files
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. Signed-off-by: Madhav Jivrajani <madhav.jiv@gmail.com>
1 parent 4740315 commit 3c990bc

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
@@ -384,3 +384,27 @@ function git_assert_branch_in_sync {
384384
log_warning "Cannot verify consistency with the origin, as git is on detached branch."
385385
fi
386386
}
387+
388+
# The version present in the .go-verion is the default version that test and build scripts will use.
389+
# However, it is possible to control the version that should be used with the help of env vars:
390+
# - FORCE_HOST_GO: if set to a non-empty value, use the version of go installed in system's $PATH.
391+
# - GO_VERSION: desired version of go to be used, might differ from what is present in .go-version.
392+
# If empty, the value defaults to the version in .go-version.
393+
function determine_go_version {
394+
# Borrowing from how Kubernetes does this:
395+
# https://github.com/kubernetes/kubernetes/blob/17854f0e0a153b06f9d0db096e2cd8ab2fa89c11/hack/lib/golang.sh#L510-L520
396+
#
397+
# default GO_VERSION to content of .go-version
398+
GO_VERSION="${GO_VERSION:-"$(cat "${ETCD_ROOT_DIR}/.go-version")"}"
399+
if [ "${GOTOOLCHAIN:-auto}" != 'auto' ]; then
400+
# no-op, just respect GOTOOLCHAIN
401+
:
402+
elif [ -n "${FORCE_HOST_GO:-}" ]; then
403+
export GOTOOLCHAIN='local'
404+
else
405+
GOTOOLCHAIN="go${GO_VERSION}"
406+
export GOTOOLCHAIN
407+
fi
408+
}
409+
410+
determine_go_version

0 commit comments

Comments
 (0)