From c2659dcb1d0cb40ac8349dae3482e8165711ffd1 Mon Sep 17 00:00:00 2001 From: kfj001 Date: Mon, 31 Aug 2026 00:31:40 -0700 Subject: [PATCH] ci: make release step idempotent + fix Gitea asset upload - resolve-or-create the release by tag to avoid the 409 'Release is has no Tag' when a release already exists for the tag (e.g. one made manually in the UI) - use POST /releases/{id}/assets with multipart field 'attachment' (was the obsolete /_attachments route with field 'file') --- .github/workflows/release.yml | 45 ++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 44fb759..8c28231 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -42,13 +42,40 @@ jobs: exit 0 fi - release_id=$(curl -s -X POST \ - -H "Authorization: token $GITEA_TOKEN" \ - -H "Content-Type: application/json" \ - -d "{\"tag_name\": \"$TAG\", \"name\": \"$TAG\", \"body\": \"Automated release build for $TAG\"}" \ - "$GITEA_API/repos/$REPO/releases" | node -e 'let d="";process.stdin.on("data",c=>d+=c).on("end",()=>{const j=JSON.parse(d);if(j.id==null){console.error("release create failed:",JSON.stringify(j));process.exit(1)}console.log(j.id)})') + json_id() { node -e 'let d="";process.stdin.on("data",c=>d+=c).on("end",()=>{const j=JSON.parse(d||"{}");if(j.id==null){console.error("no release id:",JSON.stringify(j));process.exit(1)}console.log(j.id)})'; } - curl -s -X POST \ - -H "Authorization: token $GITEA_TOKEN" \ - -F "file=@vidplex-${TAG}.zip" \ - "$GITEA_API/repos/$REPO/releases/$release_id/_attachments" \ No newline at end of file + release_id=$( + curl -s -o /tmp/rel.json -w "%{http_code}" \ + -H "Authorization: token $GITEA_TOKEN" \ + "$GITEA_API/repos/$REPO/releases/tags/$TAG" + ) + + if [ "$release_id" = "200" ]; then + echo "Release for $TAG already exists; reusing it." + release_id=$(json_id < /tmp/rel.json) + else + echo "Creating release for $TAG." + release_id=$( + curl -s -o /tmp/rel.json -w "%{http_code}" -X POST \ + -H "Authorization: token $GITEA_TOKEN" \ + -H "Content-Type: application/json" \ + -d "{\"tag_name\": \"$TAG\", \"name\": \"$TAG\", \"body\": \"Automated release build for $TAG\"}" \ + "$GITEA_API/repos/$REPO/releases" + ) + case "$release_id" in + 201|200) release_id=$(json_id < /tmp/rel.json) ;; + *) echo "::error::release create returned HTTP $release_id: $(cat /tmp/rel.json)"; exit 1 ;; + esac + fi + + echo "Uploading asset to release $release_id." + resp=$(curl -s -o /tmp/att.json -w "%{http_code}" -X POST \ + -H "Authorization: token $GITEA_TOKEN" \ + -F "attachment=@vidplex-${TAG}.zip" \ + "$GITEA_API/repos/$REPO/releases/$release_id/assets") + if [ "$resp" != "200" ] && [ "$resp" != "201" ]; then + echo "::error::asset upload returned HTTP $resp: $(cat /tmp/att.json)" + exit 1 + fi + cat /tmp/att.json + echo \ No newline at end of file