From cce993ac0a4cdf79b48f29c255e41ebe07f0f12e Mon Sep 17 00:00:00 2001 From: Daniel Wu Date: Tue, 17 Nov 2026 13:29:38 +0800 Subject: [PATCH] =?UTF-8?q?fix(ci):=20=E4=BF=AE=E5=A4=8D=E5=8F=91=E5=B8=83?= =?UTF-8?q?=E6=B5=81=E6=B0=B4=E7=BA=BF=E6=BA=90=E7=A0=81=E5=8C=85=E5=BD=92?= =?UTF-8?q?=E6=A1=A3=E5=A4=B1=E8=B4=A5=E5=B9=B6=E6=94=AF=E6=8C=81=E9=87=8D?= =?UTF-8?q?=E5=8F=91=E5=B9=82=E7=AD=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 归档产物写到 RUNNER_TEMP,避免 tar 自包含报 file changed as we read it - 创建/复用同 tag Release,同名附件先删后传,修复重发失败 - curl 加 -f 显式失败,避免 HTTP 错误被静默吞掉 --- .gitea/workflows/release.yml | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml index 2879727..0bc492c 100644 --- a/.gitea/workflows/release.yml +++ b/.gitea/workflows/release.yml @@ -27,17 +27,36 @@ jobs: env: GITEA_TOKEN: ${{ secrets.REGISTRY_PUSH_TOKEN }} run: | - set -eu + set -euo pipefail API="${GITHUB_SERVER_URL}/api/v1" REPO="${GITHUB_REPOSITORY}" VERSION="${GITHUB_REF_NAME}" - tar -czf "entitleforge-sdk-${VERSION}.tar.gz" --exclude='.git' . - PAYLOAD=$(printf '{"tag_name":"%s","name":"益铸 EntitleForge SDK %s","body":"go get %s@%s(零第三方依赖)","draft":false,"prerelease":false}' \ - "${VERSION}" "${VERSION}" "${REPO,,}" "${VERSION}") - curl -sS -X POST -H "Authorization: token ${GITEA_TOKEN}" \ - -H "Content-Type: application/json" -d "${PAYLOAD}" \ - "${API}/repos/${REPO}/releases" >/dev/null - echo "Release ${VERSION} 创建完成(go get 引用即发版本体)" + AUTH="Authorization: token ${GITEA_TOKEN}" + # 产物写到仓库外:在 "." 内创建归档会触发 tar "file changed as we read it"。 + ARTIFACT="${RUNNER_TEMP:-/tmp}/entitleforge-sdk-${VERSION}.tar.gz" + tar -czf "${ARTIFACT}" --exclude='.git' . + # 已存在同 tag release 时复用(重发/重跑幂等)。 + RELEASE_ID=$(curl -fsS -H "${AUTH}" "${API}/repos/${REPO}/releases/tags/${VERSION}" \ + | python3 -c "import json,sys; print(json.load(sys.stdin).get('id',''))" 2>/dev/null || true) + if [ -z "${RELEASE_ID}" ]; then + PAYLOAD=$(printf '{"tag_name":"%s","name":"益铸 EntitleForge SDK %s","body":"go get %s@%s(零第三方依赖)","draft":false,"prerelease":false}' \ + "${VERSION}" "${VERSION}" "${REPO,,}" "${VERSION}") + RELEASE_ID=$(curl -fsS -X POST -H "${AUTH}" -H "Content-Type: application/json" -d "${PAYLOAD}" \ + "${API}/repos/${REPO}/releases" \ + | python3 -c "import json,sys; print(json.load(sys.stdin).get('id',''))") + fi + [ -n "${RELEASE_ID}" ] || { echo "release id 获取失败" >&2; exit 1; } + # 同名旧附件先删,保证重发同一版本时附件上传幂等。 + ASSET_NAME="$(basename "${ARTIFACT}")" + curl -fsS -H "${AUTH}" "${API}/repos/${REPO}/releases/${RELEASE_ID}/assets" \ + | python3 -c "import json,sys; [print(a['id']) for a in json.load(sys.stdin) if a.get('name')=='${ASSET_NAME}']" \ + | while read -r aid; do + curl -fsS -o /dev/null -X DELETE -H "${AUTH}" \ + "${API}/repos/${REPO}/releases/${RELEASE_ID}/assets/${aid}" + done + curl -fsS -X POST -H "${AUTH}" --upload-file "${ARTIFACT}" \ + "${API}/repos/${REPO}/releases/${RELEASE_ID}/assets?name=${ASSET_NAME}" >/dev/null + echo "Release ${VERSION} 创建完成(go module tag 即发版本体,源码包已附)" # 清理失败的 action 记录——always():release 失败时更要清理(否则失败轮次永久堆积) cleanup: