@@ -41,20 +41,38 @@ if [ -n "$VERSION" ]; then
4141else
4242 echo " Detecting the latest version of Kosli CLI..."
4343 debug_print " Fetching latest version from GitHub API"
44- # Fetches the latest release tag from the GitHub API
45- METADATA=$( curl -s " https://api.github.com/repos/kosli-dev/cli/releases/latest" )
46- debug_print " GitHub API response: $METADATA "
47- TAG_NAME=$( echo " $METADATA " | grep ' "tag_name":' )
48- debug_print " GitHub API response tag: $TAG_NAME "
49- LATEST_TAG=$( echo " $TAG_NAME " | sed -E ' s/.*"([^"]+)".*/\1/' )
50- debug_print " GitHub API response tag: $LATEST_TAG "
51- if [ -z " $LATEST_TAG " ]; then
52- echo " Error: Could not fetch the latest version tag from GitHub."
53- exit 1
54- fi
55- VERSION=$LATEST_TAG
56- echo " Latest version is $VERSION . Downloading..."
57- debug_print " Set VERSION to: $VERSION "
44+
45+ # Retry mechanism for fetching the latest version
46+ RETRY_COUNT=0
47+ MAX_RETRIES=5
48+ while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do
49+ METADATA=$( curl -s " https://api.github.com/repos/kosli-dev/cli/releases/latest" )
50+ debug_print " GitHub API response: $METADATA "
51+
52+ # Check if the response contains the expected tag_name
53+ if echo " $METADATA " | grep -q ' "tag_name":' ; then
54+ TAG_NAME=$( echo " $METADATA " | grep ' "tag_name":' )
55+ debug_print " GitHub API response tag: $TAG_NAME "
56+ LATEST_TAG=$( echo " $TAG_NAME " | sed -E ' s/.*"([^"]+)".*/\1/' )
57+ debug_print " GitHub API response tag: $LATEST_TAG "
58+ if [ -z " $LATEST_TAG " ]; then
59+ echo " Error: Could not fetch the latest version tag from GitHub."
60+ exit 1
61+ fi
62+ VERSION=$LATEST_TAG
63+ echo " Latest version is $VERSION . Downloading..."
64+ debug_print " Set VERSION to: $VERSION "
65+ break
66+ else
67+ echo " Warning: GitHub API response did not contain a valid tag_name. Retrying in 5 seconds..."
68+ sleep 5
69+ RETRY_COUNT=$(( RETRY_COUNT + 1 ))
70+ if [ $RETRY_COUNT -eq $MAX_RETRIES ]; then
71+ echo " Error: GitHub rate limit exceeded too many times."
72+ exit 1
73+ fi
74+ fi
75+ done
5876fi
5977echo " "
6078
0 commit comments