Skip to content
This repository was archived by the owner on Jan 25, 2023. It is now read-only.

Commit 970118f

Browse files
authored
fix: ensure that go is always correctly installed (#887)
* fix: ensure that go is always correctly installed * adapt tests * more tests and do not allow installs from git
1 parent 5ddad3e commit 970118f

File tree

3 files changed

+35
-16
lines changed

3 files changed

+35
-16
lines changed

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,8 @@ ENV GOCACHE "/opt/buildhome/.gimme_cache/gocache"
468468
# Install the default version
469469
ENV GIMME_GO_VERSION "1.19.x"
470470
ENV GIMME_ENV_PREFIX "/opt/buildhome/.gimme/env"
471+
ENV GIMME_VERSION_PREFIX "/opt/buildhome/.gimme/versions"
472+
ENV GIMME_TYPE "binary"
471473
RUN gimme | bash
472474

473475
################################################################################

run-build-functions.sh

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,28 +1015,27 @@ install_go() {
10151015
fi
10161016
fi
10171017

1018-
if [ "$GIMME_GO_VERSION" != "$installGoVersion" ]
1018+
# Cache known version for 7days (604800 seconds)
1019+
resolvedGoVersion="$(GIMME_KNOWN_CACHE_MAX=604800 gimme --resolve $installGoVersion)"
1020+
if [ $? -ne 0 ]
1021+
then
1022+
echo "Failed to resolve Go version '$installGoVersion'"
1023+
exit 1
1024+
fi
1025+
1026+
gimmeEnvFile=$HOME/.gimme/env/go$resolvedGoVersion.linux.$(dpkg --print-architecture).env
1027+
1028+
# Check if the version is already installed by gimme
1029+
if [ ! -f $gimmeEnvFile ]
10191030
then
1020-
resolvedGoVersion=$(gimme --resolve $installGoVersion)
10211031
echo "Installing Go version $resolvedGoVersion (requested $installGoVersion)"
10221032
GIMME_ENV_PREFIX=$HOME/.gimme/env GIMME_VERSION_PREFIX=$HOME/.gimme/versions gimme $resolvedGoVersion
1023-
if [ $? -eq 0 ]
1033+
if [ $? -ne 0 ]
10241034
then
1025-
source $HOME/.gimme/env/go$resolvedGoVersion.linux.$(dpkg --print-architecture).env
1026-
else
10271035
echo "Failed to install Go version '$resolvedGoVersion'"
10281036
exit 1
10291037
fi
1030-
else
1031-
gimme | bash
1032-
if [ $? -eq 0 ]
1033-
then
1034-
source $HOME/.gimme/env/go$GIMME_GO_VERSION.linux.amd64.env
1035-
else
1036-
echo "Failed to install Go version '$GIMME_GO_VERSION'"
1037-
exit 1
1038-
fi
10391038
fi
10401039

1040+
source $gimmeEnvFile
10411041
}
1042-

tests/go/base.bats

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,28 @@ setup() {
1515
run install_go
1616
assert_success
1717
# we can't specify which patch version because it will change
18-
assert_output --partial "Installing Go version 1.19."
18+
# Also no message about installation will be shown because it is the default already installed version
19+
refute_output --partial "Installing Go version 1.19."
1920
assert_output --partial "go version go1.19."
2021
}
2122

23+
@test 'go version 1.19 at the latest patch is installed and available at startup by default when specifying default version' {
24+
run install_go $GIMME_GO_VERSION
25+
assert_success
26+
# we can't specify which patch version because it will change
27+
# Also no message about installation will be shown because it is the default already installed version
28+
refute_output --partial "Installing Go version 1.19."
29+
assert_output --partial "go version go1.19."
30+
}
31+
32+
@test 'an unresolvable go version fails script' {
33+
run install_go "notaversion"
34+
assert_failure
35+
assert_output --partial "Failed to resolve Go version 'notaversion'"
36+
refute_output --partial "Installing Go version"
37+
refute_output --partial "go version go"
38+
}
39+
2240
@test 'install custom go version' {
2341
local customGoVersion=1.16.4
2442
run install_go $customGoVersion

0 commit comments

Comments
 (0)