aisop/tools/Publish-Avalonia.ps1

28 lines
1.8 KiB
PowerShell

param(
[string]$OutputRoot = '',
[string[]]$RuntimeIdentifiers = @('win-x64','linux-x64')
)
$ErrorActionPreference='Stop'
$repo=Split-Path $PSScriptRoot -Parent
if (!$OutputRoot) { $OutputRoot=Join-Path $repo 'artifacts/avalonia' }
$project=Join-Path $repo 'src/SopHelper.Avalonia/SopHelper.Avalonia.csproj'
$sources=@('src/SopHelper.Avalonia','src/SopHelper.CrossPlatform.Engine') | ForEach-Object {
Get-ChildItem (Join-Path $repo $_) -Recurse -File | Where-Object {
$_.FullName -notmatch '[\\/](bin|obj)[\\/]' -and $_.Extension -in '.cs','.axaml','.csproj'
}
} | Sort-Object FullName
$manifest=@($sources | ForEach-Object { [ordered]@{path=[IO.Path]::GetRelativePath($repo,$_.FullName).Replace('\','/');sha256=(Get-FileHash $_.FullName -Algorithm SHA256).Hash} })
$sourceJson=ConvertTo-Json -InputObject $manifest -Depth 5
foreach ($rid in $RuntimeIdentifiers) {
if ($rid -notin @('win-x64','linux-x64')) { throw "Unsupported runtime: $rid" }
$destination=Join-Path $OutputRoot $rid
$nativePlatform=if($rid -eq 'win-x64'){'Windows'}else{'Linux'}
& dotnet publish $project -c Release -r $rid --self-contained true -p:PublishSingleFile=false "-p:NativePlatform=$nativePlatform" -o $destination --nologo
if ($LASTEXITCODE) { throw "Publish failed: $rid" }
[IO.File]::WriteAllText((Join-Path $destination 'source-manifest.json'),$sourceJson,[Text.UTF8Encoding]::new($false))
}
$hashes=@($RuntimeIdentifiers | ForEach-Object { (Get-FileHash (Join-Path $OutputRoot "$_/source-manifest.json")).Hash } | Select-Object -Unique)
if ($hashes.Count -ne 1) { throw 'Published source manifests differ.' }
# RID-specific intermediate/PDB paths can change PE bytes even with identical IL.
Write-Host "PASS: Published runtimes share source manifest: $($hashes[0])"