diff --git a/.gitea/workflows/ci-main.yml b/.gitea/workflows/ci-main.yml index b32cd79..04e24bb 100644 --- a/.gitea/workflows/ci-main.yml +++ b/.gitea/workflows/ci-main.yml @@ -183,25 +183,25 @@ jobs: env: GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} run: | + set -ex if [ -z "$GITEA_TOKEN" ]; then echo "Error: GITEA_TOKEN secret is not set" exit 1 fi VERSION=${{ steps.version.outputs.version }} API="${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases" - echo "=== Debug ===" - echo "GITEA_TOKEN length: ${#GITEA_TOKEN}" - echo "API endpoint: ${API}" echo "Creating release ${VERSION} at ${API}" - EXISTING_ID=$(curl -s -H "Authorization: token ${GITEA_TOKEN}" "${API}/tags/${VERSION}" | grep -o '"id":[0-9]*' | head -1 | grep -o '[0-9]*') - if [ -n "$EXISTING_ID" ]; then - echo "Release ${VERSION} already exists (ID: ${EXISTING_ID}), deleting..." - curl -s -X DELETE -H "Authorization: token ${GITEA_TOKEN}" "${API}/${EXISTING_ID}" - echo "Deleted existing release" + EXISTING=$(curl -sf -H "Authorization: token ${GITEA_TOKEN}" "${API}/tags/${VERSION}" || echo "") + if [ -n "$EXISTING" ]; then + EXISTING_ID=$(echo "$EXISTING" | python3 -c "import sys,json; print(json.load(sys.stdin).get('id',''))" 2>/dev/null || echo "") + if [ -n "$EXISTING_ID" ]; then + echo "Release ${VERSION} already exists (ID: ${EXISTING_ID}), deleting..." + curl -sf -X DELETE -H "Authorization: token ${GITEA_TOKEN}" "${API}/${EXISTING_ID}" || true + fi fi - BODY=$(cat /tmp/stable_changelog.md) + BODY=$(python3 -c "import json,sys; print(json.dumps(sys.stdin.read()))" < /tmp/stable_changelog.md) RESPONSE=$(curl -s -w "\n%{http_code}" -X POST "${API}" \ -H "Authorization: token ${GITEA_TOKEN}" \ -H "Content-Type: application/json" \ @@ -209,7 +209,7 @@ jobs: \"tag_name\":\"${VERSION}\", \"target_commitish\":\"main\", \"name\":\"muyue ${VERSION}\", - \"body\":$(echo "$BODY" | jq -Rs .), + \"body\":${BODY}, \"draft\":false, \"prerelease\":false }") @@ -217,7 +217,7 @@ jobs: RESPONSE_BODY=$(echo "$RESPONSE" | sed '$d') echo "HTTP Status: ${HTTP_CODE}" echo "Response: ${RESPONSE_BODY}" - RELEASE_ID=$(echo "$RESPONSE_BODY" | grep -o '"id":[0-9]*' | head -1 | grep -o '[0-9]*') + RELEASE_ID=$(echo "$RESPONSE_BODY" | python3 -c "import sys,json; print(json.load(sys.stdin).get('id',''))" 2>/dev/null || echo "") if [ -z "$RELEASE_ID" ]; then echo "Failed to create release" exit 1