diff --git a/deploy/publish-release.sh b/deploy/publish-release.sh index 94b4fa6..d142c49 100644 --- a/deploy/publish-release.sh +++ b/deploy/publish-release.sh @@ -42,19 +42,30 @@ else echo "release $TAG already exists (id $id): replacing its files" fi -existing=$(curl -fsS -H "$AUTH" "$API/releases/$id/assets" | json 'import sys, json +# the ids of the release's assets with a given name (a failed upload can leave a partial one behind) +asset_ids() { + curl -fsS -H "$AUTH" "$API/releases/$id/assets" | "$PY" -c 'import sys, json for a in json.load(sys.stdin): - print(a["id"], a["name"])') + if a["name"] == sys.argv[1]: + print(a["id"])' "$1" +} for f in dist/*.tar.gz dist/*.zip dist/SHA256SUMS; do [ -f "$f" ] || continue name=$(basename "$f") - echo "$existing" | while read -r aid aname; do - if [ "$aname" = "$name" ]; then + n=1 + while :; do + for aid in $(asset_ids "$name"); do curl -fsS -X DELETE -H "$AUTH" "$API/releases/$id/assets/$aid" > /dev/null + done + echo "uploading $name (attempt $n)" + if curl -fsS --max-time 1200 -X POST -H "$AUTH" -F "attachment=@$f" "$API/releases/$id/assets?name=$name" > /dev/null; then + break fi + # large uploads can hit a proxy timeout (HTTP 502); try again + [ "$n" -lt 5 ] || { echo "giving up on $name after $n attempts" >&2; exit 1; } + n=$((n + 1)) + sleep $((n * 10)) done - echo "uploading $name" - curl -fsS -X POST -H "$AUTH" -F "attachment=@$f" "$API/releases/$id/assets?name=$name" > /dev/null done echo "published $SERVER/$REPO/releases/tag/$TAG"