Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 401f8b4

Browse files
authored
provide useful debug info when retrieving a version from GitHub fails (coder#15956)
Closes coder#15851 This fails the installation when the version cannot be retrieved, and prints useful debug info. `install.sh` could use with more error-handling in general, but this at least ameliorates the linked issue. Signed-off-by: Danny Kopping <[email protected]>
1 parent 5e88289 commit 401f8b4

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

install.sh

+27-2
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,19 @@ 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}"
98109
echo "${version}"
99110
}
@@ -103,7 +114,19 @@ echo_latest_mainline_version() {
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)