-
Notifications
You must be signed in to change notification settings - Fork 122
400 lines (346 loc) · 15.1 KB
/
ci.yml
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
name: CI
on:
workflow_dispatch: # Allows you to run this workflow manually from the Actions tab
push:
paths-ignore:
- '.github/workflows/deploy-site.yml'
- 'Docs/**'
- 'Site/**'
pull_request:
paths-ignore:
- '.github/workflows/deploy-site.yml'
- 'Docs/**'
- 'Site/**'
schedule:
# Run daily at 00:00 so we get notified if CI is broken before a pull request
# is submitted.
- cron: '0 0 * * *'
env:
DOTNET_NOLOGO: true
jobs:
# Check some basic style rules.
check-style:
# Do not run this job for pull requests where both branches are from the same repo.
# Jobs that depend on this one will be skipped too.
# This prevents duplicate CI runs for our own pull requests, whilst preserving the ability to
# run the CI for each branch push to a fork, and for each pull request originating from a fork.
if: github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' || github.event_name == 'push' || github.event.pull_request.head.repo.id != github.event.pull_request.base.repo.id
needs:
- check-style-line-lengths
- check-style-line-endings
- check-style-copyright-headers
runs-on: ubuntu-latest
steps:
- run: echo "All style checks done"
check-style-line-lengths:
if: github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' || github.event_name == 'push' || github.event.pull_request.head.repo.id != github.event.pull_request.base.repo.id
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Check line length
run: .github/workflows/Scripts/CheckLineLength.ps1 -path Src
check-style-line-endings:
if: github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' || github.event_name == 'push' || github.event.pull_request.head.repo.id != github.event.pull_request.base.repo.id
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Check T4 line endings
run: .github/workflows/Scripts/CheckT4LineEndings.ps1 -path Src
check-style-copyright-headers:
if: github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' || github.event_name == 'push' || github.event.pull_request.head.repo.id != github.event.pull_request.base.repo.id
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup the latest .NET 7 SDK
uses: actions/[email protected]
with:
dotnet-version: 7.0.x
- name: Check Copyright Headers
run: |
dotnet run --configuration=Release -p:TreatWarningsAsErrors=true --project Tools/CopyrightUpdateTool
if [[ -z "$(git status --porcelain)" ]]; then
exit 0
else
git status --porcelain
exit 1
fi
# Setup the OS matrix so that CUDA tests do not run on forks, as it needs self-hosted runners.
# Skip running on macOS in most cases.
setup-os-matrix:
# Do not run this job for pull requests where both branches are from the same repo.
# Jobs that depend on this one will be skipped too.
# This prevents duplicate CI runs for our own pull requests, whilst preserving the ability to
# run the CI for each branch push to a fork, and for each pull request originating from a fork.
if: github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' || github.event_name == 'push' || github.event.pull_request.head.repo.id != github.event.pull_request.base.repo.id
runs-on: ubuntu-latest
steps:
- name: Check if repo is fork
id: is-fork
run: echo "fork=$(gh api repos/${{ github.repository }} | jq .fork)" >> $GITHUB_OUTPUT
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Setup OS matrix
id: setup-os-matrix
run: |
os=("ubuntu-latest" "windows-latest")
# runs on macOS only if there is a push to master, or a tag is
# pushed, we do this since macOS builds last too long and ILGPU
# is rarely used on a macOS
(
[ "${{ github.event_name }}" == "workflow_dispatch" ] ||
[ "${{ github.event_name }}" == "schedule" ] ||
(
[ "${{ github.event_name }}" == "push" ] &&
(
[ "${{ github.ref }}" == "refs/heads/master" ] ||
[[ "${{ github.ref }}" =~ "refs/tags/v" ]]
)
)
) && os+=("macos-latest")
# Temporarily disabled cuda
# [ "${{ steps.is-fork.outputs.fork }}" == "false" ] && os+=("cuda")
echo "os=$(jq -cn '$ARGS.positional' --args ${os[@]})" >> $GITHUB_OUTPUT
outputs:
os: ${{ steps.setup-os-matrix.outputs.os }}
# Check that building the entire solution for all target frameworks works.
build:
# Do not run this job for pull requests where both branches are from the same repo.
# Jobs that depend on this one will be skipped too.
# This prevents duplicate CI runs for our own pull requests, whilst preserving the ability to
# run the CI for each branch push to a fork, and for each pull request originating from a fork.
if: github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' || github.event_name == 'push' || github.event.pull_request.head.repo.id != github.event.pull_request.base.repo.id
runs-on: windows-latest
strategy:
matrix:
path: [Src, Samples]
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup the latest .NET 7 SDK
uses: actions/[email protected]
with:
dotnet-version: 7.0.x
- name: Build
run: dotnet build ${{ matrix.path }} --configuration=Release -p:TreatWarningsAsErrors=true
# Run tests for all supported combinations of OS/library/framework.
test-library:
needs: setup-os-matrix
strategy:
matrix:
os: ${{ fromJson(needs.setup-os-matrix.outputs.os) }}
library: [ILGPU, ILGPU.Algorithms]
framework: [netcoreapp3.1, net5.0, net6.0, net7.0]
include:
- os: windows-latest
library: ILGPU
framework: net471
- os: windows-latest
library: ILGPU.Algorithms
framework: net471
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup the latest .NET Core 3.1 SDK
if: matrix.framework == 'netcoreapp3.1'
uses: actions/[email protected]
with:
dotnet-version: 3.1.x
- name: Setup the latest .NET 5 SDK
if: matrix.framework == 'net5.0'
uses: actions/[email protected]
with:
dotnet-version: 5.0.x
- name: Setup the latest .NET 6 SDK
if: matrix.framework == 'net6.0'
uses: actions/[email protected]
with:
dotnet-version: 6.0.x
- name: Setup the latest .NET 7 SDK
uses: actions/[email protected]
with:
dotnet-version: 7.0.x
- name: Set test flavor
id: test-flavor
shell: bash
run: echo "flavor=$([[ "${{ matrix.os }}" == cuda ]] && echo "Cuda" || echo "CPU")" >> $GITHUB_OUTPUT
- name: Build and test
run: dotnet test Src/${{ matrix.library }}.Tests.${{ steps.test-flavor.outputs.flavor }} --configuration=Release --framework=${{ matrix.framework }} -p:TreatWarningsAsErrors=true
env:
ILGPU_CLEAN_TESTS: ${{ github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' || (github.event_name == 'push' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v'))) }}
# Ensure that ILGPU libraries are built using the same version tag.
check-version:
# Do not run this job for pull requests where both branches are from the same repo.
# Jobs that depend on this one will be skipped too.
# This prevents duplicate CI runs for our own pull requests, whilst preserving the ability to
# run the CI for each branch push to a fork, and for each pull request originating from a fork.
if: github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' || github.event_name == 'push' || github.event.pull_request.head.repo.id != github.event.pull_request.base.repo.id
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Check version
id: version
shell: pwsh
run: |
$xpath = "/Project/PropertyGroup/LibraryVersionPrefix/text()"
$main_version = (Select-Xml -path Src/Directory.Build.props -XPath $xpath).Node.Value
if ("${{ github.ref }}" -like "refs/tags/v*") {
$tag = "${{ github.ref }}".SubString(11)
if (-not ($tag -eq $main_version)) {
echo "::error ::There is a mismatch between the project version ($main_version) and the tag ($tag)"
exit 1
}
}
if (-not ("${{ github.ref }}" -like "refs/tags/v*")) {
$suffix = "preview-$(Get-Date -Format yyyyMMddHHmmss -AsUTC)-$(git rev-parse --short HEAD)"
$main_version = "$main_version-$suffix"
}
echo "version=$main_version" >> $env:GITHUB_OUTPUT
echo "suffix=$suffix" >> $env:GITHUB_OUTPUT
outputs:
version: ${{ steps.version.outputs.version }}
suffix: ${{ steps.version.outputs.suffix }}
# Create the NuGet packages, with fixes for portable symbols.
package-library:
needs: check-version
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup the latest .NET 7 SDK
uses: actions/[email protected]
with:
dotnet-version: 7.0.x
- name: Create NuGet packages
run: |
$suffix = "${{ needs.check-version.outputs.suffix }}"
if ([bool]$suffix) {
$params = "--version-suffix", $suffix
}
dotnet pack Src --configuration=Release @params
- name: Fix NuGet Symbols Packages
run: .github/workflows/Scripts/FixNugetSymbolPackages.ps1 -version "${{ needs.check-version.outputs.version }}"
- name: Upload NuGet package artifacts
uses: actions/upload-artifact@v3
with:
name: nuget-packages
path: ./Bin/Release/ILGPU*.${{ needs.check-version.outputs.version }}.*nupkg
# Create the Samples zip file, replacing ILGPU project references with equivalent NuGet package references.
package-samples:
needs:
- check-version
- package-library
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup the latest .NET 7 SDK
uses: actions/[email protected]
with:
dotnet-version: 7.0.x
# Change the ILGPU project references to NuGet package references
- name: Update sample references
id: package
run: .github/workflows/Scripts/UpdateSampleReferences.ps1 -version "${{ needs.check-version.outputs.version }}" -suffix "${{ needs.check-version.outputs.suffix }}"
# Compress the Samples folder
- name: Compress samples
run: |
$artifactPath = "Samples-${{ needs.check-version.outputs.version }}.zip"
Compress-Archive .\Samples\* -DestinationPath $artifactPath
# Verify that the sample projects can compile after switching to NuGet references
- name: Download NuGet package artifact
uses: actions/download-artifact@v3
with:
name: nuget-packages
path: local-nuget-packages
- name: Compile sample projects
run: |
# Decompress sample projects into temp folder
$tempFolder = Join-Path $env:RUNNER_TEMP "TempSamples"
Expand-Archive "Samples-*.zip" -DestinationPath $tempFolder
# Add local nuget packages
# NB: We use a fully qualified path because relative paths are relative to the
# NuGet.Config file. This could either be the NuGet.Config file in the samples,
# or the global NuGet.Config file (if we did not create one in the samples)
pushd $tempFolder
$repoPath = Resolve-Path (Join-Path $env:GITHUB_WORKSPACE "local-nuget-packages")
dotnet nuget add source $repoPath --name "ILGPU Local NuGet Packages"
# Ensure sample projects can compile
dotnet build --configuration=Release -p:TreatWarningsAsErrors=true
popd
# Upload samples artifact (for version tags and master branch only)
- name: Upload Samples artifact
uses: actions/upload-artifact@v3
if: github.event_name == 'push' && !github.event.repository.fork && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v'))
with:
name: samples
path: ./Samples-*.zip
# Virtual job that can be configured as a required check before a PR can be
# merged.
# As GitHub considers a check as successful if it is skipped, we need to
# check its status in another workflow (check-required.yml) and create a
# check there.
all-required-checks-done:
needs:
- check-style
- build
- test-library
- package-library
- package-samples
runs-on: ubuntu-latest
steps:
- run: echo "All required checks done"
# Publish a preview version of the NuGet packages on feedz.io when there is
# a push to master.
publish-preview:
if: github.event_name == 'push' && github.ref == 'refs/heads/master' && !github.event.repository.fork
needs: all-required-checks-done
runs-on: ubuntu-latest
steps:
- name: Download NuGet package artifact
uses: actions/download-artifact@v3
with:
name: nuget-packages
- name: Publish to FeedzIO
run: dotnet nuget push "*.nupkg" --api-key ${{ secrets.FEEDZIO_API_KEY }} --source https://f.feedz.io/ilgpu/preview/nuget/index.json
# Create a GitHub release and publish the NuGet packages to nuget.org when
# a tag is pushed.
publish-release:
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') && !github.event.repository.fork
# Depends explictly on the 'check-version' job so we can access its output
needs:
- all-required-checks-done
- check-version
runs-on: ubuntu-latest
steps:
- name: Download NuGet package artifact
uses: actions/download-artifact@v3
with:
name: nuget-packages
- name: Download Samples artifact
uses: actions/download-artifact@v3
with:
name: samples
# if tag contains "-" treat it as pre-release
# example: 1.0.0-beta1
- name: Create release
uses: softprops/action-gh-release@v1
with:
name: Release v${{ needs.check-version.outputs.version }}
draft: true
prerelease: ${{ contains(needs.check-version.outputs.version, '-') }}
files: |
*.nupkg
Samples-*.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Publish to NuGet
run: dotnet nuget push "*.nupkg" --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json