-
Notifications
You must be signed in to change notification settings - Fork 1
556 lines (462 loc) Β· 20.4 KB
/
Copy pathrelease.yml
File metadata and controls
556 lines (462 loc) Β· 20.4 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
name: Release
on:
push:
tags:
- "v*.*.*"
workflow_dispatch:
inputs:
dry_run_publish:
description: "Build and validate release without winget publication"
required: false
default: "false"
permissions:
contents: write
jobs:
build:
runs-on: windows-2022
outputs:
version: ${{ steps.version.outputs.version }}
tag: ${{ steps.version.outputs.tag }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: "8.0.x"
- name: Resolve version
id: version
shell: pwsh
run: |
$refName = "${{ github.ref_name }}"
if ($refName -match '^v\d+\.\d+\.\d+$') {
$version = $refName.TrimStart('v')
$tag = $refName
}
else {
[xml]$project = Get-Content "ThreadPilot.csproj"
$version = $project.Project.PropertyGroup.Version
if ([string]::IsNullOrWhiteSpace($version)) {
throw "Unable to resolve version from tag or ThreadPilot.csproj"
}
$tag = "v$version"
}
"version=$version" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
"tag=$tag" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
- name: Restore
run: dotnet restore "ThreadPilot_1.sln"
- name: Build
run: dotnet build "ThreadPilot_1.sln" --configuration Release --no-restore
- name: Test
run: dotnet test "Tests/ThreadPilot.Core.Tests/ThreadPilot.Core.Tests.csproj" --configuration Release --no-restore --verbosity normal --collect:"XPlat Code Coverage" --settings "Tests/ThreadPilot.Core.Tests/coverlet.runsettings" --results-directory TestResults
- name: Publish self-contained single-file
run: dotnet publish "ThreadPilot.csproj" --configuration Release -p:PublishProfile=WinX64-SingleFile
- name: Ensure bundled power plans in single-file output
shell: pwsh
run: |
$ErrorActionPreference = "Stop"
New-Item -ItemType Directory -Force -Path "artifacts/release/singlefile/Powerplans" | Out-Null
Copy-Item "assets/Powerplans/*" -Destination "artifacts/release/singlefile/Powerplans" -Recurse -Force
- name: Publish ReadyToRun
run: dotnet publish "ThreadPilot.csproj" --configuration Release -p:PublishProfile=WinX64-ReadyToRun
- name: Install Inno Setup
shell: pwsh
run: choco install innosetup --no-progress -y
- name: Build Inno Setup installer
shell: pwsh
run: |
$ErrorActionPreference = "Stop"
$version = "${{ steps.version.outputs.version }}"
$sourceDir = (Resolve-Path "artifacts/release/singlefile").Path
& iscc.exe "/DMyAppVersion=$version" "/DMyAppSourceDir=$sourceDir" "Installer/setup.iss"
- name: Prepare signing certificate (optional)
shell: pwsh
run: |
$ErrorActionPreference = "Stop"
if ([string]::IsNullOrWhiteSpace($env:WINDOWS_SIGNING_CERT_BASE64) -or [string]::IsNullOrWhiteSpace($env:WINDOWS_SIGNING_CERT_PASSWORD))
{
Write-Host "Signing secrets not provided via environment variables. Skipping certificate preparation."
exit 0
}
$certPath = Join-Path $env:RUNNER_TEMP "threadpilot-signing.pfx"
[System.IO.File]::WriteAllBytes($certPath, [System.Convert]::FromBase64String($env:WINDOWS_SIGNING_CERT_BASE64))
"THREADPILOT_SIGN_CERT_PATH=$certPath" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
- name: Sign binaries and packages (optional)
shell: pwsh
run: |
$ErrorActionPreference = "Stop"
if ([string]::IsNullOrWhiteSpace($env:THREADPILOT_SIGN_CERT_PATH) -or -not (Test-Path $env:THREADPILOT_SIGN_CERT_PATH))
{
Write-Host "No signing certificate prepared. Skipping signing step."
exit 0
}
if (-not (Get-Command signtool.exe -ErrorAction SilentlyContinue))
{
throw "signtool.exe not found on runner; install Windows SDK or disable signing."
}
$timestampUrl = "http://timestamp.digicert.com"
$password = $env:WINDOWS_SIGNING_CERT_PASSWORD
$targets = @()
$targets += Get-ChildItem "artifacts/release/singlefile" -Recurse -File -Include *.exe -ErrorAction SilentlyContinue
$targets += Get-ChildItem "artifacts/release/readytorun" -Recurse -File -Include *.exe -ErrorAction SilentlyContinue
$targets += Get-ChildItem "artifacts/release/installer" -Recurse -File -Include *.exe -ErrorAction SilentlyContinue
foreach ($target in $targets)
{
signtool.exe sign /fd SHA256 /tr $timestampUrl /td SHA256 /f "$env:THREADPILOT_SIGN_CERT_PATH" /p $password "$($target.FullName)"
}
- name: Create release packages
shell: pwsh
run: |
$ErrorActionPreference = "Stop"
$version = "${{ steps.version.outputs.tag }}"
New-Item -ItemType Directory -Force -Path "artifacts/release/packages" | Out-Null
New-Item -ItemType Directory -Force -Path "artifacts/release/package-staging" | Out-Null
$sharedUninstall = "artifacts/release/package-staging/uninstall.bat"
$sharedLicense = "artifacts/release/package-staging/LICENSE.md"
$uninstallContent = @'
@echo off
setlocal EnableExtensions
title ThreadPilot Uninstaller
set "APP_DIR=%~dp0"
if "%APP_DIR:~-1%"=="\" set "APP_DIR=%APP_DIR:~0,-1%"
echo ======================================================
echo ThreadPilot Uninstaller
echo ======================================================
echo.
echo [1/4] Closing running ThreadPilot processes...
taskkill /IM "ThreadPilot.exe" /F >nul 2>&1
echo [2/4] Removing startup task and startup registry entry...
schtasks /Delete /TN "ThreadPilot_Startup" /F >nul 2>&1
reg delete "HKCU\Software\Microsoft\Windows\CurrentVersion\Run" /v "ThreadPilot" /f >nul 2>&1
echo [3/4] Removing ThreadPilot user data for this Windows account...
rem Full uninstall removes only ThreadPilot-owned per-user AppData. Normal install/update paths never run this script.
if exist "%APPDATA%\ThreadPilot" (
rd /s /q "%APPDATA%\ThreadPilot"
echo ThreadPilot user data removed.
) else (
echo No ThreadPilot user data folder found.
)
echo [4/4] Scheduling app folder removal...
start "" /min cmd /c "timeout /t 5 /nobreak >nul & rd /s /q \"%APP_DIR%\""
echo.
echo Uninstall completed. Remaining files will be removed in a few seconds.
endlocal
exit /b 0
'@
Set-Content -LiteralPath $sharedUninstall -Value $uninstallContent -Encoding Ascii
Copy-Item "LICENSE" -Destination $sharedLicense -Force
$portableStage = "artifacts/release/package-staging/portable"
New-Item -ItemType Directory -Force -Path $portableStage | Out-Null
Copy-Item "artifacts/release/singlefile/*" -Destination $portableStage -Recurse -Force
Copy-Item $sharedUninstall -Destination (Join-Path $portableStage "uninstall.bat") -Force
Copy-Item $sharedLicense -Destination (Join-Path $portableStage "LICENSE.md") -Force
$portableZip = "artifacts/release/packages/ThreadPilot_$version`_Portable.zip"
Compress-Archive -Path "$portableStage/*" -DestinationPath $portableZip -Force
- name: Generate checksums
shell: pwsh
run: |
$ErrorActionPreference = "Stop"
$hashFile = "artifacts/release/SHA256SUMS.txt"
$releaseFiles = @()
$releaseFiles += Get-ChildItem "artifacts/release/packages" -File -ErrorAction SilentlyContinue
$releaseFiles += Get-ChildItem "artifacts/release/installer/*.exe" -File -ErrorAction SilentlyContinue
$releaseFiles | ForEach-Object {
$hash = Get-FileHash $_.FullName -Algorithm SHA256
"$($hash.Hash) $($_.Name)" | Out-File -FilePath $hashFile -Append -Encoding utf8
}
- name: Generate winget manifests
shell: pwsh
run: |
$ErrorActionPreference = "Stop"
$version = "${{ steps.version.outputs.version }}"
$tag = "${{ steps.version.outputs.tag }}"
$installer = Get-ChildItem "artifacts/release/installer/*.exe" -File | Select-Object -First 1
if (-not $installer)
{
throw "Installer executable not found."
}
$sha = (Get-FileHash $installer.FullName -Algorithm SHA256).Hash.ToUpperInvariant()
$url = "https://github.com/${{ github.repository }}/releases/download/$tag/$($installer.Name)"
./build/generate-winget-manifests.ps1 `
-Version $version `
-Tag $tag `
-InstallerUrl $url `
-InstallerSha256 $sha `
-OutputRoot "winget-manifests"
- name: Generate SBOM
shell: pwsh
run: |
$ErrorActionPreference = "Stop"
dotnet tool install --global Microsoft.Sbom.DotNetTool
$env:PATH += ";$env:USERPROFILE\.dotnet\tools"
sbom-tool generate -b ./artifacts -bc . -pn ThreadPilot -pv "${{ steps.version.outputs.version }}" -ps PrimeBuild -nsb https://github.com/PrimeBuild-pc/ThreadPilot
$sbomReleaseDir = "artifacts/release/sbom"
New-Item -ItemType Directory -Force -Path $sbomReleaseDir | Out-Null
$sbomManifest = Get-ChildItem "artifacts" -Recurse -File -Filter "manifest.spdx.json" -ErrorAction SilentlyContinue |
Sort-Object LastWriteTimeUtc -Descending |
Select-Object -First 1
if (-not $sbomManifest)
{
throw "SBOM manifest not found under artifacts after generation."
}
Copy-Item -LiteralPath $sbomManifest.FullName -Destination (Join-Path $sbomReleaseDir "manifest.spdx.json") -Force
- name: Upload portable artifact
uses: actions/upload-artifact@v4
with:
name: release-portable
path: artifacts/release/singlefile
- name: Upload installer artifact
uses: actions/upload-artifact@v4
with:
name: release-installer
path: artifacts/release/installer
- name: Upload packages artifact
uses: actions/upload-artifact@v4
with:
name: release-packages
path: artifacts/release/packages
- name: Upload checksums artifact
uses: actions/upload-artifact@v4
with:
name: release-checksums
path: artifacts/release/SHA256SUMS.txt
- name: Upload winget manifests
uses: actions/upload-artifact@v4
with:
name: winget-manifests
path: winget-manifests
- name: Upload SBOM
uses: actions/upload-artifact@v4
with:
name: sbom
path: artifacts/release/sbom/manifest.spdx.json
if-no-files-found: error
smoke-test:
runs-on: windows-2022
needs: build
steps:
- uses: actions/download-artifact@v4
with:
name: release-portable
path: smoke
- name: Smoke test
shell: pwsh
run: |
$ErrorActionPreference = "Stop"
$exe = Get-ChildItem "smoke" -Recurse -Filter "ThreadPilot.exe" -File | Select-Object -First 1
if (-not $exe)
{
throw "ThreadPilot.exe not found in smoke-test artifact."
}
$process = Start-Process -FilePath $exe.FullName -ArgumentList "--smoke-test" -Wait -PassThru
if ($process.ExitCode -ne 0)
{
throw "Smoke test failed with exit code $($process.ExitCode)."
}
release:
runs-on: ubuntu-latest
needs:
- build
- smoke-test
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download installer artifact
uses: actions/download-artifact@v4
with:
name: release-installer
path: release-assets/installer
- name: Download packages artifact
uses: actions/download-artifact@v4
with:
name: release-packages
path: release-assets/packages
- name: Download checksums artifact
uses: actions/download-artifact@v4
with:
name: release-checksums
path: release-assets
- name: Download winget manifests
uses: actions/download-artifact@v4
with:
name: winget-manifests
path: winget-manifests
- name: Download SBOM artifact
uses: actions/download-artifact@v4
with:
name: sbom
path: sbom
- name: Validate release assets
shell: bash
run: |
set -euo pipefail
compgen -G "release-assets/installer/*.exe" > /dev/null || { echo "Missing installer executable in release-assets/installer"; exit 1; }
compgen -G "release-assets/packages/*.zip" > /dev/null || { echo "Missing release package zip in release-assets/packages"; exit 1; }
test -f "release-assets/SHA256SUMS.txt" || { echo "Missing release checksums file"; exit 1; }
find "winget-manifests" -type f -name "*.yaml" | grep -q . || { echo "Missing winget manifest yaml files"; exit 1; }
test -f "sbom/manifest.spdx.json" || { echo "Missing SBOM manifest"; exit 1; }
- name: Stage public GitHub release assets
shell: bash
run: |
set -euo pipefail
tag="${{ needs.build.outputs.tag }}"
mkdir -p public-release-assets
cp "release-assets/installer/ThreadPilot_${tag}_Setup.exe" "public-release-assets/ThreadPilot_${tag}_Setup.exe"
cp "release-assets/packages/ThreadPilot_${tag}_Portable.zip" "public-release-assets/ThreadPilot_${tag}_Portable.zip"
cp "release-assets/SHA256SUMS.txt" "public-release-assets/SHA256SUMS.txt"
expected_count=3
actual_count="$(find public-release-assets -maxdepth 1 -type f | wc -l | tr -d ' ')"
if [ "$actual_count" != "$expected_count" ]; then
echo "Expected $expected_count public release asset files, found $actual_count."
find public-release-assets -maxdepth 1 -type f -print
exit 1
fi
- name: Install git-cliff
uses: taiki-e/install-action@v2
with:
tool: git-cliff@2.10.0
- name: Generate changelog
id: git-cliff
shell: bash
run: |
set -euo pipefail
git-cliff --config cliff.toml --latest > release-notes.md
{
echo "content<<EOF"
cat release-notes.md
echo "EOF"
} >> "$GITHUB_OUTPUT"
- name: Contributors file check (manual maintenance mode)
shell: pwsh
run: |
if (-not (Test-Path "CONTRIBUTORS.md")) {
throw "CONTRIBUTORS.md not found."
}
Write-Host "CONTRIBUTORS.md is maintained manually in this workflow."
- name: Publish GitHub release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ needs.build.outputs.tag }}
name: ThreadPilot ${{ needs.build.outputs.tag }}
body: ${{ steps.git-cliff.outputs.content }}
files: |
public-release-assets/ThreadPilot_${{ needs.build.outputs.tag }}_Setup.exe
public-release-assets/ThreadPilot_${{ needs.build.outputs.tag }}_Portable.zip
public-release-assets/SHA256SUMS.txt
generate_release_notes: true
publish-winget:
runs-on: windows-2022
needs:
- build
- release
if: needs.release.result == 'success'
steps:
- name: Resolve winget publish policy
id: policy
shell: pwsh
run: |
$ErrorActionPreference = "Stop"
$dryRun = "${{ github.event_name }}" -eq "workflow_dispatch" -and "${{ github.event.inputs.dry_run_publish }}" -eq "true"
"dry_run=$($dryRun.ToString().ToLowerInvariant())" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
- name: Check winget publish policy
id: gate
shell: pwsh
env:
WINGET_GITHUB_TOKEN: ${{ secrets.WINGET_GITHUB_TOKEN }}
WINGET_FORK_OWNER: ${{ secrets.WINGET_FORK_OWNER }}
run: |
$ErrorActionPreference = "Stop"
$logsDir = "release-channel-logs"
New-Item -ItemType Directory -Force -Path $logsDir | Out-Null
$logPath = Join-Path $logsDir "winget-submit-log.txt"
$dryRun = "${{ steps.policy.outputs.dry_run }}" -eq "true"
if ($dryRun)
{
$summary = @(
"## winget publish",
"- attempted: false",
"- version: ${{ needs.build.outputs.version }}",
"- result: dry-run",
"- reason: workflow_dispatch requested dry_run_publish=true"
)
$summary | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8 -Append
"Dry run requested. Winget submission intentionally skipped." | Set-Content -Path $logPath -Encoding utf8
"enabled=false" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
exit 0
}
if ([string]::IsNullOrWhiteSpace($env:WINGET_GITHUB_TOKEN) -or [string]::IsNullOrWhiteSpace($env:WINGET_FORK_OWNER))
{
$message = "Winget publish secrets are missing. Refusing to report a green public release without a submission attempt."
$summary = @(
"## winget publish",
"- attempted: false",
"- version: ${{ needs.build.outputs.version }}",
"- result: failed-policy",
"- reason: missing WINGET_GITHUB_TOKEN and/or WINGET_FORK_OWNER"
)
$summary | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8 -Append
$message | Set-Content -Path $logPath -Encoding utf8
throw $message
}
"enabled=true" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
- name: Checkout
if: steps.gate.outputs.enabled == 'true'
uses: actions/checkout@v4
- name: Download winget manifests
if: steps.gate.outputs.enabled == 'true'
uses: actions/download-artifact@v4
with:
name: winget-manifests
path: winget-manifests
- name: Submit winget PR
if: steps.gate.outputs.enabled == 'true'
shell: pwsh
env:
WINGET_GITHUB_TOKEN: ${{ secrets.WINGET_GITHUB_TOKEN }}
WINGET_FORK_OWNER: ${{ secrets.WINGET_FORK_OWNER }}
run: |
$ErrorActionPreference = "Stop"
$logsDir = "release-channel-logs"
New-Item -ItemType Directory -Force -Path $logsDir | Out-Null
$logPath = Join-Path $logsDir "winget-submit-log.txt"
try
{
& ./build/submit-winget-pr.ps1 `
-Version "${{ needs.build.outputs.version }}" `
-ManifestSourcePath "winget-manifests" `
-ForkOwner "$env:WINGET_FORK_OWNER" `
-RepositoryOwner "PrimeBuild" `
-PackageIdentifier "PrimeBuild.ThreadPilot" `
-GithubToken "$env:WINGET_GITHUB_TOKEN" *>&1 | Tee-Object -FilePath $logPath
if ($LASTEXITCODE -ne 0)
{
throw "submit-winget-pr.ps1 exited with code $LASTEXITCODE"
}
@(
"## winget publish",
"- attempted: true",
"- version: ${{ needs.build.outputs.version }}",
"- result: submitted"
) | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8 -Append
}
catch
{
@(
"## winget publish",
"- attempted: true",
"- version: ${{ needs.build.outputs.version }}",
"- result: failed"
) | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8 -Append
throw
}
- name: Upload winget publish logs
if: always()
uses: actions/upload-artifact@v4
with:
name: winget-publish-logs
path: release-channel-logs/winget-submit-log.txt
if-no-files-found: error