diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml index e63eeff..083300a 100644 --- a/.gitea/workflows/release.yml +++ b/.gitea/workflows/release.yml @@ -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"