Repository navigation
538 lines (479 loc) · 26.7 KB
/
Copy pathwindows-release.yml
File metadata and controls
538 lines (479 loc) · 26.7 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
name: Windows Release
on:
push:
tags:
- 'v*-windows'
workflow_dispatch:
inputs:
tag:
description: 'Windows release tag (for example, v1.0.1-windows)'
required: true
type: string
permissions:
contents: write
id-token: write
concurrency:
group: windows-release
cancel-in-progress: false
queue: max
env:
APP_PROJECT: windows/src/TinyClips.App/TinyClips.App.csproj
PACKAGE_FAMILY_NAME: Refractored.TinyClips_vmshqmcyy894t
SIGNTOOL_TIMESTAMP_URL: http://timestamp.acs.microsoft.com
jobs:
build-sign-release:
name: Build, sign, and release MSIX
runs-on: windows-latest
environment: windows-release
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Place NuGet caches in runner temp
if: runner.os == 'Windows' && runner.environment == 'github-hosted'
shell: pwsh
run: |
$packages = Join-Path $env:RUNNER_TEMP 'nuget\packages'
$httpCache = Join-Path $env:RUNNER_TEMP 'nuget\http-cache'
New-Item -ItemType Directory -Force -Path $packages, $httpCache | Out-Null
"NUGET_PACKAGES=$packages" >> $env:GITHUB_ENV
"NUGET_HTTP_CACHE_PATH=$httpCache" >> $env:GITHUB_ENV
- name: Setup .NET SDK
uses: actions/setup-dotnet@v5
with:
dotnet-version: 10.0.x
- name: Set release version
shell: pwsh
run: |
$tag = if ("${{ github.event_name }}" -eq "workflow_dispatch") {
"${{ inputs.tag }}"
} else {
"${{ github.ref_name }}"
}
if ($tag -notmatch '^v(?<base>\d+\.\d+\.\d+)(?:\.(?<revision>\d+))?-windows$') {
throw "Windows release tags must look like v1.2.3-windows or v1.2.3.4-windows. Got '$tag'."
}
$revision = if ($Matches.revision) { $Matches.revision } else { "0" }
$packageVersion = "$($Matches.base).$revision"
$assetVersion = if ($Matches.revision) { "$($Matches.base).$revision" } else { $Matches.base }
"RELEASE_TAG=$tag" >> $env:GITHUB_ENV
"PACKAGE_VERSION=$packageVersion" >> $env:GITHUB_ENV
"ASSET_VERSION=$assetVersion" >> $env:GITHUB_ENV
- name: Stamp package manifest version
shell: pwsh
run: |
$manifestPath = "windows/src/TinyClips.App/Package.appxmanifest"
$content = Get-Content $manifestPath -Raw
$content = $content -creplace '(<Identity[\s\S]*?Version=")[^"]+(")', "`${1}$env:PACKAGE_VERSION`${2}"
Set-Content -Path $manifestPath -Value $content -Encoding UTF8
- name: Build and package MSIX
shell: pwsh
run: |
New-Item -ItemType Directory -Force -Path artifacts/windows | Out-Null
"### Direct package sizes" >> $env:GITHUB_STEP_SUMMARY
"| Architecture | Compressed size |" >> $env:GITHUB_STEP_SUMMARY
"|---|---:|" >> $env:GITHUB_STEP_SUMMARY
# Direct release packages bundle the .NET 10 runtime and the Windows App SDK runtime and run
# on CoreCLR, like the Store flavor (no NativeAOT, no trimming).
# Keep build + MSIX packaging in this one invocation so the executable retains the
# registration-free WinRT activatable-class metadata required on clean machines.
$platforms = @(
@{ Platform = "x64"; Rid = "win-x64"; Asset = "x64" }
@{ Platform = "ARM64"; Rid = "win-arm64"; Asset = "arm64" }
)
foreach ($p in $platforms) {
$packageDir = "artifacts/windows/package/$($p.Asset)"
New-Item -ItemType Directory -Force -Path $packageDir | Out-Null
$packageDirFull = (Resolve-Path $packageDir).Path + [IO.Path]::DirectorySeparatorChar
$stableReleaseBase = "https://github.com/jamesmontemagno/tiny-clips/releases/download/windows-latest"
$packageUri = "https://github.com/jamesmontemagno/tiny-clips/releases/download/$env:RELEASE_TAG/TinyClips-$env:ASSET_VERSION-$($p.Asset).msix"
$appInstallerUri = "$stableReleaseBase/TinyClips-$($p.Asset).appinstaller"
$appInstallerPath = "artifacts/windows/TinyClips-$($p.Asset).appinstaller"
# The App Installer configuration ships only as a standalone release asset. It is not
# embedded in the MSIX; Assert-DirectPackage.ps1 rejects packages that embed it.
& ./windows/packaging/New-AppInstaller.ps1 `
-ManifestPath windows/src/TinyClips.App/Package.appxmanifest `
-AppInstallerPath $appInstallerPath `
-Architecture $p.Asset `
-PackageUri $packageUri `
-AppInstallerUri $appInstallerUri
dotnet build $env:APP_PROJECT `
-c Release `
-p:Platform=$($p.Platform) `
-p:RuntimeIdentifier=$($p.Rid) `
-p:TinyClipsDirectReleaseBuild=true `
-p:PublishAot=false `
-p:SelfContained=true `
-p:WindowsAppSDKSelfContained=true `
-p:PublishTrimmed=false `
-p:EnableMsixTooling=true `
-p:GenerateAppxPackageOnBuild=true `
-p:AppxPackageDir=$packageDirFull `
-p:AppxBundle=Never `
-p:UapAppxPackageBuildMode=SideloadOnly `
-p:AppxPackageSigningEnabled=false `
-v:minimal
if ($LASTEXITCODE -ne 0) { throw "MSIX build failed for $($p.Platform)." }
$produced = Get-ChildItem $packageDir -Recurse -Filter *.msix |
Where-Object { $_.Name -notmatch 'symbols' } |
Select-Object -First 1
if (-not $produced) { throw "No MSIX produced for $($p.Platform)." }
& windows/packaging/Assert-DirectPackage.ps1 `
-MsixPath $produced.FullName `
-Architecture $p.Asset
[xml]$appInstallerDocument = Get-Content $appInstallerPath -Raw
$appInstallerNamespaces = [Xml.XmlNamespaceManager]::new($appInstallerDocument.NameTable)
$appInstallerNamespaces.AddNamespace("ai", "http://schemas.microsoft.com/appx/appinstaller/2018")
$appInstallerRoot = $appInstallerDocument.SelectSingleNode("/ai:AppInstaller", $appInstallerNamespaces)
$mainPackage = $appInstallerDocument.SelectSingleNode("/ai:AppInstaller/ai:MainPackage", $appInstallerNamespaces)
$onLaunch = $appInstallerDocument.SelectSingleNode("/ai:AppInstaller/ai:UpdateSettings/ai:OnLaunch", $appInstallerNamespaces)
$backgroundTask = $appInstallerDocument.SelectSingleNode("/ai:AppInstaller/ai:UpdateSettings/ai:AutomaticBackgroundTask", $appInstallerNamespaces)
if ($appInstallerRoot.Version -ne $env:PACKAGE_VERSION -or $mainPackage.Version -ne $env:PACKAGE_VERSION) {
throw "App Installer version for $($p.Platform) does not match $env:PACKAGE_VERSION."
}
if ($mainPackage.Name -ne "Refractored.TinyClips" -or
$mainPackage.Publisher -ne "CN=Refractored LLC, O=Refractored LLC, L=Seattle, S=Washington, C=US" -or
$mainPackage.ProcessorArchitecture -ne $p.Asset -or
$mainPackage.Uri -ne $packageUri -or
$appInstallerRoot.Uri -ne $appInstallerUri) {
throw "App Installer identity or stable URL is invalid for $($p.Platform)."
}
if (-not $onLaunch -or $onLaunch.HoursBetweenUpdateChecks -ne "24") {
throw "App Installer for $($p.Platform) must check on launch about every 24 hours."
}
if (-not $backgroundTask) {
throw "App Installer for $($p.Platform) must check for updates in the background."
}
$releasePackage = "artifacts/windows/TinyClips-$env:ASSET_VERSION-$($p.Asset).msix"
Copy-Item $produced.FullName $releasePackage -Force
$sizeMiB = [Math]::Round((Get-Item $releasePackage).Length / 1MB, 2)
"| $($p.Asset) | $sizeMiB MiB |" >> $env:GITHUB_STEP_SUMMARY
}
- name: Azure login
uses: azure/login@v3
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Download Artifact Signing client
shell: pwsh
run: |
New-Item -ItemType Directory -Force -Path artifacts/tools | Out-Null
$nuget = Join-Path (Resolve-Path artifacts/tools) "nuget.exe"
Invoke-WebRequest -Uri https://dist.nuget.org/win-x86-commandline/latest/nuget.exe -OutFile $nuget
& $nuget install Microsoft.ArtifactSigning.Client -OutputDirectory artifacts/tools -ExcludeVersion -NonInteractive
- name: Sign MSIX packages
shell: pwsh
run: |
$signtool = Get-ChildItem "${env:ProgramFiles(x86)}\Windows Kits\10\bin" -Recurse -Filter signtool.exe |
Where-Object { $_.FullName -match '\\x64\\signtool\.exe$' } |
Sort-Object FullName -Descending |
Select-Object -First 1 -ExpandProperty FullName
if (!$signtool) {
throw "SignTool x64 was not found."
}
$dlib = Get-ChildItem artifacts/tools/Microsoft.ArtifactSigning.Client -Recurse -Filter Azure.CodeSigning.Dlib.dll |
Where-Object { $_.FullName -match '\\bin\\x64\\' } |
Select-Object -First 1 -ExpandProperty FullName
if (!$dlib) {
throw "Azure.CodeSigning.Dlib.dll x64 was not found."
}
$metadataPath = Join-Path (Resolve-Path artifacts/windows) "artifact-signing-metadata.json"
@{
Endpoint = "${{ secrets.AZURE_ARTIFACT_SIGNING_ENDPOINT }}"
CodeSigningAccountName = "${{ secrets.AZURE_ARTIFACT_SIGNING_ACCOUNT_NAME }}"
CertificateProfileName = "${{ secrets.AZURE_ARTIFACT_SIGNING_CERTIFICATE_PROFILE_NAME }}"
CorrelationId = "${{ github.repository }}-${{ github.run_id }}"
ExcludeCredentials = @(
"ManagedIdentityCredential",
"WorkloadIdentityCredential",
"SharedTokenCacheCredential",
"VisualStudioCredential",
"VisualStudioCodeCredential",
"AzurePowerShellCredential",
"AzureDeveloperCliCredential",
"InteractiveBrowserCredential"
)
} | ConvertTo-Json | Set-Content -Path $metadataPath -Encoding UTF8
& $signtool sign /v /fd SHA256 /tr $env:SIGNTOOL_TIMESTAMP_URL /td SHA256 /dlib "$dlib" /dmdf "$metadataPath" "artifacts/windows/TinyClips-$env:ASSET_VERSION-x64.msix"
& $signtool sign /v /fd SHA256 /tr $env:SIGNTOOL_TIMESTAMP_URL /td SHA256 /dlib "$dlib" /dmdf "$metadataPath" "artifacts/windows/TinyClips-$env:ASSET_VERSION-arm64.msix"
- name: Verify signatures
shell: pwsh
run: |
$signtool = Get-ChildItem "${env:ProgramFiles(x86)}\Windows Kits\10\bin" -Recurse -Filter signtool.exe |
Where-Object { $_.FullName -match '\\x64\\signtool\.exe$' } |
Sort-Object FullName -Descending |
Select-Object -First 1 -ExpandProperty FullName
& $signtool verify /pa /v "artifacts/windows/TinyClips-$env:ASSET_VERSION-x64.msix"
& $signtool verify /pa /v "artifacts/windows/TinyClips-$env:ASSET_VERSION-arm64.msix"
- name: Run WACK
shell: pwsh
run: |
$appcert = "${env:ProgramFiles(x86)}\Windows Kits\10\App Certification Kit\appcert.exe"
if (!(Test-Path $appcert)) {
throw "Windows App Certification Kit appcert.exe was not found at '$appcert'."
}
New-Item -ItemType Directory -Force -Path artifacts/windows/wack | Out-Null
$wackDir = Resolve-Path artifacts/windows/wack
& $appcert test -appxpackagepath (Resolve-Path "artifacts/windows/TinyClips-$env:ASSET_VERSION-x64.msix") -reportoutputpath (Join-Path $wackDir "TinyClips-$env:ASSET_VERSION-x64-wack.xml")
& $appcert test -appxpackagepath (Resolve-Path "artifacts/windows/TinyClips-$env:ASSET_VERSION-arm64.msix") -reportoutputpath (Join-Path $wackDir "TinyClips-$env:ASSET_VERSION-arm64-wack.xml")
foreach ($report in Get-ChildItem artifacts/windows/wack/*.xml) {
[xml]$xml = Get-Content $report.FullName
if ($xml.REPORT.OVERALL_RESULT -ne "PASS") {
throw "WACK failed for $($report.Name): $($xml.REPORT.OVERALL_RESULT)"
}
}
- name: Compute winget hashes
shell: pwsh
run: |
$x64Package = "artifacts/windows/TinyClips-$env:ASSET_VERSION-x64.msix"
$arm64Package = "artifacts/windows/TinyClips-$env:ASSET_VERSION-arm64.msix"
$x64InstallerHash = (winget hash $x64Package | Select-String 'InstallerSha256:' | Select-Object -Last 1).ToString().Split(':')[1].Trim()
$x64SignatureHash = (winget hash --msix $x64Package | Select-String 'SignatureSha256:' | Select-Object -Last 1).ToString().Split(':')[1].Trim()
$arm64InstallerHash = (winget hash $arm64Package | Select-String 'InstallerSha256:' | Select-Object -Last 1).ToString().Split(':')[1].Trim()
$arm64SignatureHash = (winget hash --msix $arm64Package | Select-String 'SignatureSha256:' | Select-Object -Last 1).ToString().Split(':')[1].Trim()
"X64_INSTALLER_SHA256=$x64InstallerHash" >> $env:GITHUB_ENV
"X64_SIGNATURE_SHA256=$x64SignatureHash" >> $env:GITHUB_ENV
"ARM64_INSTALLER_SHA256=$arm64InstallerHash" >> $env:GITHUB_ENV
"ARM64_SIGNATURE_SHA256=$arm64SignatureHash" >> $env:GITHUB_ENV
@"
PackageVersion: $env:PACKAGE_VERSION
PackageFamilyName: $env:PACKAGE_FAMILY_NAME
x64 InstallerSha256: $x64InstallerHash
x64 SignatureSha256: $x64SignatureHash
arm64 InstallerSha256: $arm64InstallerHash
arm64 SignatureSha256: $arm64SignatureHash
"@ | Set-Content -Path artifacts/windows/winget-hashes.txt -Encoding UTF8
- name: Generate winget manifest artifact
shell: pwsh
run: |
$wingetDir = "artifacts/windows/winget"
New-Item -ItemType Directory -Force -Path $wingetDir | Out-Null
Copy-Item windows/packaging/winget/Refractored.TinyClips.yaml $wingetDir
Copy-Item windows/packaging/winget/Refractored.TinyClips.locale.en-US.yaml $wingetDir
foreach ($manifest in Get-ChildItem $wingetDir/*.yaml) {
$content = Get-Content $manifest.FullName -Raw
$content = $content -replace 'PackageVersion: .*', "PackageVersion: $env:PACKAGE_VERSION"
Set-Content -Path $manifest.FullName -Value $content -Encoding UTF8
}
@"
# yaml-language-server: `$schema=https://aka.ms/winget-manifest.installer.1.12.0.schema.json
# Installer manifest for the signed, self-contained MSIX produced by the
# Windows Release workflow. The package bundles the .NET runtime and Windows App SDK,
# so winget runtime package dependencies are intentionally unnecessary.
PackageIdentifier: Refractored.TinyClips
PackageVersion: $env:PACKAGE_VERSION
MinimumOSVersion: 10.0.22000.0
InstallerType: msix
InstallModes:
- silent
- silentWithProgress
PackageFamilyName: $env:PACKAGE_FAMILY_NAME
Installers:
- Architecture: x64
InstallerUrl: https://github.com/jamesmontemagno/tiny-clips/releases/download/$env:RELEASE_TAG/TinyClips-$env:ASSET_VERSION-x64.msix
InstallerSha256: $env:X64_INSTALLER_SHA256
SignatureSha256: $env:X64_SIGNATURE_SHA256
- Architecture: arm64
InstallerUrl: https://github.com/jamesmontemagno/tiny-clips/releases/download/$env:RELEASE_TAG/TinyClips-$env:ASSET_VERSION-arm64.msix
InstallerSha256: $env:ARM64_INSTALLER_SHA256
SignatureSha256: $env:ARM64_SIGNATURE_SHA256
ManifestType: installer
ManifestVersion: 1.12.0
"@ | ForEach-Object { $_ -replace '^ ', '' } |
Set-Content -Path (Join-Path $wingetDir "Refractored.TinyClips.installer.yaml") -Encoding UTF8
# winget validate returns a non-zero exit code for non-fatal warnings as well as
# for errors. The GitHub runner can ship an older winget that doesn't recognize the
# 1.12.0 schema header and warns about it, even though the manifest is valid (and the
# always-current winget-pkgs validation accepts it). Distinguish success-with-warnings
# from a real failure by inspecting the output text rather than the exit code.
$validateOutput = winget validate --manifest $wingetDir 2>&1 | Out-String
Write-Host $validateOutput
if ($validateOutput -notmatch 'Manifest validation succeeded') {
throw "winget validate failed:`n$validateOutput"
}
# winget leaves a non-zero $LASTEXITCODE for warnings; the GitHub pwsh shell appends
# `exit $LASTEXITCODE`, so reset it after confirming validation succeeded.
$global:LASTEXITCODE = 0
- name: Generate release notes
shell: pwsh
run: |
$lines = Get-Content windows/CHANGELOG.md
$escapedTag = [regex]::Escape($env:RELEASE_TAG)
$start = $null
for ($i = 0; $i -lt $lines.Count; $i++) {
if ($lines[$i] -match "^## \[$escapedTag\]") {
$start = $i
break
}
}
if ($null -ne $start) {
$end = $lines.Count
for ($i = $start + 1; $i -lt $lines.Count; $i++) {
if ($lines[$i] -match '^## ') {
$end = $i
break
}
}
$notes = @($lines[($start + 1)..($end - 1)] | Where-Object { $_ -ne "" })
} else {
$notes = @("Windows release $env:PACKAGE_VERSION.")
}
$notes += ""
$notes += "## Install"
$notes += 'For direct installation with automatic updates, download the `.appinstaller` for your architecture below. It always resolves through the stable update channel, so opening one from an older release installs the current Windows version. Windows checks periodically in the background and on launch when about 24 hours have passed.'
$notes += 'The MSIX bundles the .NET runtime and Windows App SDK runtime, so direct installation has no separate runtime prerequisite.'
$notes += ""
$notes += "Tiny Clips is also published in the [winget community repository](https://github.com/microsoft/winget-pkgs). Install it from any Windows 11 terminal:"
$notes += ""
$notes += '```text'
$notes += 'winget install Refractored.TinyClips'
$notes += '```'
$notes += ""
$notes += 'winget installs the same direct MSIX, but winget installs do not receive App Installer updates. Update them with `winget upgrade Refractored.TinyClips` or the in-app update check.'
$notes += ""
$notes += "## Release validation"
$notes += "- Direct packages are self-contained for both .NET 10 and Windows App SDK and run on CoreCLR."
$notes += "- Package inspection confirmed architecture, bundled .NET and WinUI/Windows App SDK runtime files, no WindowsAppRuntime framework dependency, and no embedded App Installer configuration."
$notes += "- Azure Artifact Signing completed for x64 and ARM64 MSIX packages."
$notes += "- SignTool verification passed for x64 and ARM64 MSIX packages."
$notes += "- WACK overall result passed for x64 and ARM64 MSIX packages."
$notes += ""
$notes += "## winget hashes"
$notes += '```text'
$notes += (Get-Content artifacts/windows/winget-hashes.txt)
$notes += '```'
$notes | Set-Content -Path artifacts/windows/release-notes.md -Encoding UTF8
- name: Upload release artifacts
uses: actions/upload-artifact@v7
with:
name: windows-release
path: |
artifacts/windows/*.msix
artifacts/windows/*.appinstaller
artifacts/windows/*.txt
artifacts/windows/winget/*.yaml
artifacts/windows/wack/*.xml
- name: Create GitHub Release
uses: softprops/action-gh-release@v3
with:
tag_name: ${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.ref_name }}
name: Tiny Clips for Windows ${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.ref_name }}
body_path: artifacts/windows/release-notes.md
files: |
artifacts/windows/*.msix
artifacts/windows/*.appinstaller
artifacts/windows/winget-hashes.txt
artifacts/windows/wack/*.xml
overwrite_files: false
preserve_order: true
fail_on_unmatched_files: true
draft: false
prerelease: ${{ contains(github.event_name == 'workflow_dispatch' && inputs.tag || github.ref_name, 'beta') || contains(github.event_name == 'workflow_dispatch' && inputs.tag || github.ref_name, 'alpha') }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Promote stable direct-install assets
shell: pwsh
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
$rollingDir = "artifacts/windows/rolling"
New-Item -ItemType Directory -Force -Path $rollingDir | Out-Null
Copy-Item "artifacts/windows/TinyClips-x64.appinstaller" $rollingDir -Force
Copy-Item "artifacts/windows/TinyClips-arm64.appinstaller" $rollingDir -Force
$rollingReleaseCreated = $false
gh release view windows-latest --repo "${{ github.repository }}" *> $null
if ($LASTEXITCODE -ne 0) {
gh release create windows-latest `
--repo "${{ github.repository }}" `
--target "${{ github.sha }}" `
--title "Tiny Clips for Windows (auto-update channel)" `
--notes "Stable App Installer metadata for direct MSIX installs. Each file references the signed, immutable MSIX in its versioned Windows release. The source archives identify only the commit that created this channel; use the App Installer assets for current channel state." `
--latest=false
if ($LASTEXITCODE -ne 0) { throw "Could not create the windows-latest rolling release." }
$rollingReleaseCreated = $true
}
$currentDir = "artifacts/windows/current-appinstaller"
New-Item -ItemType Directory -Force -Path $currentDir | Out-Null
if (-not $rollingReleaseCreated) {
$downloadedCurrent = $false
for ($attempt = 1; $attempt -le 3 -and -not $downloadedCurrent; $attempt++) {
gh release download windows-latest `
--repo "${{ github.repository }}" `
--pattern "*.appinstaller" `
--dir $currentDir `
--clobber
$downloadedCurrent = $LASTEXITCODE -eq 0
if (-not $downloadedCurrent -and $attempt -lt 3) { Start-Sleep -Seconds (5 * $attempt) }
}
if (-not $downloadedCurrent) {
throw "Could not read the existing windows-latest channel; refusing to promote without a downgrade check."
}
foreach ($architecture in @("x64", "arm64")) {
if (-not (Test-Path "$currentDir/TinyClips-$architecture.appinstaller")) {
throw "The existing windows-latest channel is missing its $architecture App Installer; repair it before promoting."
}
}
foreach ($currentInstaller in Get-ChildItem $currentDir -Filter *.appinstaller) {
[xml]$current = Get-Content $currentInstaller.FullName -Raw
$currentVersion = [version]$current.AppInstaller.Version
$candidateVersion = [version]$env:PACKAGE_VERSION
if ($currentVersion -gt $candidateVersion) {
throw "Refusing to downgrade windows-latest from $($current.AppInstaller.Version) to $env:PACKAGE_VERSION."
}
$candidateInstaller = Join-Path $rollingDir $currentInstaller.Name
if ($currentVersion -eq $candidateVersion -and
(Get-FileHash $currentInstaller.FullName).Hash -ne (Get-FileHash $candidateInstaller).Hash) {
throw "Refusing to replace windows-latest version $env:PACKAGE_VERSION with different App Installer metadata."
}
}
}
$global:LASTEXITCODE = 0
function Publish-AppInstallers([string] $sourceDirectory) {
for ($attempt = 1; $attempt -le 3; $attempt++) {
gh release upload windows-latest `
"$sourceDirectory/TinyClips-x64.appinstaller" `
"$sourceDirectory/TinyClips-arm64.appinstaller" `
--repo "${{ github.repository }}" `
--clobber 2>&1 | ForEach-Object { Write-Host $_ }
if ($LASTEXITCODE -eq 0) { return $true }
if ($attempt -lt 3) { Start-Sleep -Seconds (5 * $attempt) }
}
return $false
}
function Restore-PreviousChannel {
if ($rollingReleaseCreated) {
gh release delete windows-latest --repo "${{ github.repository }}" --cleanup-tag --yes
return
}
if (-not (Publish-AppInstallers $currentDir)) {
throw "Promotion failed and the previous windows-latest channel could not be restored."
}
}
if (-not (Publish-AppInstallers $rollingDir)) {
Restore-PreviousChannel
throw "Could not publish rolling App Installer assets after three attempts."
}
try {
$verifyDir = "artifacts/windows/verify-appinstaller"
New-Item -ItemType Directory -Force -Path $verifyDir | Out-Null
gh release download windows-latest `
--repo "${{ github.repository }}" `
--pattern "*.appinstaller" `
--dir $verifyDir `
--clobber
if ($LASTEXITCODE -ne 0) { throw "Could not download rolling App Installer assets for verification." }
foreach ($architecture in @("x64", "arm64")) {
$local = "$rollingDir/TinyClips-$architecture.appinstaller"
$publishedFile = "$verifyDir/TinyClips-$architecture.appinstaller"
if (-not (Test-Path $publishedFile) -or
(Get-FileHash $local).Hash -ne (Get-FileHash $publishedFile).Hash) {
throw "Published $architecture App Installer does not match the release artifact."
}
}
}
catch {
Restore-PreviousChannel
throw
}