Skip to content

Commit 5757169

Browse files
committed
Print useful debug info when retrieving a version from GitHub fails
Signed-off-by: Danny Kopping <danny@coder.com>
1 parent 26b1f1c commit 5757169

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

install.sh

+28-3
Original file line numberDiff line numberDiff line change
@@ -92,18 +92,41 @@ EOF
9292
}
9393

9494
echo_latest_stable_version() {
95+
url="https://github.com/coder/coder/releases/latest"
9596
# https://gist.github.com/lukechilds/a83e1d7127b78fef38c2914c4ececc3c#gistcomment-2758860
96-
version="$(curl -fsSLI -o /dev/null -w "%{url_effective}" https://github.com/coder/coder/releases/latest)"
97+
response=$(curl -sSLI -o /dev/null -w "\n%{http_code} %{url_effective}" ${url})
98+
status_code=$(echo "$response" | tail -n1 | cut -d' ' -f1)
99+
version=$(echo "$response" | tail -n1 | cut -d' ' -f2-)
100+
body=$(echo "$response" | sed '$d')
101+
102+
if [ "$status_code" != "200" ]; then
103+
echoerr "GitHub API returned status code: ${status_code}"
104+
echoerr "URL: ${url}"
105+
exit 1
106+
fi
107+
97108
version="${version#https://github.com/coder/coder/releases/tag/v}"
98-
echo "${version}"
109+
echo "$version"
99110
}
100111

101112
echo_latest_mainline_version() {
102113
# Fetch the releases from the GitHub API, sort by version number,
103114
# and take the first result. Note that we're sorting by space-
104115
# separated numbers and without utilizing the sort -V flag for the
105116
# best compatibility.
106-
curl -fsSL https://api.github.com/repos/coder/coder/releases |
117+
url="https://api.github.com/repos/coder/coder/releases"
118+
response=$(curl -sSL -w "\n%{http_code}" ${url})
119+
status_code=$(echo "$response" | tail -n1)
120+
body=$(echo "$response" | sed '$d')
121+
122+
if [ "$status_code" != "200" ]; then
123+
echoerr "GitHub API returned status code: ${status_code}"
124+
echoerr "URL: ${url}"
125+
echoerr "Response body: ${body}"
126+
exit 1
127+
fi
128+
129+
echo "$body" |
107130
awk -F'"' '/"tag_name"/ {print $4}' |
108131
tr -d v |
109132
tr . ' ' |
@@ -405,8 +428,10 @@ main() {
405428
STABLE_VERSION=$(echo_latest_stable_version)
406429
if [ "${MAINLINE}" = 1 ]; then
407430
VERSION=$(echo_latest_mainline_version)
431+
echoh "Resolved mainline version: v${VERSION}"
408432
elif [ "${STABLE}" = 1 ]; then
409433
VERSION=${STABLE_VERSION}
434+
echoh "Resolved stable version: v${VERSION}"
410435
fi
411436

412437
distro_name

0 commit comments

Comments
 (0)