diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml index ca4b051..b1842eb 100644 --- a/.gitea/workflows/release.yml +++ b/.gitea/workflows/release.yml @@ -8,7 +8,7 @@ on: required: true type: string changelog: - description: "Release notes (markdown, shown on the release page)" + description: "Release notes (markdown, shown on the release page). Single-line field — use literal \\n for line breaks." required: false type: string @@ -178,19 +178,38 @@ jobs: REPO="${GITEA_REPOSITORY:-$GITHUB_REPOSITORY}" TOKEN="${RELEASE_TOKEN:-$GITHUB_TOKEN}" VERSION=$(jq -r '.inputs.version' "$GITHUB_EVENT_PATH") - CHANGELOG=$(jq -r '.inputs.changelog // ""' "$GITHUB_EVENT_PATH") + # The dispatch input is a single-line field; turn literal \n into real newlines. + CHANGELOG=$(jq -r '.inputs.changelog // ""' "$GITHUB_EVENT_PATH" | sed 's/\\n/\n/g') TAG="v$VERSION" API="$SERVER/api/v1/repos/$REPO" AUTH="Authorization: token $TOKEN" - # Re-run safety: drop a previous release (and its tag) for this version. - OLD_ID=$(curl -sf -H "$AUTH" "$API/releases/tags/$TAG" | jq -r '.id // empty') + # curl wrapper: on HTTP >= 400, print the response body (Gitea's error + # message) before failing — plain `curl -f` hides it (exit 22). + api() { + local code body + body=$(mktemp) + code=$(curl -s -o "$body" -w '%{http_code}' "$@") || { cat "$body"; rm -f "$body"; return 1; } + if [ "${code:0:1}" != "2" ]; then + echo "API error $code: $(cat "$body")" >&2 + rm -f "$body" + return 1 + fi + cat "$body" + rm -f "$body" + } + + # Re-run safety: drop a previous release AND its tag for this version. + # (Gitea's DELETE /releases/:id does NOT remove the tag; a leftover tag + # makes the POST below fail with 409.) + OLD_ID=$(api -H "$AUTH" "$API/releases/tags/$TAG" | jq -r '.id // empty') || true if [ -n "$OLD_ID" ]; then - curl -sf -X DELETE -H "$AUTH" "$API/releases/$OLD_ID" > /dev/null + api -X DELETE -H "$AUTH" "$API/releases/$OLD_ID" > /dev/null fi + api -X DELETE -H "$AUTH" "$API/git/refs/tags/$TAG" > /dev/null || true # Gitea creates the tag at the default branch HEAD automatically. - RELEASE_ID=$(curl -sf -X POST -H "$AUTH" -H "Content-Type: application/json" \ + RELEASE_ID=$(api -X POST -H "$AUTH" -H "Content-Type: application/json" \ "$API/releases" \ -d "$(jq -n --arg tag "$TAG" --arg title "Iris $VERSION" --arg body "$CHANGELOG" \ '{tag_name:$tag, title:$title, body:$body}')" \ @@ -200,7 +219,7 @@ jobs: for f in "$GITHUB_WORKSPACE"/iris-android-v* "$GITHUB_WORKSPACE"/iris-desktop-*; do [ -f "$f" ] || continue echo "Uploading $(basename "$f")" - curl -sf -X POST -H "$AUTH" -F "attachment=@$f" \ + api -X POST -H "$AUTH" -F "attachment=@$f" \ "$API/releases/$RELEASE_ID/attachments" > /dev/null done echo "Done: $SERVER/$REPO/releases/tag/$TAG"