From cdfd68489454592a2c62c95dc1a4049e1cc7b255 Mon Sep 17 00:00:00 2001 From: ila Date: Thu, 18 Jun 2026 09:45:08 +0800 Subject: [PATCH] feat: generate update release manifest --- scripts/build.ps1 | 53 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/scripts/build.ps1 b/scripts/build.ps1 index ccf3fc3..3e6951f 100644 --- a/scripts/build.ps1 +++ b/scripts/build.ps1 @@ -1,5 +1,10 @@ param( - [switch]$SkipBuild + [switch]$SkipBuild, + [string]$ManifestBaseUrl = "", + [string]$PublishDir = "", + [string]$ReleaseNotes = "", + [string]$MinSupported = "", + [switch]$Mandatory ) $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" $AppVersion = Read-VersionValue -Path $VersionFile -Name "APP_VERSION" $ReleaseName = "$AppExeName-$AppVersion" $ReleaseDir = Join-Path $ReleaseRoot $ReleaseName +$ReleaseZip = Join-Path $ReleaseRoot "$ReleaseName.zip" +$ManifestPath = Join-Path $ReleaseRoot "manifest.json" $PyInstallerOutputDir = Join-Path $DistDir $AppExeName $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 -foreach ($path in @($BuildDir, $PyInstallerOutputDir, $ReleaseDir)) { +foreach ($path in @($BuildDir, $PyInstallerOutputDir, $ReleaseDir, $ReleaseZip, $ManifestPath)) { Assert-InProject -Path $path if (Test-Path -LiteralPath $path) { 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 New-Item -ItemType Directory -Force -Path (Join-Path $ReleaseDir "logs") | 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" $Readme = @( @@ -120,4 +143,30 @@ if (-not (Test-Path -LiteralPath $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 zip: $ReleaseZip" +Write-Host "Manifest: $ManifestPath"