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

Commit f0ba5ba

Browse files
authored
Implement fallback logic for go script (#1302)
1 parent 3eb1ac0 commit f0ba5ba

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

script-library/go-debian.sh

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,28 @@ if [ "${TARGET_GO_VERSION}" != "none" ] && ! type go > /dev/null 2>&1; then
164164
curl -sSL -o /tmp/tmp-gnupg/golang_key "${GO_GPG_KEY_URI}"
165165
gpg -q --import /tmp/tmp-gnupg/golang_key
166166
echo "Downloading Go ${TARGET_GO_VERSION}..."
167-
curl -sSL -o /tmp/go.tar.gz "https://golang.org/dl/go${TARGET_GO_VERSION}.linux-${architecture}.tar.gz"
168-
curl -sSL -o /tmp/go.tar.gz.asc "https://golang.org/dl/go${TARGET_GO_VERSION}.linux-${architecture}.tar.gz.asc"
167+
set +e
168+
curl -fsSL -o /tmp/go.tar.gz https://golang.org/dl/go1.177.linux-amd64.tar.gz
169+
set -e
170+
if [ ! -s "/tmp/go.tar.gz" ] || [ "$?" != "0" ]; then
171+
echo "(!) Download failed."
172+
# Try one break fix version number less if we get a failure
173+
major="$(echo "${TARGET_GO_VERSION}" | grep -oE '^[0-9]+')"
174+
minor="$(echo "${TARGET_GO_VERSION}" | grep -oP '^[0-9]+\.\K[0-9]+')"
175+
breakfix="$(echo "${TARGET_GO_VERSION}" | grep -oP '^[0-9]+\.[0-9]+\.\K[0-9]+' 2>/dev/null)"
176+
if [ "${breakfix}" = "" ] || [ "${breakfix}" = "0" ]; then
177+
((minor=minor-1))
178+
TARGET_GO_VERSION="${major}.${minor}"
179+
find_version_from_git_tags TARGET_GO_VERSION "https://go.googlesource.com/go" "tags/go" "." "true"
180+
else
181+
((breakfix=breakfix-1))
182+
TARGET_GO_VERSION="${major}.${minor}.${breakfix}"
183+
fi
184+
echo "Trying ${TARGET_GO_VERSION}..."
185+
curl -fsSL -o /tmp/go.tar.gz "https://golang.org/dl/go${TARGET_GO_VERSION}.linux-${architecture}.tar.gz"
186+
fi
187+
set -e
188+
curl -fsSL -o /tmp/go.tar.gz.asc "https://golang.org/dl/go${TARGET_GO_VERSION}.linux-${architecture}.tar.gz.asc"
169189
gpg --verify /tmp/go.tar.gz.asc /tmp/go.tar.gz
170190
echo "Extracting Go ${TARGET_GO_VERSION}..."
171191
tar -xzf /tmp/go.tar.gz -C "${TARGET_GOROOT}" --strip-components=1
@@ -207,9 +227,15 @@ if [ "${INSTALL_GO_TOOLS}" = "true" ]; then
207227
# Move Go tools into path and clean up
208228
mv /tmp/gotools/bin/* ${TARGET_GOPATH}/bin/
209229

210-
# install dlv-dap (dlv@master)
230+
# install dlv-dap (dlv@master) - but do not exit on failure
231+
set +e
211232
go ${go_install_command} -v github.com/go-delve/delve/cmd/dlv@master 2>&1 | tee -a /usr/local/etc/vscode-dev-containers/go.log
212-
mv /tmp/gotools/bin/dlv ${TARGET_GOPATH}/bin/dlv-dap
233+
set -e
234+
if [ -e "/tmp/gotools/bin/dlv" ]; then
235+
mv /tmp/gotools/bin/dlv ${TARGET_GOPATH}/bin/dlv-dap
236+
else
237+
echo "(*) Failed to install github.com/go-delve/delve/cmd/dlv@master. Skipping."
238+
fi
213239

214240
rm -rf /tmp/gotools
215241
fi

0 commit comments

Comments
 (0)