fix(release): only trust a finished asset, replace a broken one
GitHub answers 201 when it accepts an upload, not when the file is stored: the 1.35 GiB transfer died on a DNS hiccup and left a "starter" asset, which the next run then treated as already published. Only state=uploaded now counts, an incomplete asset is deleted before the retry, and the result is checked again after the upload instead of being assumed.
This commit is contained in:
1 file changed
+25
-3
+25
-3
@@ -474,9 +474,20 @@ publish_github() {
|
|||||||
|
|
||||||
info "GitHub : envoi de $ISO_NAME ($(( ISO_BYTES / 1024 / 1024 )) Mio)…"
|
info "GitHub : envoi de $ISO_NAME ($(( ISO_BYTES / 1024 / 1024 )) Mio)…"
|
||||||
gh_api GET "/repos/$GH_REPO/releases/$release_id/assets"
|
gh_api GET "/repos/$GH_REPO/releases/$release_id/assets"
|
||||||
if echo "$HTTP_BODY" | jq -e --arg n "$ISO_NAME" 'any(.[]; .name == $n)' >/dev/null 2>&1; then
|
local existing_id existing_state
|
||||||
warn "GitHub : $ISO_NAME déjà joint à la release — envoi sauté."
|
existing_id="$(echo "$HTTP_BODY" | jq -r --arg n "$ISO_NAME" '[.[] | select(.name == $n)] | first | .id // empty' 2>/dev/null || true)"
|
||||||
|
existing_state="$(echo "$HTTP_BODY" | jq -r --arg n "$ISO_NAME" '[.[] | select(.name == $n)] | first | .state // empty' 2>/dev/null || true)"
|
||||||
|
if [ -n "$existing_id" ] && [ "$existing_state" = "uploaded" ]; then
|
||||||
|
warn "GitHub : $ISO_NAME déjà joint et complet — envoi sauté."
|
||||||
else
|
else
|
||||||
|
# A "starter" asset is a transfer that never finished: it holds the name
|
||||||
|
# without holding a usable file, so it has to go before the retry.
|
||||||
|
if [ -n "$existing_id" ]; then
|
||||||
|
warn "GitHub : $ISO_NAME présent mais incomplet (état '${existing_state:-?}') — suppression puis renvoi."
|
||||||
|
gh_api DELETE "/repos/$GH_REPO/releases/assets/$existing_id"
|
||||||
|
[ "$HTTP_CODE" = "204" ] \
|
||||||
|
|| { pub_err "GitHub : suppression de l'asset incomplet impossible (HTTP $HTTP_CODE)."; return 1; }
|
||||||
|
fi
|
||||||
# Assets are served by uploads.github.com, not api.github.com: the
|
# Assets are served by uploads.github.com, not api.github.com: the
|
||||||
# request goes to that host verbatim. -T streams the file, -X POST
|
# request goes to that host verbatim. -T streams the file, -X POST
|
||||||
# because GitHub accepts nothing else for an asset upload.
|
# because GitHub accepts nothing else for an asset upload.
|
||||||
@@ -488,7 +499,18 @@ publish_github() {
|
|||||||
"$GH_UPLOAD/repos/$GH_REPO/releases/$release_id/assets?name=$ISO_NAME"
|
"$GH_UPLOAD/repos/$GH_REPO/releases/$release_id/assets?name=$ISO_NAME"
|
||||||
[ "$HTTP_CODE" = "201" ] || [ "$HTTP_CODE" = "200" ] \
|
[ "$HTTP_CODE" = "201" ] || [ "$HTTP_CODE" = "200" ] \
|
||||||
|| { pub_err "$(upload_error GitHub "$HTTP_CODE")"; return 1; }
|
|| { pub_err "$(upload_error GitHub "$HTTP_CODE")"; return 1; }
|
||||||
success "GitHub : ISO jointe."
|
|
||||||
|
# An accepted request is not a stored file: GitHub keeps a "starter"
|
||||||
|
# asset when the transfer dies halfway, which is invisible in the UI
|
||||||
|
# until someone tries to download the ISO.
|
||||||
|
gh_api GET "/repos/$GH_REPO/releases/$release_id/assets"
|
||||||
|
if echo "$HTTP_BODY" | jq -e --arg n "$ISO_NAME" \
|
||||||
|
'any(.[]; .name == $n and .state == "uploaded")' >/dev/null 2>&1; then
|
||||||
|
success "GitHub : ISO jointe et finalisée."
|
||||||
|
else
|
||||||
|
pub_err "GitHub : l'asset $ISO_NAME n'est pas finalisé (état incomplet) — relance avec --skip-build."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
GITHUB_RESULT="ok"
|
GITHUB_RESULT="ok"
|
||||||
|
|||||||
Reference in new issue
Block a user