Files
EasyDesignCollection/scripts/publish_release.ps1
T
admin 68c2f5d8f1 1.3.5:更名 EDC|易得设计,空白启动首页 + 可扩展图元库识别,架构图大版本
- 品牌:更名 EDC|易得设计(exe/安卓/仓库 EasyDesignCollection;旧地址 301 兼容老客户端更新)
- 首页:空白启动 + 六模块「新建文档」选择 + 最近打开;品牌菜单重做
- 架构图:手绘识别统一图形;Visio 式可扩展图元库(导入 / 存为图元 / 分类折叠 /
  手绘匹配 / 多笔回溯组合);识别后图形尺寸编辑(宽高长径 + 画布标注 + 双击改值);
  IT 系统图元;mm 标尺(右轴数值 / 实线游标 / A0 默认画布);图层、F8 正交 / F10 极轴、
  对齐均布;连线端点换绑重吸附;DXF / SVG / PNG 导出;缩小时画布溢出到侧栏的裁剪修复
- 时序图:分文件保存(*.seq.json / *.arch.json;旧 .edc.json 兼容)
- 路径:运行时目录迁移 %APPDATA%/EDC;素材库 library/;安卓 Documents/EDC
- 清理:参数化草图入口冻结;Windows Ink 原生桥移除;dist/ 退役
- 构建:exe + APK 双端同步(1.3.5+26);发布脚本切换 release/ 新目录结构
2026-10-11 10:19:01 +08:00

152 lines
7.4 KiB
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# ============================================================
# 发布新版本到 Gitea Releases(更新说明 + 安装包附件)
#
# 用法(在仓库根目录或任意位置):
# powershell -File scripts\publish_release.ps1 -Version 1.2.1 `
# -NotesFile release\notes\RELEASE_NOTES_v1.2.1.md
#
# 说明:
# - 更新说明写入 Release 正文(Markdown),客户端「检查更新」时读取展示;
# - 安卓 APK:默认取 release\android\EasyDesignCollection_android_v<版本>_release.apk;
# - Windows 绿色版:默认把 release\windows\EasyDesignCollection\ 打包为 zip
# (客户端下载后原地解压覆盖;zip 内部必须平铺,脚本自动生成于 release\windows\);
# - 安装包作为 Release 附件保存,不进入 git 历史,仓库保持精简;
# - 发布幂等:v<版本> 已存在(如上次上传中断)时复用它并更新说明;
# - 发布完成后自动清理历史附件:只保留「最新 1 个版本」的安装包
# (Release 记录与更新说明保留,仅删除更早版本的附件,释放服务器空间)。
# ============================================================
param(
[Parameter(Mandatory = $true)][string]$Version,
[Parameter(Mandatory = $true)][string]$NotesFile,
[string]$ApkPath = "",
[string]$WindowsZipPath = "",
[string]$Server = "http://124.220.63.9:30000",
[string]$Owner = "admin",
[string]$Repo = "EasyDesignCollection", # 2026-10 由 Sequence-Diagram 改名(旧名保留 301 重定向)
[string]$Auth = "liuyu65@126.com:ds3317210",
# 上传限速(curl --limit-rate):服务器带宽很小(5Mbps),
# 限速上传避免打满带宽把服务器压垮(默认 320KB/s ≈ 2.6Mbps)。
[string]$UploadLimit = "320k"
)
$ErrorActionPreference = "Stop"
$root = Split-Path -Parent $PSScriptRoot # 仓库根目录(scripts 的上一级)
# ---- 1) 定位安装包 ----
if ($ApkPath -eq "") {
$ApkPath = Join-Path $root "release\android\EasyDesignCollection_android_v${Version}_release.apk"
}
if (!(Test-Path $ApkPath)) {
throw "找不到 APK:$ApkPath(先执行 flutter build apk --release 并归档到 release\)"
}
if ($WindowsZipPath -eq "") {
$WindowsZipPath = Join-Path $root "release\windows\EasyDesignCollection_windows_v${Version}.zip"
}
if (!(Test-Path $WindowsZipPath) -or (Get-Item $WindowsZipPath).Length -lt 1048576) {
$winDir = Join-Path $root "release\windows\EasyDesignCollection"
if (!(Test-Path (Join-Path $winDir "EasyDesignCollection.exe"))) {
throw "找不到 release\windows\EasyDesignCollection\EasyDesignCollection.exe(先执行 flutter build windows --release 并同步到该目录)"
}
Write-Host "打包 Windows 绿色版:$WindowsZipPath"
if (Test-Path $WindowsZipPath) { Remove-Item $WindowsZipPath -Force }
& tar.exe -a -cf $WindowsZipPath -C $winDir .
if ($LASTEXITCODE -ne 0) { throw "打包失败" }
}
if (!(Test-Path $NotesFile)) { throw "找不到更新说明文件:$NotesFile" }
$notes = [System.IO.File]::ReadAllText($NotesFile, [System.Text.Encoding]::UTF8)
# ---- 2) 创建(或复用)Release(正文 = 更新说明) ----
# 幂等:若 v<版本> 已存在(如上次发布上传中断),复用该 Release 并更新说明。
$tmp = Join-Path $env:TEMP "seq_release.json"
$tagFile = Join-Path $env:TEMP "seq_release_tag.json"
curl.exe -s --max-time 300 -o $tagFile "$Server/api/v1/repos/$Owner/$Repo/releases/tags/v$Version" | Out-Null
$rel = $null
try {
$rel = [System.IO.File]::ReadAllText($tagFile, [System.Text.Encoding]::UTF8) | ConvertFrom-Json
} catch {
$rel = $null
}
if ($rel -and $rel.id) {
Write-Host "Release v$Version 已存在(id=$($rel.id)),复用并更新说明..."
$payload = @{ body = $notes } | ConvertTo-Json -Compress
[System.IO.File]::WriteAllText($tmp, $payload, (New-Object System.Text.UTF8Encoding($false)))
curl.exe -s --max-time 300 -o NUL -X PATCH -H "Content-Type: application/json" --data-binary "@$tmp" -u $Auth "$Server/api/v1/repos/$Owner/$Repo/releases/$($rel.id)" | Out-Null
} else {
$payload = @{
tag_name = "v$Version"
name = "v$Version"
body = $notes
draft = $false
prerelease = $false
} | ConvertTo-Json -Compress
[System.IO.File]::WriteAllText($tmp, $payload, (New-Object System.Text.UTF8Encoding($false)))
Write-Host "创建 Release v$Version ..."
$resp = curl.exe -s --max-time 300 -X POST -H "Content-Type: application/json" --data-binary "@$tmp" -u $Auth "$Server/api/v1/repos/$Owner/$Repo/releases"
$rel = $resp | ConvertFrom-Json
if (-not $rel.id) { throw "创建 Release 失败:$resp" }
}
Write-Host "Release id = $($rel.id)"
# ---- 3) 上传附件 ----
# 同名附件先删后传:支持上传中断后重跑(避免重名重复)。
# 注意:大文件上传不设 --max-time(慢链路下需要数分钟)。
function Upload-Asset([string]$path) {
$name = Split-Path $path -Leaf
$curFile = Join-Path $env:TEMP "seq_release_cur.json"
curl.exe -s --max-time 300 -o $curFile "$Server/api/v1/repos/$Owner/$Repo/releases/tags/v$Version" | Out-Null
try {
$cur = [System.IO.File]::ReadAllText($curFile, [System.Text.Encoding]::UTF8) | ConvertFrom-Json
foreach ($a in $cur.assets) {
if ($a.name -eq $name) {
curl.exe -s --max-time 300 -o NUL -X DELETE -u $Auth "$Server/api/v1/repos/$Owner/$Repo/releases/$($rel.id)/assets/$($a.id)" | Out-Null
}
}
} catch {}
Write-Host "上传附件:$name (限速 $UploadLimit)..."
$r = curl.exe -s --limit-rate $UploadLimit -X POST -F "attachment=@$path" -u $Auth "$Server/api/v1/repos/$Owner/$Repo/releases/$($rel.id)/assets?name=$name"
$asset = $r | ConvertFrom-Json
if (-not $asset.name) { throw "上传失败:$r" }
Write-Host " 完成:$($asset.browser_download_url)"
}
Upload-Asset $ApkPath
Upload-Asset $WindowsZipPath
# ---- 4) 清理历史版本附件:只保留最新 1 个版本的安装包 ----
# 客户端更新只使用「最新版本」的附件,更早版本的安装包可安全删除以释放空间;
# Release 记录与更新说明保留,历史版本页面仍可查阅。
# 该步骤失败不影响本次发布(仅打印警告)。
$keepVersions = 1
try {
Write-Host ""
Write-Host "清理历史版本附件(只保留最新 $keepVersions 个版本)..."
$listFile = Join-Path $env:TEMP "seq_releases_list.json"
curl.exe -s --max-time 300 -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 --max-time 300 -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)"