-
Notifications
You must be signed in to change notification settings - Fork 35
362 lines (309 loc) · 11 KB
/
Copy pathpackage.yml
File metadata and controls
362 lines (309 loc) · 11 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
name: Package
on:
pull_request:
branches: [ main ]
paths:
- '.github/workflows/package.yml'
- 'nuget/**'
- 'scripts/nuget/**'
- 'CMakeLists.txt'
- 'LICENSE'
- 'README.md'
- 'build.bat'
- 'build_all.bat'
- 'cmake/**'
- 'docs/**'
- 'include/**'
- 'src/**'
- 'test/**'
push:
branches: [ main ]
tags:
- 'v*'
paths:
- '.github/workflows/package.yml'
- 'nuget/**'
- 'scripts/nuget/**'
- 'CMakeLists.txt'
- 'LICENSE'
- 'README.md'
- 'build.bat'
- 'build_all.bat'
- 'cmake/**'
- 'docs/**'
- 'include/**'
- 'src/**'
- 'test/**'
workflow_dispatch:
inputs:
package_version:
description: Optional package version override
required: false
type: string
publish:
description: Publish the generated package to nuget.org
required: true
type: boolean
default: false
github_release:
description: Upload release assets to GitHub Releases
required: true
type: boolean
default: false
permissions:
contents: read
jobs:
version:
name: Resolve package version
runs-on: windows-2022
outputs:
package_version: ${{ steps.version.outputs.package_version }}
steps:
- uses: actions/checkout@v5
- name: Resolve package version
id: version
shell: pwsh
run: |
$version = '${{ inputs.package_version }}'
if ([string]::IsNullOrWhiteSpace($version)) {
$version = ./scripts/nuget/Get-CrtSysVersion.ps1
}
if ($env:GITHUB_REF_TYPE -eq 'tag') {
if ($env:GITHUB_REF_NAME -notmatch '^v(.+)$') {
throw "Release tag must use v<version> format."
}
$tagVersion = $Matches[1]
if ($version -ne $tagVersion) {
throw "Package version '$version' does not match tag version '$tagVersion'."
}
}
"package_version=$version" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
Write-Host "Package version: $version"
build-libs:
name: Build NuGet libs ${{ matrix.arch }} ${{ matrix.config }}
needs: version
runs-on: windows-2022
strategy:
fail-fast: false
matrix:
arch: [x64, ARM64]
config: [Debug, Release]
steps:
- uses: actions/checkout@v5
- name: Build prebuilt libraries
shell: pwsh
run: >
./scripts/nuget/Build-CrtSysNuGetLibs.ps1
-Architecture '${{ matrix.arch }}'
-Configuration '${{ matrix.config }}'
-WindowsSdkVersion '10.0.22621.0'
- uses: actions/upload-artifact@v7
with:
name: crtsys-nuget-libs-${{ matrix.arch }}-${{ matrix.config }}
path: artifacts/nuget-staging/lib/native/${{ matrix.arch }}/${{ matrix.config }}
if-no-files-found: error
pack:
name: Pack NuGet
needs: [version, build-libs]
runs-on: windows-2022
outputs:
package_version: ${{ steps.version.outputs.package_version }}
steps:
- uses: actions/checkout@v5
- name: Set package version
id: version
shell: pwsh
run: |
"package_version=${{ needs.version.outputs.package_version }}" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
- uses: actions/setup-dotnet@v5
with:
dotnet-version: '10.0.x'
- uses: NuGet/setup-nuget@v2
- uses: actions/download-artifact@v7
with:
name: crtsys-nuget-libs-x64-Debug
path: artifacts/nuget-staging/lib/native/x64/Debug
- uses: actions/download-artifact@v7
with:
name: crtsys-nuget-libs-x64-Release
path: artifacts/nuget-staging/lib/native/x64/Release
- uses: actions/download-artifact@v7
with:
name: crtsys-nuget-libs-ARM64-Debug
path: artifacts/nuget-staging/lib/native/ARM64/Debug
- uses: actions/download-artifact@v7
with:
name: crtsys-nuget-libs-ARM64-Release
path: artifacts/nuget-staging/lib/native/ARM64/Release
- name: Pack
shell: pwsh
run: ./scripts/nuget/Pack-CrtSysNuGet.ps1 -Version '${{ steps.version.outputs.package_version }}'
- name: Pack GitHub release assets
shell: pwsh
run: ./scripts/nuget/Pack-CrtSysReleaseAssets.ps1 -Version '${{ steps.version.outputs.package_version }}'
- uses: actions/upload-artifact@v7
with:
name: crtsys-nuget-${{ steps.version.outputs.package_version }}
path: artifacts/nuget/*.nupkg
if-no-files-found: error
- uses: actions/upload-artifact@v7
with:
name: crtsys-release-assets-${{ steps.version.outputs.package_version }}
path: artifacts/release/*
if-no-files-found: error
test-package-driver:
name: Test NuGet driver package ${{ matrix.arch }} ${{ matrix.config }}
needs: pack
runs-on: windows-2022
strategy:
fail-fast: false
matrix:
arch: [x64, ARM64]
config: [Debug, Release]
steps:
- uses: actions/checkout@v5
- uses: NuGet/setup-nuget@v2
- uses: actions/download-artifact@v7
with:
name: crtsys-nuget-${{ needs.pack.outputs.package_version }}
path: artifacts/nuget
- name: Build package consumer test driver
shell: pwsh
run: >
./scripts/nuget/Test-CrtSysNuGetPackage.ps1
-PackageDirectory artifacts/nuget
-Version '${{ needs.pack.outputs.package_version }}'
-Consumer Driver
-Architecture '${{ matrix.arch }}'
-Configuration '${{ matrix.config }}'
-WindowsSdkVersion '10.0.22621.0'
test-package-app:
name: Test NuGet app package ${{ matrix.arch }} ${{ matrix.config }}
needs: pack
runs-on: windows-2022
strategy:
fail-fast: false
matrix:
arch: [x86, x64, ARM64]
config: [Debug, Release]
steps:
- uses: actions/checkout@v5
- uses: NuGet/setup-nuget@v2
- uses: actions/download-artifact@v7
with:
name: crtsys-nuget-${{ needs.pack.outputs.package_version }}
path: artifacts/nuget
- name: Build package app consumer test
shell: pwsh
run: >
./scripts/nuget/Test-CrtSysNuGetPackage.ps1
-PackageDirectory artifacts/nuget
-Version '${{ needs.pack.outputs.package_version }}'
-Consumer App
-Architecture '${{ matrix.arch }}'
-Configuration '${{ matrix.config }}'
-WindowsSdkVersion '10.0.22621.0'
test-release-prebuilt-cmake:
name: Test release prebuilt CMake asset ${{ matrix.arch }} ${{ matrix.config }}
needs: pack
runs-on: windows-2022
strategy:
fail-fast: false
matrix:
arch: [x64, ARM64]
config: [Debug, Release]
steps:
- uses: actions/checkout@v5
- uses: actions/download-artifact@v7
with:
name: crtsys-release-assets-${{ needs.pack.outputs.package_version }}
path: artifacts/release
- name: Build prebuilt release CMake consumer test
shell: pwsh
run: >
./scripts/nuget/Test-CrtSysReleaseAssets.ps1
-ReleaseDirectory artifacts/release
-Version '${{ needs.pack.outputs.package_version }}'
-Architecture '${{ matrix.arch }}'
-Configuration '${{ matrix.config }}'
-WindowsSdkVersion '10.0.22621.0'
publish:
name: Publish NuGet
needs: [pack, test-package-driver, test-package-app]
if: ${{ (github.event_name != 'workflow_dispatch' && startsWith(github.ref, 'refs/tags/v')) || (github.event_name == 'workflow_dispatch' && inputs.publish) }}
runs-on: windows-2022
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v5
- uses: actions/setup-dotnet@v5
with:
dotnet-version: '10.0.x'
- uses: actions/download-artifact@v7
with:
name: crtsys-nuget-${{ needs.pack.outputs.package_version }}
path: artifacts/nuget
- name: Validate NuGet trusted publishing user
shell: pwsh
run: |
if ([string]::IsNullOrWhiteSpace('${{ vars.NUGET_TRUSTED_PUBLISHING_USER }}')) {
throw 'Repository variable NUGET_TRUSTED_PUBLISHING_USER is required for NuGet Trusted Publishing.'
}
- name: NuGet login
uses: NuGet/login@v1
id: nuget-login
with:
user: ${{ vars.NUGET_TRUSTED_PUBLISHING_USER }}
- name: Publish to nuget.org
shell: pwsh
env:
NUGET_API_KEY: ${{ steps.nuget-login.outputs.NUGET_API_KEY }}
run: ./scripts/nuget/Push-CrtSysNuGet.ps1 -SkipDuplicate
github-release:
name: Upload GitHub Release Assets
needs: [pack, test-package-driver, test-package-app, test-release-prebuilt-cmake]
if: ${{ (github.event_name != 'workflow_dispatch' && startsWith(github.ref, 'refs/tags/v')) || (github.event_name == 'workflow_dispatch' && inputs.github_release) }}
runs-on: windows-2022
permissions:
contents: write
steps:
- uses: actions/checkout@v5
- uses: actions/download-artifact@v7
with:
name: crtsys-release-assets-${{ needs.pack.outputs.package_version }}
path: artifacts/release
- name: Create or update GitHub release
shell: pwsh
env:
GH_TOKEN: ${{ github.token }}
run: |
Set-Location '${{ github.workspace }}'
$version = '${{ needs.pack.outputs.package_version }}'
$tagName = "v$version"
if ('${{ github.ref_type }}' -eq 'tag') {
$tagName = '${{ github.ref_name }}'
}
$repo = '${{ github.repository }}'
$assets = @(Get-ChildItem -Path artifacts\release -File | Sort-Object FullName | ForEach-Object { $_.FullName })
if ($assets.Count -eq 0) {
throw 'No GitHub Release assets were found.'
}
& gh release view $tagName --repo $repo *> $null
if ($LASTEXITCODE -eq 0) {
Write-Host "Uploading assets to existing GitHub Release $tagName"
& gh release upload $tagName @assets --repo $repo --clobber
} else {
Write-Host "Creating GitHub Release $tagName"
$notes = @(
"crtsys $version release assets."
""
"- crtsys.$version.nupkg: offline NuGet package"
"- crtsys-$version-prebuilt.zip: headers, docs, CMake helpers/package config, native MSBuild imports, and prebuilt x64/ARM64 Debug/Release libraries"
"- crtsys-$version-SHA256SUMS.txt: SHA-256 checksums"
) -join [Environment]::NewLine
& gh release create $tagName @assets --repo $repo --target '${{ github.sha }}' --title "crtsys $version" --notes $notes
}
if ($LASTEXITCODE -ne 0) {
throw "GitHub Release upload failed with exit code $LASTEXITCODE."
}