From 47b12895fd4c992cd519a37ff72e74474ad70f54 Mon Sep 17 00:00:00 2001 From: Daniel Samson Date: Sat, 17 Oct 2026 14:17:26 +0100 Subject: [PATCH] ci: read the release id correctly and reuse an existing release Co-Authored-By: Claude Sonnet 5.5 --- .github/workflows/release.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 48f238c..fcc714c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -62,11 +62,17 @@ jobs: code=$(curl -sS -o "$resp" -w '%{http_code}' -X POST "$api/releases" \ -H "Authorization: token $TOKEN" -H "Content-Type: application/json" \ -d "{\"tag_name\":\"$TAG\",\"name\":\"$TAG\",\"body\":${body}}") - if [ "$code" != "201" ]; then + if [ "$code" = "409" ]; then + # The release already exists (e.g. an earlier run created it): reuse it. + code=$(curl -sS -o "$resp" -w '%{http_code}' -H "Authorization: token $TOKEN" "$api/releases/tags/$TAG") + fi + if [ "$code" != "201" ] && [ "$code" != "200" ]; then echo "creating the release failed: HTTP $code"; cat "$resp"; echo exit 1 fi - id=$(sed -n 's/.*"id":\([0-9]*\).*/\1/p' "$resp" | head -1) + # The release's own id is the first key; later "id"s belong to nested objects. + id=$(sed -n 's/^{"id":\([0-9]*\),.*/\1/p' "$resp" | head -1) + [ -n "$id" ] || { echo "could not read the release id"; cat "$resp"; echo; exit 1; } for f in dist/*; do echo "uploading $f" code=$(curl -sS -o "$resp" -w '%{http_code}' -X POST "$api/releases/$id/assets?name=$(basename "$f")" \