From c815fb4cc89db6fb8be8dc13996e8f964b81a5e0 Mon Sep 17 00:00:00 2001 From: voson Date: Sat, 21 Mar 2026 11:33:45 +0800 Subject: [PATCH] =?UTF-8?q?ci:=20=E4=BF=AE=E5=A4=8D=E8=A6=86=E7=9B=96?= =?UTF-8?q?=E9=87=8D=E5=8F=91=E6=97=B6=20Release=20=E5=94=AF=E4=B8=80?= =?UTF-8?q?=E7=BA=A6=E6=9D=9F=E5=86=B2=E7=AA=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit DELETE + POST 同名 release 会触发 Gitea 的 UQE_release_n 约束。 改为:已有 release → PATCH 更新 name/body,再逐个删除旧 assets 后重传; 无 release → 正常 POST 新建。 Made-with: Cursor --- .gitea/workflows/secrets.yml | 57 +++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 21 deletions(-) diff --git a/.gitea/workflows/secrets.yml b/.gitea/workflows/secrets.yml index 23c606c..725f93f 100644 --- a/.gitea/workflows/secrets.yml +++ b/.gitea/workflows/secrets.yml @@ -140,37 +140,52 @@ jobs: [ -z "$changes" ] && changes="- 首次发布" body=$(printf '## 变更日志\n\n%s' "$changes") - payload=$(jq -n \ - --arg tag "$tag" \ + meta=$(jq -n \ --arg name "secrets-mcp ${version}" \ --arg body "$body" \ - '{tag_name: $tag, name: $name, body: $body, draft: false}') + '{name: $name, body: $body, draft: false}') - # 若已存在同名 Release 则先删除(覆盖重发) + # 若已存在同名 Release,PATCH 更新(避免 DELETE+POST 触发唯一约束冲突) existing_code=$(curl -sS -o /tmp/existing-release.json -w '%{http_code}' \ -H "Authorization: token $RELEASE_TOKEN" \ "${release_api}/tags/${tag}") + if [ "$existing_code" = "200" ]; then - old_id=$(jq -r '.id // empty' /tmp/existing-release.json) - if [ -n "$old_id" ]; then - curl -sS -o /dev/null -H "Authorization: token $RELEASE_TOKEN" \ - -X DELETE "${release_api}/${old_id}" - echo "已删除旧 Release: ${old_id}" + release_id=$(jq -r '.id // empty' /tmp/existing-release.json) + http_code=$(curl -sS -o /tmp/release.json -w '%{http_code}' \ + -H "Authorization: token $RELEASE_TOKEN" \ + -H "Content-Type: application/json" \ + -X PATCH "${release_api}/${release_id}" -d "$meta") + echo "已更新旧 Release: ${release_id} (HTTP ${http_code})" + + # 删除旧 assets,上传前清空 + jq -r '.[].id' <<< "$(curl -sS \ + -H "Authorization: token $RELEASE_TOKEN" \ + "${release_api}/${release_id}/assets")" | while read -r aid; do + curl -sS -o /dev/null \ + -H "Authorization: token $RELEASE_TOKEN" \ + -X DELETE "${release_api}/${release_id}/assets/${aid}" + done + else + # 首次创建 + create_payload=$(jq -n \ + --arg tag "$tag" \ + --arg name "secrets-mcp ${version}" \ + --arg body "$body" \ + '{tag_name: $tag, name: $name, body: $body, draft: false}') + http_code=$(curl -sS -o /tmp/release.json -w '%{http_code}' \ + -H "Authorization: token $RELEASE_TOKEN" \ + -H "Content-Type: application/json" \ + -X POST "$release_api" -d "$create_payload") + if [ "$http_code" != "201" ] && [ "$http_code" != "200" ]; then + echo "创建 Release 失败 (HTTP ${http_code})" + cat /tmp/release.json || true + exit 1 fi + release_id=$(jq -r '.id' /tmp/release.json) + echo "已创建 Release: ${release_id}" fi - http_code=$(curl -sS -o /tmp/release.json -w '%{http_code}' \ - -H "Authorization: token $RELEASE_TOKEN" \ - -H "Content-Type: application/json" \ - -X POST "$release_api" -d "$payload") - - if [ "$http_code" != "201" ] && [ "$http_code" != "200" ]; then - echo "创建 Release 失败 (HTTP ${http_code})" - cat /tmp/release.json || true - exit 1 - fi - release_id=$(jq -r '.id' /tmp/release.json) - bin="target/${MUSL_TARGET}/release/${MCP_BINARY}" archive="${MCP_BINARY}-${tag}-x86_64-linux-musl.tar.gz" tar -czf "$archive" -C "$(dirname "$bin")" "$(basename "$bin")"