From fb1bd57af064b7a60d3a946c80cb1900c7ab3128 Mon Sep 17 00:00:00 2001 From: gouki Date: Sun, 9 Aug 2026 20:14:31 +0000 Subject: [PATCH] =?UTF-8?q?feat(ci):=20=E5=8F=91=E5=B8=83=E5=90=8E?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E6=B8=85=E7=90=86=E6=97=A7=E7=89=88=E6=9C=AC?= =?UTF-8?q?=EF=BC=8Cserver-v*=20Release=20=E4=BB=85=E4=BF=9D=E7=95=99?= =?UTF-8?q?=E6=9C=80=E8=BF=91=2010=20=E4=B8=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 超出部分连同附件与 tag 一并删除,防止磁盘被部署包占满 - 纯 grep/sed 解析,不依赖 python3/jq;已对真实 API 验证提取逻辑 --- .gitea/workflows/server-deploy.yml | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/.gitea/workflows/server-deploy.yml b/.gitea/workflows/server-deploy.yml index 0d11d97..5a914a3 100644 --- a/.gitea/workflows/server-deploy.yml +++ b/.gitea/workflows/server-deploy.yml @@ -151,6 +151,35 @@ jobs: -o /dev/null -w "附件上传: HTTP %{http_code}\n" echo "发布地址: https://gitea.neatcn.com/gouki/lunar-mini/releases/tag/$TAG" + - name: Cleanup old releases (keep latest 10) + env: + LUNAR_PUBLISH_TOKEN: ${{ secrets.LUNAR_PUBLISH_TOKEN }} + run: | + # 只保留最近 10 个 server-v* 发布,避免附件无限堆积占满磁盘 + API="https://gitea.neatcn.com/api/v1/repos/gouki/lunar-mini" + TOKEN="${LUNAR_PUBLISH_TOKEN:-$GITEA_TOKEN}" + AUTH="Authorization: token $TOKEN" + KEEP=10 + + # Gitea Release JSON 中 id 与 tag_name 相邻且按新到旧排序; + # 附件随 release 删除一并清理 + PAIRS=$(curl -sS -H "$AUTH" "$API/releases?limit=50" \ + | grep -oE '"id":[0-9]+,"tag_name":"server-v[^"]*"' || true) + TOTAL=$(printf '%s\n' "$PAIRS" | grep -c '"id"' || true) + if [ "$TOTAL" -le "$KEEP" ]; then + echo "当前 $TOTAL 个发布版本,未超过 $KEEP,无需清理" + exit 0 + fi + + printf '%s\n' "$PAIRS" | tail -n +$((KEEP + 1)) | while IFS= read -r line; do + [ -z "$line" ] && continue + RID=$(printf '%s' "$line" | grep -oE '"id":[0-9]+' | cut -d: -f2) + RTAG=$(printf '%s' "$line" | sed 's/.*"tag_name":"\([^"]*\)".*/\1/') + curl -sS -X DELETE -H "$AUTH" "$API/releases/$RID" -o /dev/null -w "删除旧发布 $RTAG: HTTP %{http_code}\n" + # 同步删除自动创建的 tag,避免 tag 堆积 + curl -sS -X DELETE -H "$AUTH" "$API/tags/$RTAG" -o /dev/null -w "删除 tag $RTAG: HTTP %{http_code}\n" + done + - name: Send success notification if: success() env: