57 lines
3.7 KiB
PowerShell
57 lines
3.7 KiB
PowerShell
param(
|
||
[string]$Target = 'Administrator@192.168.0.184',
|
||
[string]$InstallRoot = 'C:\sophelper',
|
||
[string]$ReleaseId = '',
|
||
[switch]$SkipPublish,
|
||
[switch]$SkipGpuCheck
|
||
)
|
||
# 通过 SSH/SCP 把当前 win-x64 发布包部署到远端 Windows 工位机。
|
||
# 约定同 Deploy-Linux.ps1:发布复用 artifacts/avalonia/<RID>/,每个版本放入 <InstallRoot>\releases\<ReleaseId>,
|
||
# configs/models/workspace 保留在 <InstallRoot> 下,通过目录联接跨版本复用。
|
||
$ErrorActionPreference = 'Stop'
|
||
if ($Target -notmatch '^[a-zA-Z0-9_.-]+@[a-zA-Z0-9_.-]+$') { throw 'Target must be user@host' }
|
||
if ($InstallRoot -notmatch '^[A-Za-z]:\\[A-Za-z0-9_.\\-]+$') { throw 'InstallRoot must be an absolute Windows path without spaces' }
|
||
$repo = Split-Path $PSScriptRoot -Parent
|
||
$output = Join-Path $repo 'artifacts\avalonia\win-x64'
|
||
$remoteRootFwd = $InstallRoot.Replace('\', '/')
|
||
$sha = (& git -C $repo rev-parse --short HEAD | Out-String).Trim()
|
||
$dirty = @(& git -C $repo status --porcelain).Count -gt 0
|
||
if (!$ReleaseId) {
|
||
$ReleaseId = 'avalonia-' + (Get-Date -Format 'yyyyMMdd-HHmmss') + '-' + $sha
|
||
if ($dirty) { $ReleaseId += '-dirty' }
|
||
}
|
||
Write-Host "Release: $ReleaseId (commit $sha$(if($dirty){' + 未提交修改'}))"
|
||
|
||
if (!$SkipPublish) {
|
||
& dotnet publish (Join-Path $repo 'src\SopHelper.Avalonia') -c Release -r win-x64 --self-contained true -p:PublishSingleFile=false -p:BundlePythonRuntime=false -p:NativePlatform=Windows -o $output --nologo
|
||
if ($LASTEXITCODE) { throw 'Publish failed' }
|
||
}
|
||
|
||
# 本机先自检,避免把跑不起来的包传到工位机。
|
||
$exe = Join-Path $output 'SopHelper.Avalonia.exe'
|
||
if (!(Test-Path -LiteralPath $exe)) { throw "Missing published executable: $exe" }
|
||
$logDir = Join-Path (Split-Path $repo -Parent) 'scratch\test-results'
|
||
New-Item -ItemType Directory -Path $logDir -Force | Out-Null
|
||
$runtimeCheck = Start-Process -FilePath $exe -ArgumentList '--check-runtime' -NoNewWindow -PassThru -Wait `
|
||
-RedirectStandardOutput (Join-Path $logDir 'deploy-windows-local-check-runtime.stdout.log') `
|
||
-RedirectStandardError (Join-Path $logDir 'deploy-windows-local-check-runtime.stderr.log')
|
||
if ($runtimeCheck.ExitCode) { throw '本机 --check-runtime 自检失败,详见 scratch/test-results/deploy-windows-local-check-runtime.*.log' }
|
||
Write-Host '本机 --check-runtime 通过。'
|
||
|
||
# 打包:不含 python(BundlePythonRuntime=false 时发布目录里的 python 为历史遗留)。
|
||
$packageItems = Get-ChildItem -LiteralPath $output -Force | Where-Object { $_.Name -ne 'python' } | Select-Object -ExpandProperty Name
|
||
if (!$packageItems) { throw "Nothing to package in $output" }
|
||
$archive = Join-Path $repo ('artifacts\' + $ReleaseId + '.tar.gz')
|
||
if (Test-Path -LiteralPath $archive) { Remove-Item -LiteralPath $archive -Force }
|
||
& tar -czf $archive -C $output $packageItems
|
||
if ($LASTEXITCODE) { throw 'Packaging failed' }
|
||
Write-Host ('打包完成: ' + $archive + ' (' + [math]::Round((Get-Item $archive).Length/1MB,1) + ' MB)')
|
||
|
||
& ssh -o BatchMode=yes $Target "New-Item -Force -ItemType Directory $InstallRoot, $InstallRoot\releases | Out-Null"
|
||
if ($LASTEXITCODE) { throw 'SSH failed' }
|
||
& scp -o BatchMode=yes $archive (Join-Path $PSScriptRoot 'windows\install-release.ps1') "${Target}:$remoteRootFwd/"
|
||
if ($LASTEXITCODE) { throw 'Transfer failed' }
|
||
& ssh -o BatchMode=yes $Target "powershell -NoProfile -ExecutionPolicy Bypass -File $InstallRoot\install-release.ps1 -ReleaseId $ReleaseId -InstallRoot $InstallRoot -SkipGpuCheck $([int][bool]$SkipGpuCheck)"
|
||
if ($LASTEXITCODE) { throw "安装或自检失败,详见 $InstallRoot\releases\$ReleaseId\workspace\logs" }
|
||
Write-Host "已部署 $ReleaseId 到 $Target;开始菜单和桌面均有 SopHelper 快捷方式。"
|