ci(release): tolerate Cloudflare 524 timeouts on APK uploads
dev / Build debug APK (push) Successful in 36s
dev / Build debug APK (push) Successful in 36s
The v0.3.7.1 release run failed in the attach step: the 28.7 MB debug APK upload took ~126s through the Cloudflare proxy, which returned "error code: 524" (origin timeout, ~100s limit). The step then crashed parsing the non-JSON error page as JSON, and the release APK was never attempted — leaving release 36 with zero assets. upload_asset() now: - retries with --retry-all-errors so HTTP error responses (524) are retried, not just connection failures; - verifies success server-side by listing the release assets after each attempt (a 524 often means the origin saved the file before Cloudflare gave up, so the response body is not trusted); - only fails after 5 attempts with the asset still missing.
This commit is contained in:
1 parent
37e9c14d1e
commit
4a28f4f52b
1 file changed
+32
-8
@@ -120,6 +120,37 @@ jobs:
|
||||
|
||||
echo "aW1wb3J0IHN5cywganNvbiwgdXJsbGliLnJlcXVlc3QKYXBpID0gc3lzLmFyZ3ZbMV0KcmVsZWFzZV9pZCA9IHN5cy5hcmd2WzJdCmFwayA9IHN5cy5hcmd2WzNdCnRva2VuID0gc3lzLmFyZ3ZbNF0KcmVxID0gdXJsbGliLnJlcXVlc3QuUmVxdWVzdCgKICAgIGYie2FwaX0vcmVsZWFzZXMve3JlbGVhc2VfaWR9L2Fzc2V0cyIsCiAgICBoZWFkZXJzPXsiQXV0aG9yaXphdGlvbiI6IGYidG9rZW4ge3Rva2VufSJ9CikKcmVzcCA9IHVybGxpYi5yZXF1ZXN0LnVybG9wZW4ocmVxKQpmb3IgYSBpbiBqc29uLmxvYWRzKHJlc3AucmVhZCgpKToKICAgIGlmIGFbIm5hbWUiXSA9PSBhcGs6CiAgICAgICAgZGVsZXRlX3JlcSA9IHVybGxpYi5yZXF1ZXN0LlJlcXVlc3QoCiAgICAgICAgICAgIGYie2FwaX0vcmVsZWFzZXMve3JlbGVhc2VfaWR9L2Fzc2V0cy97YVsnaWQnXX0iLAogICAgICAgICAgICBtZXRob2Q9IkRFTEVURSIsCiAgICAgICAgICAgIGhlYWRlcnM9eyJBdXRob3JpemF0aW9uIjogZiJ0b2tlbiB7dG9rZW59In0KICAgICAgICApCiAgICAgICAgdXJsbGliLnJlcXVlc3QudXJsb3BlbihkZWxldGVfcmVxKQogICAgICAgIHByaW50KGYiRGVsZXRlZCB7YVsnaWQnXX0iLCBmbHVzaD1UcnVlKQo=" | base64 -d > /tmp/delete_asset.py
|
||||
|
||||
# Upload one asset with retries, then verify server-side.
|
||||
# Cloudflare sits in front of the origin and returns
|
||||
# "error code: 524" (origin timeout, ~100s) on large/slow
|
||||
# uploads — the file frequently lands on the origin anyway,
|
||||
# so success is decided by listing the release's assets
|
||||
# rather than trusting the upload response body (which may
|
||||
# be a non-JSON Cloudflare error page).
|
||||
upload_asset() {
|
||||
local apk_name="$1" apk_path="$2"
|
||||
local attempt
|
||||
for attempt in 1 2 3 4 5; do
|
||||
echo "--- Uploading $apk_name (attempt $attempt/5) ---"
|
||||
ls -la "$apk_path"
|
||||
UPLOAD=$(curl -s -f -X POST "$API/releases/$RELEASE_ID/assets?name=$apk_name" \
|
||||
-H "Authorization: token $GH_TOKEN" \
|
||||
-F "attachment=@$apk_path" \
|
||||
--max-time 600 --retry 2 --retry-all-errors --retry-delay 15 || true)
|
||||
echo "Upload response: ${UPLOAD:0:200}"
|
||||
if curl -s "$API/releases/$RELEASE_ID" \
|
||||
-H "Authorization: token $GH_TOKEN" \
|
||||
| python3 -c "import sys,json; d=json.load(sys.stdin); sys.exit(0 if any(a['name']=='$apk_name' for a in d['assets']) else 1)"; then
|
||||
echo "Verified: $apk_name is attached to the release."
|
||||
return 0
|
||||
fi
|
||||
echo "Asset not on the server yet — retrying in 15s..."
|
||||
sleep 15
|
||||
done
|
||||
echo "ERROR: $apk_name failed to attach after 5 attempts."
|
||||
return 1
|
||||
}
|
||||
|
||||
for APK in "$APK_DEBUG" "$APK_RELEASE"; do
|
||||
if echo "$APK" | grep -q "debug"; then
|
||||
APK_PATH="app/build/outputs/apk/debug/app-debug.apk"
|
||||
@@ -134,14 +165,7 @@ jobs:
|
||||
echo "--- Deleting stale assets for $APK ---"
|
||||
python3 /tmp/delete_asset.py "$API" "$RELEASE_ID" "$APK" "$GH_TOKEN"
|
||||
|
||||
echo "--- Uploading $APK ---"
|
||||
ls -la "$APK_PATH"
|
||||
UPLOAD=$(curl -s -X POST "$API/releases/$RELEASE_ID/assets?name=$APK" \
|
||||
-H "Authorization: token $GH_TOKEN" \
|
||||
-F "attachment=@$APK_PATH" \
|
||||
--max-time 600 --retry 3 --retry-delay 10)
|
||||
echo "Upload response: $UPLOAD"
|
||||
echo "$UPLOAD" | python3 -c "import sys,json; d=json.loads(sys.stdin.read()); print('Asset uploaded:', d.get('name','?'), d.get('id','?'))"
|
||||
upload_asset "$APK" "$APK_PATH" || exit 1
|
||||
done
|
||||
|
||||
echo "--- Final release state ---"
|
||||
|
||||
Reference in new issue
Block a user