Files
ms-private/Build-AmePlaybook.ps1
T
0x000 cdfa0ecda8
Windows tests / test-and-build (push) Canceled after 0s
Fix GUI apply status update
2026-09-23 19:25:04 -04:00

20 lines
2.5 KiB
PowerShell

#Requires -Version 5.1
[CmdletBinding()]param([string]$OutputDirectory,[ValidatePattern('^\d+\.\d+\.\d+$')][string]$Version='0.0.3')
Set-StrictMode -Version Latest;$ErrorActionPreference='Stop'
if(-not$OutputDirectory){$OutputDirectory=Join-Path $PSScriptRoot 'dist'};$out=[IO.Path]::GetFullPath($OutputDirectory);[IO.Directory]::CreateDirectory($out)|Out-Null
$seven=@((Get-Command 7z.exe -ErrorAction SilentlyContinue),(Get-Command (Join-Path $env:ProgramFiles '7-Zip\7z.exe') -ErrorAction SilentlyContinue))|Where-Object{$_}|Select-Object -First 1
if(-not$seven){throw '7-Zip is required to create an AME .apbx archive.'}
$stage=Join-Path ([IO.Path]::GetTempPath()) ('ms-private-ame-'+[guid]::NewGuid().ToString('N'));[IO.Directory]::CreateDirectory($stage)|Out-Null
try{
Copy-Item -LiteralPath (Join-Path $PSScriptRoot 'ame\src\playbook.conf') -Destination $stage
$playbookPath=Join-Path $stage 'playbook.conf';$playbook=[xml][IO.File]::ReadAllText($playbookPath);$playbook.Playbook.Version=$Version;$settings=[Xml.XmlWriterSettings]::new();$settings.Encoding=[Text.UTF8Encoding]::new($false);$settings.Indent=$true;$writer=[Xml.XmlWriter]::Create($playbookPath,$settings);try{$playbook.Save($writer)}finally{$writer.Dispose()}
Copy-Item -LiteralPath (Join-Path $PSScriptRoot 'ame\src\Configuration') -Destination $stage -Recurse
Copy-Item -LiteralPath (Join-Path $PSScriptRoot 'ame\src\Executables') -Destination $stage -Recurse
$payload=Join-Path $stage 'Executables\ms-private'
foreach($file in @(Get-ChildItem -LiteralPath $PSScriptRoot -File|Where-Object{$_.Extension-in@('.ps1','.md')})) {Copy-Item -LiteralPath $file.FullName -Destination $payload}
foreach($folder in @('src','config','docs')){Copy-Item -LiteralPath (Join-Path $PSScriptRoot $folder) -Destination $payload -Recurse}
$target=Join-Path $out ("ms-private-$Version.apbx");if(Test-Path -LiteralPath $target){throw 'AME archive already exists. Use an empty output directory.'}
Push-Location $stage;try{& $seven.Source a $target playbook.conf Executables Configuration '-pmalte'|Out-Host;if($LASTEXITCODE-ne 0){throw "7-Zip failed with exit code $LASTEXITCODE."}}finally{Pop-Location}
$hash=(Get-FileHash -LiteralPath $target -Algorithm SHA256).Hash.ToLowerInvariant();[IO.File]::WriteAllText((Join-Path $out ("ms-private-$Version.apbx.sha256")),($hash+' '+[IO.Path]::GetFileName($target)+[Environment]::NewLine),[Text.UTF8Encoding]::new($false));Write-Output "Created $target. SHA256: $hash"
}finally{if(Test-Path -LiteralPath $stage){Remove-Item -LiteralPath $stage -Recurse -Force}}