chore(scripts): 发布脚本自动清理历史版本附件(只保留最近 2 个版本)

- 发布完成后查询 Releases 列表(按创建时间倒序),仅保留最近两个版本的安装包;
- 更早版本的附件自动删除(Release 记录与更新说明保留,历史页面仍可查阅);
- 清理失败仅打印警告,不影响本次发布结果。
This commit is contained in:
2026-10-09 14:52:53 +08:00
parent 233a329c0a
commit d0e6ce457e
+37 -1
View File
@@ -9,7 +9,9 @@
# - 更新说明写入 Release 正文(Markdown),客户端「检查更新」时读取展示;
# - 安卓 APK:默认取 release\sequence_diagram_android_v<版本>_release.apk;
# - Windows 绿色版:默认把 dist\ 打包为 zip 后上传(客户端下载后原地覆盖);
# - 安装包作为 Release 附件保存,不进入 git 历史,仓库保持精简。
# - 安装包作为 Release 附件保存,不进入 git 历史,仓库保持精简;
# - 发布完成后自动清理历史附件:只保留最近 2 个版本的安装包
# (Release 记录与更新说明保留,仅删除更早版本的附件,释放服务器空间)。
# ============================================================
param(
[Parameter(Mandatory = $true)][string]$Version,
@@ -78,5 +80,39 @@ function Upload-Asset([string]$path) {
Upload-Asset $ApkPath
Upload-Asset $WindowsZipPath
# ---- 4) 清理历史版本附件:只保留最近 2 个版本的安装包 ----
# 客户端更新只使用「最新版本」的附件,更早版本的安装包可安全删除以释放空间;
# Release 记录与更新说明保留,历史版本页面仍可查阅。
# 该步骤失败不影响本次发布(仅打印警告)。
$keepVersions = 2
try {
Write-Host ""
Write-Host "清理历史版本附件(只保留最近 $keepVersions 个版本)..."
$listFile = Join-Path $env:TEMP "seq_releases_list.json"
curl.exe -s -o $listFile "$Server/api/v1/repos/$Owner/$Repo/releases?limit=50" | Out-Null
$all = [System.IO.File]::ReadAllText($listFile, [System.Text.Encoding]::UTF8) | ConvertFrom-Json
$ordered = @($all | Sort-Object -Property created_at -Descending)
$freed = 0
for ($i = $keepVersions; $i -lt $ordered.Count; $i++) {
$r = $ordered[$i]
foreach ($a in $r.assets) {
$code = curl.exe -s -o NUL -w "%{http_code}" -X DELETE -u $Auth "$Server/api/v1/repos/$Owner/$Repo/releases/$($r.id)/assets/$($a.id)"
if ($code -eq "204") {
$freed += $a.size
Write-Host " 已清理 $($r.tag_name) / $($a.name)"
} else {
Write-Host " [warn] 清理失败 $($r.tag_name) / $($a.name):HTTP $code"
}
}
}
if ($freed -gt 0) {
Write-Host " 共释放 $([math]::Round($freed / 1MB, 1)) MB"
} else {
Write-Host " 无需清理(仅最近 $keepVersions 个版本带有附件)"
}
} catch {
Write-Host " [warn] 历史附件清理失败(不影响本次发布):$_"
}
Write-Host ""
Write-Host "发布完成!客户端下次启动即可检查到 v$Version($Server/$Owner/$Repo/releases)"