# 用途: 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 } $exeTime = (Get-Item $exe).LastWriteTime Write-Host "[4/4] 启动验证(装机 exe 时间: $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 }