Files
DevFlow/scripts/package-devflow.ps1
T
lxy 070223baa5 文档: 设计文档入库与构建配套收尾
- 云化两设计文档入库(devflow-core 抽取三步收口/云化架构 html)
- 看板销账: T1-T4 逐件附验收
- D4 工具 schema 空 description 清理(渐进披露配套,~10KB/轮)
- 换装脚本验证修复: 安装后装机 exe 版本核对,防 NSIS 静默失败误报成功
- capabilities/锁文件随批
2026-10-26 01:36:55 +08:00

81 lines
3.9 KiB
PowerShell

# 用途: devflow 打包换装双通道脚本(verify=快速编译验证 / full=全量发版换装)
# 生命周期: 长期保留(挂机模式打包组件的雏形,接力棒 M1 落地后由其接管安装段)
# 用法: .\scripts\package-devflow.ps1 -Mode verify # 只验 release 编译,分钟级
# .\scripts\package-devflow.ps1 -Mode full # tauri build -> 杀进程 -> /S 静默装 -> 启动验证
param(
[ValidateSet("verify", "full")]
[string]$Mode = "verify"
)
$ErrorActionPreference = "Continue"
$repo = "E:\wk-lab\devflow"
$exe = "$env:LOCALAPPDATA\devflow\devflow.exe"
$minFreeGB = 10
Set-Location $repo
function Get-FreeGB($path) {
$drive = (Get-Item $path).PSDrive
return [math]::Round($drive.Free / 1GB, 1)
}
$free = Get-FreeGB $repo
if ($free -lt $minFreeGB) {
Write-Host "[预检失败] E 盘剩余 ${free}GB < ${minFreeGB}GB,先清 target\debug\incremental(历史教训 os error 112)"
exit 1
}
Write-Host "[预检] E 盘剩余 ${free}GB,通过"
if ($Mode -eq "verify") {
Write-Host "== 通道1: 快速编译验证(cargo tauri build --no-bundle,与 full 同形态共享增量缓存) =="
cmd /c "cargo tauri build --no-bundle 2>&1"
if ($LASTEXITCODE -ne 0) { Write-Host "[失败] 编译未过"; exit 1 }
Write-Host "[通过] tauri 形态编译成功(未打安装包)"
exit 0
}
Write-Host "== 通道2: 全量发版换装(tauri build -> 静默安装 -> 启动验证) =="
Write-Host "[1/4] tauri build(可能 10 分钟级)..."
# 本地换装不需要 updater 签名产物:未设私钥时用 --config 关掉 createUpdaterArtifacts,
# 否则 tauri build 必因「A public key has been found, but no private key」报错中断(实测多次),
# 安装段被跳过,只能手工补 swap-install。发版(需签名)走 publish-release.ps1。
$tauriArgs = "cargo tauri build"
if (-not $env:TAURI_SIGNING_PRIVATE_KEY) {
Write-Host " [本地换装模式] 未设 TAURI_SIGNING_PRIVATE_KEY -> 关闭 updater 产物(发版走 publish-release.ps1)"
$override = "$repo\temp\local-no-updater.json"
@{ bundle = @{ createUpdaterArtifacts = $false } } | ConvertTo-Json | Set-Content $override -Encoding utf8
$tauriArgs = "cargo tauri build --config `"$override`""
}
cmd /c "$tauriArgs 2>&1"
if ($LASTEXITCODE -ne 0) { Write-Host "[失败] tauri build"; exit 1 }
$bundle = Get-ChildItem "$repo\target\release\bundle\nsis\*.exe" | Sort-Object LastWriteTime -Descending | Select-Object -First 1
if (-not $bundle) { Write-Host "[失败] 未找到安装包产物"; exit 1 }
Write-Host "[2/4] 安装包: $($bundle.Name) ($([math]::Round($bundle.Length/1MB,1))MB, $($bundle.LastWriteTime))"
Write-Host "[3/4] 杀旧进程 -> 静默安装..."
Get-Process devflow -ErrorAction SilentlyContinue | Stop-Process -Force
Start-Sleep -Seconds 2
Start-Process $bundle.FullName -ArgumentList "/S" -Wait
if (-not (Test-Path $exe)) { Write-Host "[失败] 安装后未找到 $exe"; exit 1 }
# 版本核对(2026-10-25 实证修复):NSIS 静默安装可能因文件锁静默失败,旧进程复活锁文件时
# 曾出现「报换装成功但装机 exe 仍是旧版」。装机版本必须与本次构建一致才算换装成功。
$wantVer = (Get-Content "$repo\src-tauri\tauri.conf.json" | ConvertFrom-Json).version
$gotVer = (Get-Item $exe).VersionInfo.ProductVersion
if ($gotVer -ne $wantVer) {
Write-Host "[失败] 静默安装未生效:装机 exe 版本 $gotVer != 构建 $wantVer(疑似安装器被文件锁/旧进程拦截),请手工运行安装包后重试"
exit 1
}
$exeTime = (Get-Item $exe).LastWriteTime
Write-Host "[4/4] 启动验证(装机 exe $gotVer,时间: $exeTime)..."
Start-Process $exe
Start-Sleep -Seconds 6
$proc = Get-Process devflow -ErrorAction SilentlyContinue
if ($proc) {
Write-Host "[换装成功] PID $($proc.Id) 存活,装机时间 $exeTime"
} else {
Write-Host "[警告] 启动后 6 秒未见进程,请人工确认(可能仍在初始化)"
exit 1
}