Skip to content

Commit bfd1892

Browse files
committed
fix(ci-run): add fallback for Go version installation in CI script
This patch allows to keep the build working even if the snap version expected in the juju go mod hasn't be released. It fallback on the latest version available and use GOTOOLCHAIN to ensure we use the expected version of Go. **Updated files:** - *jobs/ci-run/scripts/package-juju-source.sh*: Added a fallback mechanism to install the latest Go version after failing to install the specified version. Also included a workaround by exporting `GOTOOLCHAIN` to ensure compatibility with the required Go version for Juju.
1 parent c677b88 commit bfd1892

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

jobs/ci-run/scripts/package-juju-source.sh

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,24 @@ if [ -z "$GOVERSION" ]; then
1111
exit 1
1212
fi
1313

14+
1415
export PATH="/snap/bin:$PATH"
1516
GO_MAJOR_MINOR=$(echo ${GOVERSION} | cut -d '.' -f1,2)
16-
sudo snap refresh go --channel="${GO_MAJOR_MINOR}/stable" || sudo snap install go --channel="${GO_MAJOR_MINOR}/stable" --classic
17+
if sudo snap refresh go --channel="${GO_MAJOR_MINOR}/stable" || sudo snap install go --channel="${GO_MAJOR_MINOR}/stable" --classic; then
18+
echo "Successfully installed Go ${GO_MAJOR_MINOR}"
19+
else
20+
# If specific version installation fails, install latest available
21+
echo "Failed to install Go ${GO_MAJOR_MINOR}, installing latest available version"
22+
if sudo snap refresh go --channel=latest/stable || sudo snap install go --channel=latest/stable --classic; then
23+
echo "Successfully installed latest Go version: $(go version)"
24+
# Export GOTOOLCHAIN to use the expected version
25+
# Note: this is a hack which avoid breaking the CI if for some reason snap go is behind the required version for
26+
# Juju. It is not something that should happens regularly, and whenever the snap go is available, this hack won't
27+
# be used.
28+
export GOTOOLCHAIN="go${GOVERSION}.0+auto"
29+
echo "Exported GOTOOLCHAIN=${GOTOOLCHAIN}"
30+
fi
31+
fi
1732

1833
# TODO - fix this workaround
1934
# As we clone the full history (can't shallow clone otherwise queued jobs miss

0 commit comments

Comments
 (0)