Enhance NSIS installer script with size validation and staging checks
Some checks failed
farmcontrol/farmcontrol-server/pipeline/head There was a failure building this commit
Some checks failed
farmcontrol/farmcontrol-server/pipeline/head There was a failure building this commit
- Added a new parameter for minimum installer size to ensure the generated NSIS installer meets the required threshold. - Implemented a function to calculate the total size of staged application files, validating that the complete app bundle is present before proceeding with the installer creation. - Improved error handling to provide clearer messages if the staged application or installer does not meet size requirements.
This commit is contained in:
parent
d4b22e3734
commit
d572688370
@ -6,7 +6,9 @@ param(
|
||||
[string]$OutputExe,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]$Version
|
||||
[string]$Version,
|
||||
|
||||
[long]$MinInstallerBytes = 10485760
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
@ -31,6 +33,16 @@ function Find-Makensis() {
|
||||
throw "Could not find makensis. Install NSIS 3.x on the Windows build agent."
|
||||
}
|
||||
|
||||
function Get-DirectoryBytes {
|
||||
param([string]$Path)
|
||||
|
||||
$total = 0
|
||||
foreach ($item in Get-ChildItem -LiteralPath $Path -Recurse -File -Force) {
|
||||
$total += $item.Length
|
||||
}
|
||||
return $total
|
||||
}
|
||||
|
||||
$rootDir = Split-Path -Parent $PSScriptRoot
|
||||
$nsiPath = Join-Path $rootDir "packaging/windows/farmcontrol-server.nsi"
|
||||
$installerInclude = Join-Path $rootDir "packaging/windows/installer.nsh"
|
||||
@ -42,6 +54,22 @@ if (Test-Path $workDir) {
|
||||
New-Item -ItemType Directory -Path $workDir | Out-Null
|
||||
|
||||
$appDirPath = (Resolve-Path -LiteralPath $AppDir).Path
|
||||
$stagingAppDir = Join-Path $workDir "app"
|
||||
|
||||
Write-Host "Staging application files for NSIS from $appDirPath"
|
||||
Copy-Item -LiteralPath $appDirPath -Destination $stagingAppDir -Recurse -Force
|
||||
|
||||
$stagedAppBytes = Get-DirectoryBytes $stagingAppDir
|
||||
Write-Host "Staged application size: $([math]::Round($stagedAppBytes / 1MB, 2)) MB"
|
||||
|
||||
if ($stagedAppBytes -lt 5242880) {
|
||||
throw "Staged application is only $([math]::Round($stagedAppBytes / 1KB, 1)) KiB. Expected a full Electrobun app bundle before building the installer."
|
||||
}
|
||||
|
||||
$requiredExe = Join-Path $stagingAppDir "bin\farmcontrol-server.exe"
|
||||
if (-not (Test-Path $requiredExe)) {
|
||||
throw "Staged application is missing bin\farmcontrol-server.exe"
|
||||
}
|
||||
|
||||
Copy-Item -LiteralPath $nsiPath -Destination (Join-Path $workDir "farmcontrol-server.nsi")
|
||||
Copy-Item -LiteralPath $installerInclude -Destination (Join-Path $workDir "installer.nsh")
|
||||
@ -58,11 +86,12 @@ $makensisArgs = @(
|
||||
"/NOCD"
|
||||
"/DOUTFILE=$outputExePath"
|
||||
"/DVERSION=$Version"
|
||||
"/DAPP_SOURCE_DIR=$appDirPath"
|
||||
"/DAPP_SOURCE_DIR=app"
|
||||
)
|
||||
|
||||
if (Test-Path $iconPath) {
|
||||
$makensisArgs += "/DINSTALLER_ICON=$iconPath"
|
||||
$iconPathForNsis = $iconPath.Replace("\", "/")
|
||||
$makensisArgs += "/DINSTALLER_ICON=$iconPathForNsis"
|
||||
}
|
||||
|
||||
$makensisArgs += (Join-Path $workDir "farmcontrol-server.nsi")
|
||||
@ -70,6 +99,9 @@ $makensisArgs += (Join-Path $workDir "farmcontrol-server.nsi")
|
||||
Push-Location $workDir
|
||||
try {
|
||||
& $makensis @makensisArgs
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "makensis failed with exit code $LASTEXITCODE"
|
||||
}
|
||||
} finally {
|
||||
Pop-Location
|
||||
}
|
||||
@ -78,6 +110,13 @@ if (-not (Test-Path $outputExePath)) {
|
||||
throw "NSIS installer was not created at $outputExePath"
|
||||
}
|
||||
|
||||
$installerBytes = (Get-Item -LiteralPath $outputExePath).Length
|
||||
Write-Host "NSIS installer size: $([math]::Round($installerBytes / 1MB, 2)) MB"
|
||||
|
||||
if ($installerBytes -lt $MinInstallerBytes) {
|
||||
throw "NSIS installer is only $([math]::Round($installerBytes / 1KB, 1)) KiB at $outputExePath. The application files were not packaged. Check APP_SOURCE_DIR staging and NSIS logs."
|
||||
}
|
||||
|
||||
if (Test-Path $iconPath) {
|
||||
$embedIconScript = Join-Path $rootDir "scripts/embed-windows-exe-icon.mjs"
|
||||
& bun $embedIconScript $outputExePath --icon $iconPath
|
||||
|
||||
@ -480,6 +480,14 @@ function buildWindowsNsis(appDir, arch) {
|
||||
);
|
||||
}
|
||||
|
||||
const minInstallerBytes = 10 * 1024 * 1024;
|
||||
const installerSize = statSync(exePath).size;
|
||||
if (installerSize < minInstallerBytes) {
|
||||
throw new Error(
|
||||
`Windows installer ${path.basename(exePath)} is only ${(installerSize / 1024).toFixed(1)} KiB; expected at least ${minInstallerBytes / (1024 * 1024)} MiB`,
|
||||
);
|
||||
}
|
||||
|
||||
console.log(`Published ${exePath}`);
|
||||
return exePath;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user