Icon generation finds ImageMagick past the runner's stale PATH #7
+42
-12
@@ -25,29 +25,59 @@ if (-not $Force -and (Test-Path $output) -and
|
||||
return
|
||||
}
|
||||
|
||||
$magick = Get-Command magick -ErrorAction SilentlyContinue
|
||||
if (-not $magick) {
|
||||
# winget only exists in interactive user contexts — CI service accounts
|
||||
# (LocalSystem) do not have it. The icon is cosmetic (the MSI compiles
|
||||
# without it via ?ifdef AppIconPath), so degrade to a warning.
|
||||
# Service processes (the CI runner) capture PATH at service start, so a
|
||||
# later ImageMagick install is invisible to Get-Command — probe the usual
|
||||
# install locations directly before giving up.
|
||||
function Find-Magick {
|
||||
$command = Get-Command magick -ErrorAction SilentlyContinue
|
||||
if ($command) { return $command.Source }
|
||||
|
||||
$patterns = @(
|
||||
"$env:ProgramFiles\ImageMagick*\magick.exe"
|
||||
"${env:ProgramFiles(x86)}\ImageMagick*\magick.exe"
|
||||
"$env:LOCALAPPDATA\Programs\ImageMagick*\magick.exe"
|
||||
"$env:LOCALAPPDATA\Microsoft\WinGet\Links\magick.exe"
|
||||
)
|
||||
foreach ($pattern in $patterns) {
|
||||
$found = Get-Item $pattern -ErrorAction SilentlyContinue |
|
||||
Sort-Object FullName -Descending | Select-Object -First 1
|
||||
if ($found) { return $found.FullName }
|
||||
}
|
||||
|
||||
return $null
|
||||
}
|
||||
|
||||
$magickPath = Find-Magick
|
||||
if (-not $magickPath) {
|
||||
# winget lives on the user PATH (WindowsApps), which services also miss;
|
||||
# probe its well-known location too. The icon is cosmetic (the MSI
|
||||
# compiles without it via ?ifdef AppIconPath), so degrade to a warning.
|
||||
$winget = Get-Command winget -ErrorAction SilentlyContinue
|
||||
if (-not $winget) {
|
||||
$wingetPath = if ($winget) { $winget.Source }
|
||||
elseif (Test-Path "$env:LOCALAPPDATA\Microsoft\WindowsApps\winget.exe") {
|
||||
"$env:LOCALAPPDATA\Microsoft\WindowsApps\winget.exe"
|
||||
}
|
||||
if (-not $wingetPath) {
|
||||
Write-Warning 'ImageMagick and winget are both unavailable — skipping icon generation (MSI builds without an icon).'
|
||||
return
|
||||
}
|
||||
|
||||
Write-Host 'ImageMagick not found — installing via winget...'
|
||||
winget install ImageMagick.ImageMagick --silent --accept-package-agreements --accept-source-agreements --disable-interactivity
|
||||
if ($LASTEXITCODE -ne 0) { throw "winget install of ImageMagick failed ($LASTEXITCODE)." }
|
||||
|
||||
# Refresh PATH for this session.
|
||||
& $wingetPath install ImageMagick.ImageMagick --silent --accept-package-agreements --accept-source-agreements --disable-interactivity
|
||||
# The exit code is intentionally not fatal: "already installed / no
|
||||
# upgrade available" returns non-zero. What matters is whether
|
||||
# magick.exe exists afterwards.
|
||||
$env:Path = [Environment]::GetEnvironmentVariable('Path', 'Machine') + ';' +
|
||||
[Environment]::GetEnvironmentVariable('Path', 'User')
|
||||
$magick = Get-Command magick -ErrorAction Stop
|
||||
$magickPath = Find-Magick
|
||||
if (-not $magickPath) {
|
||||
Write-Warning 'winget ran but magick.exe was not found — skipping icon generation (MSI builds without an icon).'
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
New-Item -ItemType Directory -Force $outputDir | Out-Null
|
||||
& $magick.Source $source -define icon:auto-resize=256,128,64,48,32,16 $output
|
||||
& $magickPath $source -define icon:auto-resize=256,128,64,48,32,16 $output
|
||||
if ($LASTEXITCODE -ne 0) { throw "ImageMagick icon generation failed ($LASTEXITCODE)." }
|
||||
|
||||
Write-Host "Generated $output"
|
||||
|
||||
Reference in New Issue
Block a user