92
92
}
93
93
94
94
echo_latest_stable_version () {
95
+ url=" https://github.com/coder/coder/releases/latest"
95
96
# 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
+
97
108
version=" ${version# https:// github.com/ coder/ coder/ releases/ tag/ v} "
98
109
echo " ${version} "
99
110
}
@@ -103,7 +114,19 @@ echo_latest_mainline_version() {
103
114
# and take the first result. Note that we're sorting by space-
104
115
# separated numbers and without utilizing the sort -V flag for the
105
116
# 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 " |
107
130
awk -F' "' ' /"tag_name"/ {print $4}' |
108
131
tr -d v |
109
132
tr . ' ' |
@@ -405,8 +428,10 @@ main() {
405
428
STABLE_VERSION=$( echo_latest_stable_version)
406
429
if [ " ${MAINLINE} " = 1 ]; then
407
430
VERSION=$( echo_latest_mainline_version)
431
+ echoh " Resolved mainline version: v${VERSION} "
408
432
elif [ " ${STABLE} " = 1 ]; then
409
433
VERSION=${STABLE_VERSION}
434
+ echoh " Resolved stable version: v${VERSION} "
410
435
fi
411
436
412
437
distro_name
0 commit comments