From 8e0dc8f1cc7397e867a4626d23c82f286d246134 Mon Sep 17 00:00:00 2001 From: "Aleksei (Faumaray) Selikhov" Date: Sat, 5 Dec 2026 14:33:04 +0300 Subject: [PATCH] ci(release): reuse an existing release when uploading assets --- .gitea/workflows/release.yml | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml index 1ce2df8..dc9c847 100644 --- a/.gitea/workflows/release.yml +++ b/.gitea/workflows/release.yml @@ -95,12 +95,19 @@ jobs: body="$(printf 'Release %s\n\nBuilt from %s with the full CTest suite green.\nSee SHA256SUMS for artifact digests.' "${tag}" "${GITHUB_SHA}")" payload="$(printf '{"tag_name":"%s","name":"%s","body":"%s","draft":false,"prerelease":false}' \ "${tag}" "${tag}" "${body}")" - release_id="$(curl -fsS -X POST -H "Authorization: token ${TOKEN}" \ - -H "Content-Type: application/json" -d "${payload}" \ - "${api}/releases" | python3 -c 'import json,sys; print(json.load(sys.stdin).get("id",""))')" + extract_id() { + python3 -c 'import json,sys +try: print(json.load(sys.stdin).get("id","")) +except Exception: print("")' + } + # The release may already exist (e.g. created by hand for the tag): fall back to it. + created="$(curl -sS -X POST -H "Authorization: token ${TOKEN}" \ + -H "Content-Type: application/json" -d "${payload}" "${api}/releases" || true)" + release_id="$(printf '%s' "${created}" | extract_id)" if [ -z "${release_id}" ]; then - release_id="$(curl -fsS -H "Authorization: token ${TOKEN}" \ - "${api}/releases/tags/${tag}" | python3 -c 'import json,sys; print(json.load(sys.stdin).get("id",""))')" + existing="$(curl -sS -H "Authorization: token ${TOKEN}" \ + "${api}/releases/tags/${tag}" || true)" + release_id="$(printf '%s' "${existing}" | extract_id)" fi test -n "${release_id}" for file in dist/*; do