Repository navigation
220 lines (194 loc) · 9.61 KB
/
Copy pathbuild.yml
File metadata and controls
220 lines (194 loc) · 9.61 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
name: Build and release
# StreamerKit is a WinUI 3 desktop app, so this only ever runs on a Windows runner —
# the Windows App SDK targets do not exist on linux or macOS.
#
# Every push to main refreshes a rolling "latest" prerelease, so there is always something
# downloadable without anyone having to do anything. Pushing a v* tag cuts a permanent
# release instead. Pull requests build and get checked, but never publish a release.
on:
push:
branches: [main, master]
tags: ['v*']
pull_request:
branches: [main, master]
workflow_dispatch:
# Needed to create releases and upload assets.
permissions:
contents: write
# Every one of these is prefixed SK_ on purpose. MSBuild reads environment variables as
# properties, so a plain VERSION becomes $(Version) and restore dies with
# "'latest-7331b54' is not a valid version string" before any of this workflow's own logic
# runs. CONFIGURATION would silently become $(Configuration) the same way. Prefixing keeps
# them out of MSBuild's namespace entirely.
env:
SK_PROJECT: LauncherWinUI/LauncherWinUI.csproj
SK_CONFIG: Release
jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # release notes are generated from commit history
# global.json pins this to the 9.0 SDK. Without it the runner uses whatever newest SDK
# it happens to ship with (10.0.302 at time of writing) regardless of what is requested
# here, which is not what the app is developed against.
- name: Set up .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '9.0.x'
- name: Show the SDK actually in use
shell: pwsh
run: dotnet --version
# There is no lock file, so the key is the project file: the only place package
# versions are declared.
- name: Cache NuGet packages
uses: actions/cache@v4
with:
path: ~/.nuget/packages
key: nuget-${{ runner.os }}-${{ hashFiles('LauncherWinUI/LauncherWinUI.csproj') }}
restore-keys: nuget-${{ runner.os }}-
- name: Work out the version
shell: pwsh
run: |
if ($env:GITHUB_REF -like 'refs/tags/v*') {
$tag = $env:GITHUB_REF -replace '^refs/tags/', ''
$name = $tag -replace '^v', ''
$rolling = 'false'
} else {
# A rolling release keeps one tag and moves it, so main always has a download
# without filling the releases page with an entry per commit.
$tag = 'latest'
$name = "latest-$($env:GITHUB_SHA.Substring(0,7))"
$rolling = 'true'
}
Write-Host "tag=$tag name=$name rolling=$rolling"
"SK_TAG=$tag" | Out-File $env:GITHUB_ENV -Append -Encoding utf8
"SK_NAME=$name" | Out-File $env:GITHUB_ENV -Append -Encoding utf8
"SK_ROLLING=$rolling" | Out-File $env:GITHUB_ENV -Append -Encoding utf8
- name: Restore
run: dotnet restore $env:SK_PROJECT
shell: pwsh
- name: Build
run: dotnet build $env:SK_PROJECT -c $env:SK_CONFIG --no-restore
shell: pwsh
# Two builds, because they suit different people and the project cannot be both at once.
#
# The framework-dependent one is the project's own configuration (~37 MB) and needs
# .NET 9 Desktop and Windows App Runtime 1.8 already installed. The self-contained one
# carries both (~213 MB) and runs on a machine with neither. Overriding on the command
# line rather than in the csproj keeps local publishes exactly as they were.
#
# Deliberately not --no-build: publish runs the MSIX-tooling targets that copy the
# compiled XAML and StreamerKit.pri into the output, and reusing a plain build's output
# risks skipping exactly the step the check below exists to catch.
# This one matches the properties the restore step already ran with, so --no-restore
# is safe here.
- name: Publish (needs the runtimes installed)
shell: pwsh
run: dotnet publish $env:SK_PROJECT -c $env:SK_CONFIG -o publish/framework-dependent --no-restore
# This one must NOT say --no-restore. SelfContained changes which packages are needed:
# the earlier restore ran with the project's default of false, so the win-x64 runtime
# pack was never downloaded and publish fails with NETSDK1112. Flipping the property at
# publish time only works if restore sees it too.
- name: Publish (self-contained)
shell: pwsh
run: >
dotnet publish $env:SK_PROJECT -c $env:SK_CONFIG -o publish/self-contained
-p:SelfContained=true -p:WindowsAppSDKSelfContained=true
# The bug this repo has hit hardest: with EnableMsixTooling false, publish silently
# omits StreamerKit.pri and the app dies instantly with 0xC000027B — which looks exactly
# like a missing runtime. The build stays green while the output is broken, so it is
# worth asserting rather than trusting, and doubly so when the output is a download.
- name: Check both builds are complete
shell: pwsh
run: |
$required = @(
'StreamerKit.exe', 'StreamerKit.dll', 'StreamerKit.pri',
'Microsoft.WindowsAppRuntime.Bootstrap.dll',
'servers.json', 'platforms.json', 'integrations.json',
'plugins.json', 'actions.json', 'icons.json'
)
$failed = $false
foreach ($dir in 'publish/framework-dependent', 'publish/self-contained') {
$missing = $required | Where-Object { -not (Test-Path (Join-Path $dir $_)) }
if ($missing) {
$failed = $true
Write-Host "::error::$dir is incomplete."
$missing | ForEach-Object { Write-Host "::error:: missing $_" }
} else {
$files = Get-ChildItem $dir -Recurse -File
$size = [math]::Round(($files | Measure-Object Length -Sum).Sum / 1MB, 1)
Write-Host "$dir ok: $($files.Count) files, $size MB"
}
}
if ($failed) {
Write-Host 'If StreamerKit.pri is missing, check that EnableMsixTooling is still true in the csproj.'
exit 1
}
- name: Zip them
shell: pwsh
run: |
New-Item -ItemType Directory -Force dist | Out-Null
Compress-Archive -Path 'publish/framework-dependent/*' `
-DestinationPath "dist/StreamerKit-$env:SK_NAME-win-x64.zip"
Compress-Archive -Path 'publish/self-contained/*' `
-DestinationPath "dist/StreamerKit-$env:SK_NAME-win-x64-self-contained.zip"
Get-ChildItem dist | ForEach-Object {
Write-Host ("{0} {1} MB" -f $_.Name, [math]::Round($_.Length / 1MB, 1)) }
# Kept even for pull requests, where no release is published, so a PR build is still
# downloadable for testing.
- name: Upload as a workflow artifact
uses: actions/upload-artifact@v4
with:
name: StreamerKit-${{ env.SK_NAME }}
path: dist/
if-no-files-found: error
retention-days: 14
# Recreated rather than updated: moving a rolling tag and clobbering assets in place is
# fiddly and leaves stale files behind when a name changes. A versioned tag is only ever
# created once, so this does nothing for it.
- name: Clear the previous rolling release
if: env.SK_ROLLING == 'true' && github.event_name != 'pull_request'
shell: pwsh
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release delete $env:SK_TAG --yes --cleanup-tag 2>$null
Write-Host 'Previous rolling release cleared (if there was one).'
exit 0
- name: Publish the release
if: github.event_name != 'pull_request'
shell: pwsh
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
$notes = @"
**Which download do I want?**
| File | Download | Unzipped | Needs |
|---|---|---|---|
| ``StreamerKit-$env:SK_NAME-win-x64-self-contained.zip`` | ~86 MB | ~213 MB | Nothing. Unzip and run. |
| ``StreamerKit-$env:SK_NAME-win-x64.zip`` | ~11 MB | ~38 MB | .NET 9 Desktop Runtime and Windows App Runtime 1.8 |
If you are not sure, take the self-contained one.
Unzip somewhere writable and run ``StreamerKit.exe`` — settings, servers and actions
are read from JSON files next to it. Windows will warn about an unsigned app;
these builds are not code-signed.
Built from ``$env:GITHUB_SHA``.
"@
$notesFile = Join-Path $env:RUNNER_TEMP 'notes.md'
$notes | Out-File $notesFile -Encoding utf8
$argList = @('release', 'create', $env:SK_TAG,
'--target', $env:GITHUB_SHA,
'--notes-file', $notesFile)
# Only --notes-file, never alongside --generate-notes: whether gh accepts both
# together varies by version, and a release step that fails on a flag combination
# is a poor way to find out. To get the commit list on tagged releases as well,
# add --generate-notes here and check it against the gh on the runner first.
if ($env:SK_ROLLING -eq 'true') {
$argList += @('--title', 'StreamerKit (latest from main)', '--prerelease')
} else {
$argList += @('--title', "StreamerKit $env:SK_TAG")
}
$argList += (Get-ChildItem dist | ForEach-Object { $_.FullName })
& gh $argList
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }