Repository navigation
Expand file tree
/
Copy pathBuild-MSIX.ps1
More file actions
838 lines (775 loc) · 28.3 KB
/
Copy pathBuild-MSIX.ps1
File metadata and controls
838 lines (775 loc) · 28.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[string]$PayloadDirectory,
[string]$NodeArchivePath,
[Parameter(Mandatory)]
[ValidateSet('x64', 'arm64')]
[string]$Architecture,
[Parameter(Mandatory)]
[string]$PackageVersion,
[Parameter(Mandatory)]
[ValidatePattern('^[0-9a-fA-F]{40}$')]
[string]$SourceCommit,
[ValidateSet('Store', 'Sideload')]
[string]$IdentityChannel = 'Store',
[switch]$SourceTreeDirty,
[Parameter(Mandatory)]
[string]$OutputDirectory
)
$ErrorActionPreference = 'Stop'
$repositoryRoot = Split-Path $PSScriptRoot -Parent
$projectPath = Join-Path `
$repositoryRoot `
'src\OpenClaw.Launcher\OpenClaw.Launcher.csproj'
$policy = Get-Content `
-LiteralPath (Join-Path $repositoryRoot 'release-policy.json') `
-Raw |
ConvertFrom-Json
$manifestPath = Join-Path `
$repositoryRoot `
'src\OpenClaw.Launcher\Package.appxmanifest'
[xml]$packageManifest = Get-Content -LiteralPath $manifestPath -Raw
$manifestIdentity = $packageManifest.Package.Identity
if (
[string]::IsNullOrWhiteSpace([string]$policy.packageFamilyName) -or
[string]$manifestIdentity.Name -cne [string]$policy.packageIdentityName -or
[string]$manifestIdentity.Publisher -cne [string]$policy.publisher
) {
throw 'The package manifest identity does not match release policy.'
}
function Get-PackageIdentity {
param(
[Parameter(Mandatory)]
[ValidateSet('Store', 'Sideload')]
[string]$Channel
)
$identity = if ($Channel -eq 'Sideload') {
$policy.sideloadPackageIdentity
}
else {
[pscustomobject]@{
name = $policy.packageIdentityName
familyName = $policy.packageFamilyName
publisher = $policy.publisher
}
}
if (
[string]::IsNullOrWhiteSpace([string]$identity.name) -or
[string]::IsNullOrWhiteSpace([string]$identity.familyName) -or
[string]::IsNullOrWhiteSpace([string]$identity.publisher)
) {
throw "The $Channel package identity is incomplete in release policy."
}
$identity
}
$selectedIdentity = Get-PackageIdentity -Channel $IdentityChannel
$packageIdentityName = [string]$selectedIdentity.name
$packageFamilyName = [string]$selectedIdentity.familyName
$publisher = [string]$selectedIdentity.publisher
$msbuildPublisher = & (
Join-Path $PSScriptRoot 'ConvertTo-MSBuildPropertyValue.ps1'
) -Value $publisher
function Invoke-CheckedCommand {
param(
[Parameter(Mandatory)]
[scriptblock]$Command,
[Parameter(Mandatory)]
[string]$FailureMessage
)
& $Command
if ($LASTEXITCODE -ne 0) {
throw "$FailureMessage Exit code: $LASTEXITCODE."
}
}
function Remove-DirectoryIfPresent {
param(
[Parameter(Mandatory)]
[string]$Path
)
if ([IO.Directory]::Exists($Path)) {
[IO.Directory]::Delete($Path, $true)
}
}
function Get-PortableExecutableSubsystem {
param(
[Parameter(Mandatory)]
[string]$Path
)
$bytes = [IO.File]::ReadAllBytes($Path)
if ($bytes.Length -lt 0x40 -or $bytes[0] -ne 0x4D -or $bytes[1] -ne 0x5A) {
throw "'$Path' is not a Windows executable image."
}
# The subsystem is at offset 68 of the optional header in both PE32 and
# PE32+, and the optional header follows the 4-byte signature and the
# 20-byte file header.
$peOffset = [BitConverter]::ToInt32($bytes, 0x3C)
if (
$peOffset -lt 0x40 -or
$peOffset + 24 + 70 -gt $bytes.Length -or
[BitConverter]::ToUInt32($bytes, $peOffset) -ne 0x00004550
) {
throw "'$Path' is not a Windows executable image."
}
return [BitConverter]::ToUInt16($bytes, $peOffset + 24 + 68)
}
function Test-PackageVersion {
$segments = @($PackageVersion.Split('.'))
if ($segments.Count -ne 4) {
throw 'PackageVersion must contain four numeric components.'
}
foreach ($segment in $segments) {
[uint16]$value = 0
if (-not [uint16]::TryParse($segment, [ref]$value)) {
throw "Invalid MSIX package version component: $segment"
}
if ($value -gt 65534) {
throw (
"PackageVersion component $segment exceeds the .NET " +
'assembly version maximum of 65534.'
)
}
}
}
function Assert-ApplicationDoesNotBundleNode {
param(
[Parameter(Mandatory)]
[string]$Path
)
$bundledNodeEntries = @(
Get-ChildItem -LiteralPath $Path -File -Force -Recurse |
Where-Object {
$_.Name -ieq 'node.exe' -or
$_.Name -match '^node-v\d'
}
)
if ($bundledNodeEntries.Count -ne 0) {
throw (
'The OpenClaw payload must not bundle Node.js: ' +
(
$bundledNodeEntries |
ForEach-Object {
[IO.Path]::GetRelativePath($Path, $_.FullName)
} |
Sort-Object
) -join ', '
)
}
}
function Assert-ApplicationHasNoReparsePoints {
# npm installs can produce symlinks/junctions (e.g. workspace links).
# Reject them: the per-file inventory hashes file content by path, and a
# link could point outside the expanded tree or resolve differently than
# what was hashed at build time.
param(
[Parameter(Mandatory)]
[string]$Path
)
$reparsePoint = Get-ChildItem `
-LiteralPath $Path `
-Force `
-Recurse |
Where-Object {
($_.Attributes -band [IO.FileAttributes]::ReparsePoint) -ne 0
} |
Select-Object -First 1
if ($null -ne $reparsePoint) {
throw (
'The OpenClaw payload must not contain links or reparse points: ' +
[IO.Path]::GetRelativePath($Path, $reparsePoint.FullName)
)
}
}
function Assert-NodeArchive {
param(
[Parameter(Mandatory)]
[string]$Path,
[Parameter(Mandatory)]
[string]$ExpectedRoot
)
Add-Type -AssemblyName System.IO.Compression.FileSystem
$archive = [IO.Compression.ZipFile]::OpenRead($Path)
try {
$nodeEntries = @(
$archive.Entries |
Where-Object {
$_.FullName -ieq "$ExpectedRoot/node.exe"
}
)
if ($nodeEntries.Count -ne 1) {
throw (
"The Node.js archive must contain exactly one " +
"'$ExpectedRoot/node.exe' entry."
)
}
}
finally {
$archive.Dispose()
}
}
function Add-VswhereToPath {
if (Get-Command vswhere.exe -CommandType Application -ErrorAction SilentlyContinue) {
return
}
$vswhereDirectory = Join-Path `
${env:ProgramFiles(x86)} `
'Microsoft Visual Studio\Installer'
$vswherePath = Join-Path $vswhereDirectory 'vswhere.exe'
if (-not (Test-Path -LiteralPath $vswherePath -PathType Leaf)) {
throw (
'vswhere.exe was not found. Install Visual Studio Build Tools with ' +
'the Desktop development with C++ workload.'
)
}
$env:Path = "$vswhereDirectory;$env:Path"
}
Test-PackageVersion
$PayloadDirectory = (Resolve-Path -LiteralPath $PayloadDirectory).Path
$payloadApplication = Join-Path $PayloadDirectory 'app'
$payloadMetadata = Join-Path $PayloadDirectory 'payload-metadata.json'
if (-not (Test-Path -LiteralPath $payloadApplication -PathType Container)) {
throw "Required MSIX input was not found: $payloadApplication"
}
if (-not (Test-Path -LiteralPath $payloadMetadata -PathType Leaf)) {
throw "Required MSIX input was not found: $payloadMetadata"
}
$payloadInfo = Get-Content -LiteralPath $payloadMetadata -Raw | ConvertFrom-Json
if (
$payloadInfo.repository -ne 'https://github.com/openclaw/openclaw' -or
$payloadInfo.architecture -ne $Architecture -or
$payloadInfo.layout -ne 'expanded-directory' -or
$payloadInfo.nodeVersion -isnot [string] -or
$payloadInfo.nodeVersion -notmatch '^v?\d+\.\d+\.\d+$' -or
[string]::IsNullOrWhiteSpace([string]$payloadInfo.packageVersion) -or
$payloadInfo.requestedRef -isnot [string] -or
[string]::IsNullOrWhiteSpace($payloadInfo.requestedRef) -or
$payloadInfo.resolvedCommit -notmatch '^[0-9a-fA-F]{40}$'
) {
throw 'Payload metadata is not valid for this MSIX package.'
}
$nodeVersion = $payloadInfo.nodeVersion.TrimStart('v')
$expectedNodeArchiveName = "node-v$nodeVersion-win-$Architecture.zip"
if ($NodeArchivePath) {
$NodeArchivePath = (Resolve-Path -LiteralPath $NodeArchivePath).Path
if ([IO.Path]::GetFileName($NodeArchivePath) -cne $expectedNodeArchiveName) {
throw (
'NodeArchivePath must match the payload build runtime: ' +
$expectedNodeArchiveName
)
}
}
if (-not (Test-Path `
-LiteralPath (Join-Path $payloadApplication 'openclaw.mjs') `
-PathType Leaf)) {
throw 'Expanded payload does not contain openclaw.mjs.'
}
Assert-ApplicationHasNoReparsePoints -Path $payloadApplication
Assert-ApplicationDoesNotBundleNode -Path $payloadApplication
$contentRoot = Join-Path $repositoryRoot 'content'
$openClawContent = Join-Path $contentRoot 'openclaw'
$applicationTarget = Join-Path $openClawContent 'app'
$runtimeTargetDirectory = Join-Path $openClawContent 'runtime'
$nodeArchiveTarget = Join-Path `
$runtimeTargetDirectory `
$expectedNodeArchiveName
New-Item -Path $openClawContent -ItemType Directory -Force | Out-Null
# The payload directory belongs to the caller and must stay unmodified, so it
# is always copied; the PDB removal below changes only that copy.
& (Join-Path $PSScriptRoot 'Copy-PayloadTree.ps1') `
-Source $payloadApplication `
-Destination $applicationTarget
New-Item -Path $runtimeTargetDirectory -ItemType Directory -Force | Out-Null
if (-not $NodeArchivePath) {
$archiveUri = "https://nodejs.org/dist/v$nodeVersion/$expectedNodeArchiveName"
Write-Host "Downloading bundled Node.js runtime from $archiveUri."
Invoke-WebRequest -Uri $archiveUri -OutFile $nodeArchiveTarget
}
elseif ($NodeArchivePath -ne $nodeArchiveTarget) {
Copy-Item -LiteralPath $NodeArchivePath -Destination $nodeArchiveTarget -Force
}
Assert-NodeArchive `
-Path $nodeArchiveTarget `
-ExpectedRoot ([IO.Path]::GetFileNameWithoutExtension($expectedNodeArchiveName))
$nodeArchiveHash = (
Get-FileHash -LiteralPath $nodeArchiveTarget -Algorithm SHA256
).Hash.ToLowerInvariant()
$payloadSymbols = @(
# MSBuild's own AppxPackagePayload step strips .pdb files when it later
# packages content\openclaw\app; remove them here too so the inventory
# built below matches what actually ends up in the MSIX.
Get-ChildItem `
-LiteralPath $applicationTarget `
-Filter '*.pdb' `
-File `
-Force `
-Recurse
)
foreach ($payloadSymbol in $payloadSymbols) {
Remove-Item -LiteralPath $payloadSymbol.FullName -Force
}
if ($payloadSymbols.Count -ne 0) {
Write-Host (
"Excluded $($payloadSymbols.Count) payload PDB files from the MSIX."
)
}
$payloadFiles = @(
Get-ChildItem -LiteralPath $applicationTarget -File -Force -Recurse |
ForEach-Object {
[ordered]@{
path = (
[IO.Path]::GetRelativePath(
$applicationTarget,
$_.FullName
)
).Replace('\', '/')
length = $_.Length
sha256 = (
Get-FileHash -LiteralPath $_.FullName -Algorithm SHA256
).Hash.ToLowerInvariant()
}
} |
Sort-Object path
)
if ($payloadFiles.Count -eq 0) {
throw 'Expanded payload contains no files.'
}
$payloadInventoryPath = Join-Path $openClawContent 'payload-files.json'
[ordered]@{
files = $payloadFiles
} |
# Keep the nested inventory file records intact.
ConvertTo-Json -Depth 4 |
Set-Content -LiteralPath $payloadInventoryPath -Encoding utf8
# The startup list is a best-effort setup prewarm hint; every path must still
# be a member of the verified payload inventory.
$startupFiles = @(
& (Join-Path $PSScriptRoot 'Get-PayloadStartupFiles.ps1') `
-ApplicationDirectory $applicationTarget
)
$payloadPaths = [Collections.Generic.HashSet[string]]::new(
[string[]]@($payloadFiles | ForEach-Object { $_.path }),
[StringComparer]::Ordinal
)
foreach ($startupFile in $startupFiles) {
if (-not $payloadPaths.Contains($startupFile)) {
throw "The startup file list names a path outside the payload inventory: $startupFile"
}
}
$startupFilesPath = Join-Path $openClawContent 'startup-files.json'
[ordered]@{
schemaVersion = 1
files = $startupFiles
} |
ConvertTo-Json -Depth 2 |
Set-Content -LiteralPath $startupFilesPath -Encoding utf8
Write-Host "Listed $($startupFiles.Count) startup payload files for setup prewarm."
$mxcRuntimeDirectory = Join-Path $repositoryRoot "content\mxc\$Architecture"
$mxcRuntime = & (Join-Path $PSScriptRoot 'Get-MxcSdkMetadata.ps1') `
-Architecture $Architecture `
-IncludePackagingContent `
-OutputDirectory $mxcRuntimeDirectory
$mxcMetadataFiles = @($mxcRuntime.Files)
$mxcProvenance = $mxcRuntime.Provenance
$temporaryRoot = if ($env:RUNNER_TEMP) {
$env:RUNNER_TEMP
}
else {
[IO.Path]::GetTempPath()
}
$workRoot = Join-Path `
$temporaryRoot `
"openclaw-msix-$Architecture-$([guid]::NewGuid().ToString('N'))"
$msixBuildDirectory = Join-Path $workRoot 'appx'
$directoriesToCreate = @($msixBuildDirectory, $OutputDirectory)
New-Item `
-Path $directoriesToCreate `
-ItemType Directory `
-Force |
Out-Null
try {
Add-VswhereToPath
$sessionHostProject = Join-Path `
$repositoryRoot `
'src\OpenClaw.SessionHost\OpenClaw.SessionHost.csproj'
$sessionHostOutput = Join-Path `
$repositoryRoot `
"content\session-host\$Architecture"
Remove-DirectoryIfPresent -Path $sessionHostOutput
New-Item -Path $sessionHostOutput -ItemType Directory -Force | Out-Null
Write-Host "Publishing the NativeAOT win-$Architecture session host."
Invoke-CheckedCommand `
-FailureMessage 'NativeAOT session host publish failed.' `
-Command {
& dotnet publish $sessionHostProject `
--configuration Release `
--runtime "win-$Architecture" `
--self-contained `
--no-restore `
"-p:Platform=$Architecture" `
-p:PublishAot=true `
--output $sessionHostOutput `
--nologo
}
$sessionHostFiles = @(
Get-ChildItem -LiteralPath $sessionHostOutput -File -Force -Recurse |
Where-Object Extension -notin '.pdb', '.xml' |
ForEach-Object {
[ordered]@{
path = (
[IO.Path]::GetRelativePath(
$sessionHostOutput,
$_.FullName
)
).Replace('\', '/')
length = $_.Length
sha256 = (
Get-FileHash -LiteralPath $_.FullName -Algorithm SHA256
).Hash.ToLowerInvariant()
}
} |
Sort-Object path
)
if (-not ($sessionHostFiles.path -contains 'openclaw-session-host.exe')) {
throw "The published $Architecture session host is incomplete."
}
$recoveryHelperProject = Join-Path `
$repositoryRoot `
'src\OpenClaw.GatewayRecovery\OpenClaw.GatewayRecovery.csproj'
$recoveryHelperOutput = Join-Path `
$repositoryRoot `
"content\gateway-recovery\$Architecture"
Remove-DirectoryIfPresent -Path $recoveryHelperOutput
New-Item -Path $recoveryHelperOutput -ItemType Directory -Force | Out-Null
Write-Host "Publishing the NativeAOT win-$Architecture sign-in helper."
Invoke-CheckedCommand `
-FailureMessage 'NativeAOT sign-in helper publish failed.' `
-Command {
& dotnet publish $recoveryHelperProject `
--configuration Release `
--runtime "win-$Architecture" `
--self-contained `
--no-restore `
"-p:Platform=$Architecture" `
-p:PublishAot=true `
--output $recoveryHelperOutput `
--nologo
}
$recoveryHelperFiles = @(
Get-ChildItem -LiteralPath $recoveryHelperOutput -File -Force -Recurse |
Where-Object Extension -notin '.pdb', '.xml' |
ForEach-Object {
[ordered]@{
path = (
[IO.Path]::GetRelativePath(
$recoveryHelperOutput,
$_.FullName
)
).Replace('\', '/')
length = $_.Length
sha256 = (
Get-FileHash -LiteralPath $_.FullName -Algorithm SHA256
).Hash.ToLowerInvariant()
}
}
)
if (
$recoveryHelperFiles.Count -ne 1 -or
$recoveryHelperFiles[0].path -cne 'openclaw-gateway-recovery.exe'
) {
throw "The published $Architecture sign-in helper must be exactly openclaw-gateway-recovery.exe."
}
# A console-subsystem helper would open a terminal window at every sign-in.
$recoveryHelperSubsystem = Get-PortableExecutableSubsystem `
-Path (Join-Path $recoveryHelperOutput 'openclaw-gateway-recovery.exe')
if ($recoveryHelperSubsystem -ne 2) {
throw (
"The published $Architecture sign-in helper must be a Windows GUI " +
"executable; its subsystem is $recoveryHelperSubsystem."
)
}
$appxOutput = $msixBuildDirectory.TrimEnd('\') + '\'
Write-Host "Building unsigned NativeAOT win-$Architecture MSIX with MSBuild."
Invoke-CheckedCommand `
-FailureMessage 'NativeAOT MSIX build failed.' `
-Command {
& dotnet build $projectPath `
--configuration Release `
--runtime "win-$Architecture" `
--no-restore `
"-p:Platform=$Architecture" `
"-p:RuntimeIdentifiers=win-$Architecture" `
-p:PublishAot=true `
-p:SelfContained=true `
-p:IncludePackagingContent=true `
"-p:NodeRuntimeArchiveFileName=$expectedNodeArchiveName" `
-p:GenerateAppxPackageOnBuild=true `
"-p:AssemblyVersion=$PackageVersion" `
"-p:FileVersion=$PackageVersion" `
"-p:PackageIdentityVersion=$PackageVersion" `
"-p:PackageIdentityName=$packageIdentityName" `
"-p:PackageIdentityPublisher=$msbuildPublisher" `
"-p:ClawCtlPackageVersion=$PackageVersion" `
"-p:ClawCtlPackageCommit=$($SourceCommit.ToLowerInvariant())" `
"-p:ClawCtlPayloadVersion=$([string]$payloadInfo.packageVersion)" `
"-p:ClawCtlPayloadCommit=$($payloadInfo.resolvedCommit.ToLowerInvariant())" `
"-p:AppxPackageDir=$appxOutput" `
-p:AppxBundle=Never `
-p:AppxPackageSigningEnabled=false `
-p:DebugType=None `
--nologo
}
$builtPackages = @(
Get-ChildItem `
-LiteralPath $msixBuildDirectory `
-Filter '*.msix' `
-File `
-Recurse
)
if ($builtPackages.Count -ne 1) {
throw (
"Expected one MSIX under '$msixBuildDirectory'; " +
"found $($builtPackages.Count)."
)
}
$msixName = "OpenClawGateway-$Architecture.msix"
$msixPath = Join-Path $OutputDirectory $msixName
Copy-Item -LiteralPath $builtPackages[0].FullName -Destination $msixPath -Force
$expectedPackageFiles =
[System.Collections.Generic.Dictionary[string, object]]::new(
[System.StringComparer]::OrdinalIgnoreCase
)
foreach ($applicationFile in $payloadFiles) {
$expectedPackageFiles.Add(
"app/$($applicationFile.path)",
[pscustomobject]@{
Hash = $applicationFile.sha256
}
)
}
$expectedPackageFiles.Add(
'payload/payload-files.json',
[pscustomobject]@{
Hash = (
Get-FileHash `
-LiteralPath $payloadInventoryPath `
-Algorithm SHA256
).Hash.ToLowerInvariant()
}
)
$expectedPackageFiles.Add(
'payload/startup-files.json',
[pscustomobject]@{
Hash = (
Get-FileHash `
-LiteralPath $startupFilesPath `
-Algorithm SHA256
).Hash.ToLowerInvariant()
}
)
$expectedPackageFiles.Add(
"runtime/$expectedNodeArchiveName",
[pscustomobject]@{
Hash = $nodeArchiveHash
}
)
foreach ($mxcFile in $mxcMetadataFiles) {
$expectedPackageFiles.Add(
[IO.Path]::GetFileName($mxcFile),
[pscustomobject]@{
Hash = (Get-FileHash -LiteralPath $mxcFile -Algorithm SHA256).Hash.ToLowerInvariant()
}
)
}
foreach ($sessionHostFile in $sessionHostFiles) {
$expectedPackageFiles.Add(
"session-host/$Architecture/$($sessionHostFile.path)",
[pscustomobject]@{
Hash = $sessionHostFile.sha256
}
)
}
foreach ($recoveryHelperFile in $recoveryHelperFiles) {
$expectedPackageFiles.Add(
$recoveryHelperFile.path,
[pscustomobject]@{
Hash = $recoveryHelperFile.sha256
}
)
}
$packageEntries = [System.Collections.Generic.HashSet[string]]::new(
[System.StringComparer]::OrdinalIgnoreCase
)
Add-Type -AssemblyName System.IO.Compression.FileSystem
$packageArchive = [System.IO.Compression.ZipFile]::OpenRead($msixPath)
try {
foreach ($entry in $packageArchive.Entries) {
if ([string]::IsNullOrEmpty($entry.Name)) {
continue
}
$decodedPath = [Uri]::UnescapeDataString($entry.FullName)
if (-not $packageEntries.Add($decodedPath)) {
throw "The MSIX contains a duplicate decoded path: $decodedPath"
}
$expectedEntry = $null
if (
-not $expectedPackageFiles.Remove(
$decodedPath,
[ref]$expectedEntry
)
) {
continue
}
$stream = $entry.Open()
$sha256 = [Security.Cryptography.SHA256]::Create()
try {
$packagedHash = [Convert]::ToHexString(
$sha256.ComputeHash($stream)
).ToLowerInvariant()
}
finally {
$sha256.Dispose()
$stream.Dispose()
}
if ($packagedHash -ne $expectedEntry.Hash) {
throw "MSBuild changed package content: $decodedPath"
}
}
$manifestEntry = $packageArchive.GetEntry('AppxManifest.xml')
if (-not $manifestEntry) {
throw 'The MSIX does not contain AppxManifest.xml.'
}
$manifestStream = $manifestEntry.Open()
$manifestReader = [IO.StreamReader]::new($manifestStream)
try {
[xml]$manifest = $manifestReader.ReadToEnd()
}
finally {
$manifestReader.Dispose()
$manifestStream.Dispose()
}
$builtIdentity = $manifest.Package.Identity
if (
$null -eq $builtIdentity -or
[string]$builtIdentity.Name -cne $packageIdentityName -or
[string]$builtIdentity.Publisher -cne $publisher -or
[string]$builtIdentity.ProcessorArchitecture -cne $Architecture -or
[string]$builtIdentity.Version -cne $PackageVersion
) {
throw "The built $IdentityChannel MSIX manifest identity is unexpected."
}
$aliasExtension = @(
$manifest.SelectNodes(
"//*[local-name()='Extension' and @Category='windows.appExecutionAlias']"
)
)
if ($aliasExtension.Count -ne 3) {
throw 'The MSIX must contain public, control, and sign-in helper app execution alias extensions.'
}
$aliasTargets = @{
'openclaw.exe' = 'openclaw.exe'
'clawctl.exe' = 'openclaw.exe'
'openclaw-gateway-recovery.exe' = 'openclaw-gateway-recovery.exe'
}
foreach ($extension in $aliasExtension) {
$extensionAliases = @(
$extension.SelectNodes(".//*[local-name()='ExecutionAlias']") |
ForEach-Object { $_.Alias }
)
if (
$extensionAliases.Count -ne 1 -or
-not $aliasTargets.ContainsKey([string]$extensionAliases[0]) -or
$extension.Executable -cne $aliasTargets[[string]$extensionAliases[0]]
) {
throw 'Each command alias must target its own executable.'
}
}
$registeredAliases = @(
$aliasExtension |
ForEach-Object { $_.SelectNodes(".//*[local-name()='ExecutionAlias']") } |
ForEach-Object { $_.Alias }
)
foreach ($requiredAlias in $aliasTargets.Keys) {
if ($requiredAlias -notin $registeredAliases) {
throw "The MSIX does not register $requiredAlias."
}
}
}
finally {
$packageArchive.Dispose()
}
if (-not $packageEntries.Contains('openclaw.exe')) {
throw 'The MSIX does not contain the NativeAOT host executable.'
}
$unexpectedNodeEntries = @(
$packageEntries |
Where-Object {
(
[IO.Path]::GetFileName($_) -ieq 'node.exe' -or
[IO.Path]::GetFileName($_) -match '^node-v\d'
) -and
$_ -ine "runtime/$expectedNodeArchiveName"
}
)
if ($unexpectedNodeEntries.Count -ne 0) {
throw (
'The MSIX contains unexpected Node.js content: ' +
(($unexpectedNodeEntries | Sort-Object) -join ', ')
)
}
foreach ($managedHostArtifact in @(
'openclaw.dll',
'openclaw.deps.json',
'openclaw.runtimeconfig.json'
)) {
if ($packageEntries.Contains($managedHostArtifact)) {
throw "The MSIX contains managed host artifact: $managedHostArtifact"
}
}
if ($expectedPackageFiles.Count -ne 0) {
throw (
'MSBuild omitted package content: ' +
(
$expectedPackageFiles.Keys |
Sort-Object |
Select-Object -First 5
) -join ', '
)
}
$msixHash = (
Get-FileHash -LiteralPath $msixPath -Algorithm SHA256
).Hash.ToLowerInvariant()
[ordered]@{
packagingRepository = 'https://github.com/openclaw/openclaw-windows-packaging'
packagingCommit = $SourceCommit.ToLowerInvariant()
sourceTreeDirty = $SourceTreeDirty.IsPresent
payloadRepository = $payloadInfo.repository
payloadRequestedRef = $payloadInfo.requestedRef
payloadResolvedCommit = $payloadInfo.resolvedCommit.ToLowerInvariant()
payloadPackageVersion = [string]$payloadInfo.packageVersion
payloadLayout = 'immutable-package'
payloadFileCount = $payloadFiles.Count
nodeRuntimeVersion = $nodeVersion
nodeRuntimeArchive = $expectedNodeArchiveName
nodeRuntimeSha256 = $nodeArchiveHash
mxcRuntimeVersion = [string]$mxcProvenance.version
mxcRuntimePackage = [string]$mxcProvenance.package
sessionHostFiles = $sessionHostFiles
gatewayRecoveryFiles = $recoveryHelperFiles
architecture = $Architecture
archive = $msixName
sha256 = $msixHash
signed = $false
identityChannel = $IdentityChannel.ToLowerInvariant()
packageVersion = $PackageVersion
packageIdentityName = $packageIdentityName
packageFamilyName = $packageFamilyName
publisher = $publisher
} | ConvertTo-Json |
Set-Content `
-LiteralPath (Join-Path $OutputDirectory 'msix-metadata.json') `
-Encoding utf8
Write-Host "Created unsigned MSIX: $msixPath"
}
finally {
Remove-DirectoryIfPresent -Path $workRoot
}