ci: robust Gitea release creation with HTTP status + diagnostics
Release / release (push) Failing after 21s

Previous implementation silently assumed any missing 'id' in POST
response meant "release already exists", then called an unguarded
python3 on the fallback response — which crashes (exit 1) if the
fallback also fails (e.g. release really doesn't exist).

New logic:
- Build JSON payload in Python (avoids shell escaping + CLI length limits)
- Capture HTTP status explicitly
- 201 → success
- 409 or "already exists" message → reuse existing (with HTTP check on fetch)
- Anything else → fail loudly with the response body printed

This also unblocks diagnosis of the current v0.1.0 failure by surfacing
the actual error the Gitea API is returning.
This commit is contained in:
2026-04-21 20:09:55 +03:00
parent 866a8df310
commit e12820f150
+39 -15
View File
@@ -109,23 +109,47 @@ jobs:
print(json.dumps('\n\n'.join(sections)))
")
RELEASE=$(curl -s -X POST "$BASE_URL/releases" \
# Send body via file to avoid CLI length limits / shell escaping
python3 -c "
import json, os
body = os.environ['BODY']
payload = {
'tag_name': os.environ['TAG'],
'name': f\"Notify Bridge {os.environ['VERSION']}\",
'body': json.loads(body),
'draft': False,
'prerelease': os.environ['IS_PRE'] == 'true',
}
open('/tmp/release-payload.json','w').write(json.dumps(payload))
" BODY="$BODY" TAG="$TAG" VERSION="$VERSION" IS_PRE="$IS_PRE"
HTTP=$(curl -s -o /tmp/release-resp.json -w "%{http_code}" \
-X POST "$BASE_URL/releases" \
-H "Authorization: token $DEPLOY_TOKEN" \
-H "Content-Type: application/json" \
-d "{
\"tag_name\": \"$TAG\",
\"name\": \"Notify Bridge $VERSION\",
\"body\": $BODY,
\"draft\": false,
\"prerelease\": $IS_PRE
}")
--data-binary @/tmp/release-payload.json)
# Fallback: if release already exists for this tag, reuse it
RELEASE_ID=$(echo "$RELEASE" | python3 -c "import sys,json; print(json.load(sys.stdin)['id'])" 2>/dev/null)
if [ -z "$RELEASE_ID" ]; then
echo "::warning::Release already exists for tag $TAG — reusing existing release"
RELEASE=$(curl -s "$BASE_URL/releases/tags/$TAG" \
echo "POST /releases → HTTP $HTTP"
echo "--- response ---"
head -c 2000 /tmp/release-resp.json; echo
echo "----------------"
if [ "$HTTP" = "201" ]; then
RELEASE_ID=$(python3 -c "import json; print(json.load(open('/tmp/release-resp.json'))['id'])")
echo "Created release $RELEASE_ID for $TAG"
elif [ "$HTTP" = "409" ] || grep -q "already exists" /tmp/release-resp.json; then
echo "::warning::Release already exists for tag $TAG — reusing"
HTTP2=$(curl -s -o /tmp/release-resp.json -w "%{http_code}" \
"$BASE_URL/releases/tags/$TAG" \
-H "Authorization: token $DEPLOY_TOKEN")
RELEASE_ID=$(echo "$RELEASE" | python3 -c "import sys,json; print(json.load(sys.stdin)['id'])")
if [ "$HTTP2" != "200" ]; then
echo "::error::Failed to fetch existing release (HTTP $HTTP2)"
cat /tmp/release-resp.json
exit 1
fi
RELEASE_ID=$(python3 -c "import json; print(json.load(open('/tmp/release-resp.json'))['id'])")
echo "Reused release $RELEASE_ID for $TAG"
else
echo "::error::Failed to create release for $TAG (HTTP $HTTP)"
exit 1
fi
echo "Created release $RELEASE_ID for $TAG"