From 64e2ff8223d4507190c8c2f91a28ef4357f1de02 Mon Sep 17 00:00:00 2001 From: Mat Sutcliffe Date: Wed, 8 Dec 2021 18:39:57 +0000 Subject: [PATCH 1/2] Retry asset upload if curl fails due to connection reset by peer --- entrypoint.sh | 48 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 7ba220f..b6ad292 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -224,21 +224,39 @@ for asset in "$assets"/*; do fi fi - # docs ref: https://developer.github.com/v3/repos/releases/#upload-a-release-asset - status_code="$(curl -sS -X POST \ - --write-out "%{http_code}" -o "$TMP/$file_name.json" \ - -H "Authorization: token $TOKEN" \ - -H "Content-Length: $(stat -c %s "$asset")" \ - -H "Content-Type: $(file -b --mime-type "$asset")" \ - --upload-file "$asset" \ - "$upload_url/$release_id/assets?name=$file_name")" - - if [ "$status_code" -ne "201" ]; then - >&2 echo "::error::failed to upload asset: $file_name (see log for details)" - >&2 printf "\n\tERR: Failed asset upload: %s\n" "$file_name" - >&2 jq . < "$TMP/$file_name.json" - exit 1 - fi + connreset_retry=5 + while true; do + # Don't exit if curl returns a non-zero exit code + set +e + + # docs ref: https://developer.github.com/v3/repos/releases/#upload-a-release-asset + status_code="$(curl -sS -X POST \ + --write-out "%{http_code}" -o "$TMP/$file_name.json" \ + -H "Authorization: token $TOKEN" \ + -H "Content-Length: $(stat -c %s "$asset")" \ + -H "Content-Type: $(file -b --mime-type "$asset")" \ + --upload-file "$asset" \ + "$upload_url/$release_id/assets?name=$file_name")" + + exit_code=$? + set -e + + if [ \( "$exit_code" -eq "55" -o "$exit_code" -eq "56" \) -a "$connreset_retry" -gt "0" ]; then + >&2 echo "failed to upload asset: $file_name (send/recv error; $((connreset_retry-=1)) retries remain)" + sleep 5 + asset_id="$(gh_release_api "$release_id/assets" | jq -r "map(select(.name == \"$file_name\")) | .[] | .id")" + gh_release_api "assets/$asset_id" DELETE + continue + fi + + if [ "$exit_code" -ne "0" -o "$status_code" -ne "201" ]; then + >&2 echo "::error::failed to upload asset: $file_name (see log for details)" + >&2 printf "\n\tERR: Failed asset upload: %s\n" "$file_name" + >&2 jq . < "$TMP/$file_name.json" + exit 1 + fi + break + done done echo "::endgroup::" From d88dab5178ec976b657e7ebfba172bc62250734b Mon Sep 17 00:00:00 2001 From: oktal3700 Date: Sat, 29 Oct 2022 18:12:17 +0100 Subject: [PATCH 2/2] GitHub Actions deprecated the set-output command --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index b6ad292..d2f322a 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -129,7 +129,7 @@ fi release_id="$(jq '.id' < "$TMP/$method.json")" # Make release ID available to other steps in user's workflow -echo "::set-output name=release_id::$release_id" +echo "release_id=$release_id" >>$GITHUB_OUTPUT echo "::endgroup::" #