Files
chengnan/scripts/package-windows-release.ps1
luochen570 2a70d6245e
Some checks failed
Build Windows Release / build-windows (push) Has been cancelled
ci: build Windows release package
2026-05-29 22:59:55 +08:00

60 lines
2.0 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.
param(
[ValidateSet("msvc")]
[string]$Toolchain = "msvc",
[string]$BuildDir = "$PSScriptRoot\..\build-windows",
[string]$DistDir = "$PSScriptRoot\..\dist-windows"
)
$ErrorActionPreference = "Stop"
$ProjectRoot = Resolve-Path "$PSScriptRoot\.."
$BuildDir = [System.IO.Path]::GetFullPath($BuildDir)
$DistDir = [System.IO.Path]::GetFullPath($DistDir)
$PackageName = "chengnan-windows-x86_64"
$PackageDir = Join-Path $DistDir $PackageName
$ZipPath = Join-Path $DistDir "$PackageName.zip"
$HashPath = "$ZipPath.sha256"
Write-Host "[package] ProjectRoot: $ProjectRoot"
Write-Host "[package] BuildDir: $BuildDir"
Write-Host "[package] DistDir: $DistDir"
& "$ProjectRoot\docs\windows\build-windows.ps1" -Toolchain $Toolchain -BuildDir $BuildDir -Deploy
$DeployDir = Join-Path $BuildDir "deploy"
$Exe = Join-Path $DeployDir "chengnan.exe"
if (!(Test-Path $Exe)) {
throw "未找到部署后的 Windows 可执行文件:$Exe"
}
if (Test-Path $PackageDir) { Remove-Item -Recurse -Force $PackageDir }
if (Test-Path $ZipPath) { Remove-Item -Force $ZipPath }
if (Test-Path $HashPath) { Remove-Item -Force $HashPath }
New-Item -ItemType Directory -Force -Path $DistDir | Out-Null
Copy-Item -Recurse -Force $DeployDir $PackageDir
$ReadmePath = Join-Path $PackageDir "README.txt"
@"
chengnan Windows x86_64
1.
2. chengnan.exe
- Qt OpenCV DLL
- chengnan.exe DLL Qt plugins
"@ | Set-Content -Encoding UTF8 $ReadmePath
Compress-Archive -Path (Join-Path $PackageDir "*") -DestinationPath $ZipPath -Force
$Hash = Get-FileHash -Algorithm SHA256 $ZipPath
"$($Hash.Hash.ToLower()) $(Split-Path -Leaf $ZipPath)" | Set-Content -Encoding ASCII $HashPath
if (!(Test-Path $ZipPath) -or ((Get-Item $ZipPath).Length -le 0)) {
throw "发布包生成失败:$ZipPath"
}
Write-Host "[package] 发布包:$ZipPath"
Write-Host "[package] 校验文件:$HashPath"