From b1ea89ba3d09840834f977fd6fdd09a56ed6fbba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A0=81=E5=86=9C=E9=98=BF=E6=A5=A0?= Date: Wed, 9 Sep 2026 23:31:26 +0800 Subject: [PATCH] =?UTF-8?q?fix(ci):=20=E5=8F=91=E7=89=88=E9=87=8D=E8=B7=91?= =?UTF-8?q?=E5=B9=82=E7=AD=89=EF=BC=9A=E5=88=B7=E6=96=B0=E5=8F=91=E5=B8=83?= =?UTF-8?q?=E8=AF=B4=E6=98=8E=E5=B9=B6=E6=9B=BF=E6=8D=A2=E6=97=A7=E9=99=84?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 同 tag 重跑时 POST 冲突走查询回退,需 PATCH 以本次构建为准补写 发布说明,并先清空旧附件再重传,避免同名副本。 --- .gitea/workflows/release.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml index a14069a..4b528c9 100644 --- a/.gitea/workflows/release.yml +++ b/.gitea/workflows/release.yml @@ -83,17 +83,25 @@ jobs: } > release-notes.md cat release-notes.md + # 重跑幂等:release 已存在时更新说明、清旧附件后重传 - name: 创建 Release 并上传产物 run: | set -euo pipefail API="$SITE/api/v1/repos/$REPO" AUTH="Authorization: token ${TOKEN}" REQ=$(node -e 'const fs=require("fs");process.stdout.write(JSON.stringify({tag_name:process.env.TAG,name:"pn "+process.env.TAG,body:fs.readFileSync("release-notes.md","utf8")}))') - # 同 tag release 已存在(如重跑)时回退为查询 + # 同 tag release 已存在(如失败重跑)时回退为查询 REL=$(curl -fsS -X POST "$API/releases" -H "$AUTH" -H 'Content-Type: application/json' -d "$REQ") \ || REL=$(curl -fsS "$API/releases/tags/${TAG}" -H "$AUTH") RID=$(REL="$REL" node -e 'process.stdout.write(String(JSON.parse(process.env.REL).id))') echo "==> release id=$RID" + # 发布说明以本次构建为准(回退路径下 POST 已冲突,须补写) + curl -fsS -X PATCH "$API/releases/$RID" -H "$AUTH" -H 'Content-Type: application/json' -d "$REQ" >/dev/null + # 清除旧附件,避免重跑产生同名副本 + ASSETS=$(curl -fsS "$API/releases/$RID/assets" -H "$AUTH") + ASSETS="$ASSETS" node -e 'JSON.parse(process.env.ASSETS).forEach(a=>console.log(a.id))' | while read -r aid; do + curl -fsS -X DELETE "$API/releases/$RID/assets/$aid" -H "$AUTH" >/dev/null + done for f in dist/*; do echo "==> 上传 $(basename "$f")" curl -fsS -X POST "$API/releases/$RID/assets?name=$(basename "$f")" -H "$AUTH" -F "attachment=@$f" >/dev/null