From cdc67bc26340e14b1d4ffa9f8661c1a8bf5b8f82 Mon Sep 17 00:00:00 2001 From: Eric Liu Date: Mon, 7 Sep 2026 20:56:20 -0700 Subject: [PATCH] fix(ci): follow Gitea http->https redirect when publishing releases server_url resolves to http and Gitea answers the create-release POST with a 308 redirect; curl without -L returned an empty body and the grep-based id extraction failed under set -e/pipefail, failing v0.1.3 publish. Add -L, reuse an existing release on retry, and parse with python3. --- .gitea/workflows/release.yaml | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/.gitea/workflows/release.yaml b/.gitea/workflows/release.yaml index 9f57c7a..ec4dca0 100644 --- a/.gitea/workflows/release.yaml +++ b/.gitea/workflows/release.yaml @@ -81,21 +81,35 @@ jobs: echo "Publishing release for $tag_name" wheel_file=$(ls plugin/dist/*.whl | head -n 1) tar_file=$(ls plugin/dist/*.tar.gz | head -n 1) + api_url="${{ github.server_url }}/api/v1/repos/${{ github.repository }}" - # Create release - response=$(curl -s -k -X POST "${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases" \ - -H "Authorization: token $GITEA_TOKEN" \ - -H "Content-Type: application/json" \ - -d "{\"tag_name\": \"$tag_name\", \"name\": \"$tag_name\", \"body\": \"Release $tag_name for hermes-meshtastic plugin\"}") + # server_url may be http while Gitea redirects (308) to https: + # curl needs -L or the POST returns an empty body. Release may also + # already exist (retried run) — reuse it instead of failing. + fetch_id() { python3 -c "import json,sys;print(json.load(sys.stdin).get('id') or '')" 2>/dev/null; } + + response=$(curl -s -k -L -H "Authorization: token $GITEA_TOKEN" \ + "$api_url/releases/tags/$tag_name") + release_id=$(printf '%s' "$response" | fetch_id) + + if [ -z "$release_id" ]; then + response=$(curl -s -k -L -X POST "$api_url/releases" \ + -H "Authorization: token $GITEA_TOKEN" \ + -H "Content-Type: application/json" \ + -d "{\"tag_name\": \"$tag_name\", \"name\": \"$tag_name\", \"body\": \"Release $tag_name for hermes-meshtastic plugin\"}") + release_id=$(printf '%s' "$response" | fetch_id) + fi - release_id=$(echo "$response" | grep -o '"id":[0-9]*' | head -n 1 | cut -d: -f2) if [ -n "$release_id" ]; then - curl -s -k -X POST "${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases/$release_id/assets?name=$(basename $wheel_file)" \ + curl -s -k -L -X POST "$api_url/releases/$release_id/assets?name=$(basename "$wheel_file")" \ -H "Authorization: token $GITEA_TOKEN" \ -H "Content-Type: application/octet-stream" \ --data-binary "@$wheel_file" - curl -s -k -X POST "${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases/$release_id/assets?name=$(basename $tar_file)" \ + curl -s -k -L -X POST "$api_url/releases/$release_id/assets?name=$(basename "$tar_file")" \ -H "Authorization: token $GITEA_TOKEN" \ -H "Content-Type: application/octet-stream" \ --data-binary "@$tar_file" + else + echo "ERROR: could not create or fetch release $tag_name" >&2 + exit 1 fi -- 2.52.0