diff --git a/.gitea/workflows/release-docs.yml b/.gitea/workflows/release-docs.yml index aaf781e..ab613cd 100644 --- a/.gitea/workflows/release-docs.yml +++ b/.gitea/workflows/release-docs.yml @@ -28,10 +28,19 @@ jobs: run: | TAG=${GITHUB_REF#refs/tags/} API="${{ github.server_url }}/api/v1/repos/${{ github.repository }}" + AUTH="Authorization: token ${GITEA_TOKEN}" + + # Delete existing release for this tag if any (ignore errors) + EXISTING_ID=$(curl -sf "${API}/releases/tags/${TAG}" -H "$AUTH" 2>/dev/null \ + | python3 -c "import sys,json; print(json.load(sys.stdin).get('id',''))" 2>/dev/null || true) + if [ -n "$EXISTING_ID" ]; then + echo "Deleting existing release #${EXISTING_ID}" + curl -sf -X DELETE "${API}/releases/${EXISTING_ID}" -H "$AUTH" 2>/dev/null || true + fi # Create release curl -sf -X POST "${API}/releases" \ - -H "Authorization: token ${GITEA_TOKEN}" \ + -H "$AUTH" \ -H "Content-Type: application/json" \ -d "{ \"tag_name\": \"${TAG}\", @@ -39,9 +48,8 @@ jobs: \"body\": \"米普云航司API文档更新 ${TAG}\" }" - # Get release ID via python (no jq dependency) - RELEASE_ID=$(curl -sf "${API}/releases/tags/${TAG}" \ - -H "Authorization: token ${GITEA_TOKEN}" \ + # Get release ID + RELEASE_ID=$(curl -sf "${API}/releases/tags/${TAG}" -H "$AUTH" \ | python3 -c "import sys,json; print(json.load(sys.stdin)['id'])") if [ -z "$RELEASE_ID" ] || [ "$RELEASE_ID" = "None" ]; then @@ -49,10 +57,11 @@ jobs: exit 1 fi + echo "Release #${RELEASE_ID} created" + # Upload docs.tar.gz curl -sf -X POST "${API}/releases/${RELEASE_ID}/assets?name=docs.tar.gz" \ - -H "Authorization: token ${GITEA_TOKEN}" \ - -H "Content-Type: multipart/form-data" \ + -H "$AUTH" \ -F "attachment=@/tmp/docs.tar.gz" echo "Release ${TAG} created with docs.tar.gz"