修发行版重复附件:重发前先删同名

Gitea 的发行版复用逻辑有 bug:发现标签已有发行版就复用,
但**没有先删同名附件**,于是每跑一次就多传一份。
调试期间同一个文件在 EzHub 上堆了 3 份(共 8 个附件,实际只要 3 个)。

修法:复用已有发行版时,先列出它的附件,
把和本次要传的同名的删掉,再传。

配套加了:
  * clean_ezhub_assets.py  清理已堆积的重复(同名只留最新,支持 --dry)
  * verify_releases.py     对账两个平台的发行版(标题/说明/附件/
                           管理页字眼/两边说明是否一致)

已清理:EzHub 从 8 个附件降到 3 个。
This commit is contained in:
xmz7891
2026-10-07 12:36:35 +08:00
parent 4b545ea324
commit 2425f8694e
3 changed files with 229 additions and 0 deletions
+24
View File
@@ -196,6 +196,30 @@ def gitea_release(token: str, version: str, body: str,
print(" ✗ 建发行版失败 HTTP %s: %s" % (exc.code, detail))
return False
# 先把同名旧附件删掉。
# 不删的话,复用已有发行版时每跑一次就多传一份 ——
# 实测调试期间同一个文件堆了 3 份。
try:
req = urllib.request.Request(
"%s/releases/%s" % (api, rid), headers=auth)
with urllib.request.urlopen(req, timeout=60) as resp:
existing = json.loads(resp.read().decode("utf-8", "replace"))
wanted = {p.name for p in files}
for asset in (existing.get("assets") or []):
if asset.get("name") in wanted:
del_url = "%s/releases/%s/assets/%s" % (api, rid,
asset.get("id"))
dreq = urllib.request.Request(del_url, method="DELETE",
headers=auth)
try:
urllib.request.urlopen(dreq, timeout=60)
print(" • 删掉同名旧附件 %s" % asset.get("name"))
except urllib.error.HTTPError as exc:
print(" • 删 %s 失败 HTTP %s(继续)"
% (asset.get("name"), exc.code))
except Exception as exc: # noqa: BLE001
print(" • 清理旧附件时出错(继续): %s" % exc)
ok = 0
for path in files:
boundary = "----yk" + uuid.uuid4().hex