From e37e235bf5778bad3d97bbe98f6fcd4b12cfe5c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lesimple?= Date: Fri, 19 Mar 2021 15:28:32 +0000 Subject: [PATCH] enh: install.inc: try harder to hit GitHub API in CI --- lib/shell/install.inc | 71 +++++++++++++++++++++++++------------------ 1 file changed, 42 insertions(+), 29 deletions(-) diff --git a/lib/shell/install.inc b/lib/shell/install.inc index d3e41ed..3f72c10 100644 --- a/lib/shell/install.inc +++ b/lib/shell/install.inc @@ -54,37 +54,50 @@ set_download_url() { # shellcheck disable=SC2064 trap "rm -f $payload" EXIT - _apicall "$RELEASE_API_URL" > "$payload" - if command -v jq >/dev/null; then - # If we have jq, we can do it properly - urls="$(jq -r '.[0].assets|.[]|.browser_download_url' < "$payload")" - elif perl -MJSON -e 1 2>/dev/null; then - # If we don't, there's a good chance we have Perl with the JSON module, use it - urls="$(perl -MJSON -e 'undef $/; $d=decode_json(<>); exit if ref $d ne "ARRAY"; foreach(@{ $d->[0]{assets} || [] }) { print $_->{browser_download_url}."\n" }' "$payload")" - else - # Otherwise, go the ugly way, don't bother the user in installing jq just for this need - urls="$(grep -Eo 'https://[a-z0-9./_-]+' "$payload")" - fi + maxtries=60 + for try in $(seq 1 $maxtries); do + _apicall "$RELEASE_API_URL" > "$payload" + if command -v jq >/dev/null; then + # If we have jq, we can do it properly + urls="$(jq -r '.[0].assets|.[]|.browser_download_url' < "$payload")" + elif perl -MJSON -e 1 2>/dev/null; then + # If we don't, there's a good chance we have Perl with the JSON module, use it + urls="$(perl -MJSON -e 'undef $/; $d=decode_json(<>); exit if ref $d ne "ARRAY"; foreach(@{ $d->[0]{assets} || [] }) { print $_->{browser_download_url}."\n" }' "$payload")" + else + # Otherwise, go the ugly way, don't bother the user in installing jq just for this need + urls="$(grep -Eo 'https://[a-z0-9./_-]+' "$payload")" + fi - url="$(echo "$urls" | grep -E "$pattern" | head -n1)" + url="$(echo "$urls" | grep -E "$pattern" | head -n1)" - if [ -n "$url" ]; then - action_detail "$url" - elif [ ! -s "$payload" ]; then - action_error "API returned an empty body, did we hit the query limit?" - exit 1 - elif [ -z "$urls" ]; then - action_error "Couldn't find any URL in the returned body, did we hit the query limit? Body follows:" - cat "$payload" - exit 1 - else - action_error "Couldn't find a proper URL for your architecture ($arch), looked for pattern '$pattern'. You may have to compile $PROGRAM_NAME yourself!" - action_detail "Maybe the release asset naming pattern has changed and we're not aware, if you think one of the packages below match your OS & arch, you may download & install them manually:" - for line in $urls; do - action_detail "$line" - done - exit 1 - fi + if [ -n "$url" ]; then + # success + action_detail "$url" + return 0 + elif [ ! -s "$payload" ]; then + action_error "API returned an empty body, did we hit the query limit?" + if [ "$CI" = "true" ]; then + action_detail "... CI environment detected, try $try out of $maxtries, sleeping and retrying..." + sleep 63 + continue + fi + exit 1 + elif [ -z "$urls" ]; then + action_error "Couldn't find any URL in the returned body, did we hit the query limit? Body follows:" + cat "$payload" + exit 1 + else + action_error "Couldn't find a proper URL for your architecture ($arch), looked for pattern '$pattern'. You may have to compile $PROGRAM_NAME yourself!" + action_detail "Maybe the release asset naming pattern has changed and we're not aware, if you think one of the packages below match your OS & arch, you may download & install them manually:" + for line in $urls; do + action_detail "$line" + done + exit 1 + fi + done + # if we're here, we've reached maxtries + action_error "Reached max tries, aborting" + exit 1 } prepare_temp_folder() {