feat: generate update release manifest

This commit is contained in:
2026-06-18 09:45:08 +08:00
parent 8944676ad6
commit cdfd684894
+51 -2
View File
@@ -1,5 +1,10 @@
param( param(
[switch]$SkipBuild [switch]$SkipBuild,
[string]$ManifestBaseUrl = "",
[string]$PublishDir = "",
[string]$ReleaseNotes = "",
[string]$MinSupported = "",
[switch]$Mandatory
) )
$ErrorActionPreference = "Stop" $ErrorActionPreference = "Stop"
@@ -41,10 +46,27 @@ function Assert-InProject {
} }
} }
function Join-Url {
param(
[string]$BaseUrl,
[string]$Name
)
if (-not $BaseUrl) {
return $Name
}
if (-not $BaseUrl.EndsWith("/")) {
$BaseUrl = "$BaseUrl/"
}
return (New-Object -TypeName System.Uri -ArgumentList ([System.Uri]$BaseUrl), $Name).AbsoluteUri
}
$AppName = Read-VersionValue -Path $VersionFile -Name "APP_NAME" $AppName = Read-VersionValue -Path $VersionFile -Name "APP_NAME"
$AppVersion = Read-VersionValue -Path $VersionFile -Name "APP_VERSION" $AppVersion = Read-VersionValue -Path $VersionFile -Name "APP_VERSION"
$ReleaseName = "$AppExeName-$AppVersion" $ReleaseName = "$AppExeName-$AppVersion"
$ReleaseDir = Join-Path $ReleaseRoot $ReleaseName $ReleaseDir = Join-Path $ReleaseRoot $ReleaseName
$ReleaseZip = Join-Path $ReleaseRoot "$ReleaseName.zip"
$ManifestPath = Join-Path $ReleaseRoot "manifest.json"
$PyInstallerOutputDir = Join-Path $DistDir $AppExeName $PyInstallerOutputDir = Join-Path $DistDir $AppExeName
$ExePath = Join-Path $ReleaseDir "$AppExeName.exe" $ExePath = Join-Path $ReleaseDir "$AppExeName.exe"
@@ -69,7 +91,7 @@ if (-not (Test-Path -LiteralPath $DefaultConfigDir)) {
New-Item -ItemType Directory -Force -Path $ReleaseRoot | Out-Null New-Item -ItemType Directory -Force -Path $ReleaseRoot | Out-Null
foreach ($path in @($BuildDir, $PyInstallerOutputDir, $ReleaseDir)) { foreach ($path in @($BuildDir, $PyInstallerOutputDir, $ReleaseDir, $ReleaseZip, $ManifestPath)) {
Assert-InProject -Path $path Assert-InProject -Path $path
if (Test-Path -LiteralPath $path) { if (Test-Path -LiteralPath $path) {
Remove-Item -LiteralPath $path -Recurse -Force Remove-Item -LiteralPath $path -Recurse -Force
@@ -99,6 +121,7 @@ Copy-Item -LiteralPath $PyInstallerOutputDir -Destination $ReleaseDir -Recurse
Copy-Item -LiteralPath $DefaultConfigDir -Destination (Join-Path $ReleaseDir "config") -Recurse Copy-Item -LiteralPath $DefaultConfigDir -Destination (Join-Path $ReleaseDir "config") -Recurse
New-Item -ItemType Directory -Force -Path (Join-Path $ReleaseDir "logs") | Out-Null New-Item -ItemType Directory -Force -Path (Join-Path $ReleaseDir "logs") | Out-Null
New-Item -ItemType Directory -Force -Path (Join-Path $ReleaseDir "output") | Out-Null New-Item -ItemType Directory -Force -Path (Join-Path $ReleaseDir "output") | Out-Null
Set-Content -LiteralPath (Join-Path $ReleaseDir "version.txt") -Value $AppVersion -Encoding ascii -NoNewline
$ReadmePath = Join-Path $ReleaseDir "README.txt" $ReadmePath = Join-Path $ReleaseDir "README.txt"
$Readme = @( $Readme = @(
@@ -120,4 +143,30 @@ if (-not (Test-Path -LiteralPath $ExePath)) {
throw "Executable not found: $ExePath" throw "Executable not found: $ExePath"
} }
Compress-Archive -Path (Join-Path $ReleaseDir "*") -DestinationPath $ReleaseZip -Force
$ReleaseHash = (Get-FileHash -LiteralPath $ReleaseZip -Algorithm SHA256).Hash
$ReleaseSize = (Get-Item -LiteralPath $ReleaseZip).Length
if (-not $MinSupported) {
$MinSupported = $AppVersion
}
$Manifest = [ordered]@{
version = $AppVersion
url = Join-Url -BaseUrl $ManifestBaseUrl -Name (Split-Path -Leaf $ReleaseZip)
sha256 = $ReleaseHash
size = $ReleaseSize
mandatory = [bool]$Mandatory
min_supported = $MinSupported
notes = $ReleaseNotes
}
$Manifest | ConvertTo-Json | Set-Content -LiteralPath $ManifestPath -Encoding UTF8
if ($PublishDir) {
New-Item -ItemType Directory -Force -Path $PublishDir | Out-Null
Copy-Item -LiteralPath $ReleaseZip -Destination $PublishDir -Force
Copy-Item -LiteralPath $ManifestPath -Destination $PublishDir -Force
Write-Host "Published update files to: $PublishDir"
}
Write-Host "Release created: $ReleaseDir" Write-Host "Release created: $ReleaseDir"
Write-Host "Release zip: $ReleaseZip"
Write-Host "Manifest: $ManifestPath"