-
-
Notifications
You must be signed in to change notification settings - Fork 1
487 lines (440 loc) · 22 KB
/
ClangSharp.Pathogen.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
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
name: ClangSharp.Pathogen
on:
push:
# This prevents tag pushes from triggering this workflow
branches: ['*']
pull_request:
release:
types: [published]
workflow_dispatch:
inputs:
version:
description: "Version"
default: ""
will_publish_packages:
description: "Publish packages?"
default: "false"
env:
DOTNET_NOLOGO: true
DOTNET_CLI_TELEMETRY_OPTOUT: true
DOTNET_GENERATE_ASPNET_CERTIFICATE: false
ContinuousIntegrationBuild: true
jobs:
# =====================================================================================================================================================================
# Build LLVM
# =====================================================================================================================================================================
build-llvm:
strategy:
fail-fast: false
matrix:
include:
- os: windows-2019
name: Windows x64
rid: win-x64
libclang-subpath: bin/libclang.dll
build-command: ./build-native.cmd
# We use Ubuntu 18.04 so that the binary is usable on systems using glibc 2.27 and later
# If we want to support even older versions we should explore building libclang with https://github.com/wheybags/glibc_version_header
- os: ubuntu-18.04
name: Linux x64
rid: linux-x64
libclang-subpath: lib/libclang.so
build-command: ./build-native.sh
- os: ubuntu-arm64-latest
name: Linux ARM64
rid: linux-arm64
libclang-subpath: lib/libclang.so
build-command: ./build-native.sh
skip-python-install: true
- os: macos-12
name: macOS x64
rid: osx-x64
libclang-subpath: lib/libclang.dylib
build-command: ./build-native.sh
name: Build LLVM - ${{matrix.name}}
runs-on: ${{matrix.os}}
steps:
# ----------------------------------------------------------------------- Checkout
- name: Checkout
# We intentionally don't checkout submodules here
# They will be restored as needed only if we need to build LLVM.
uses: actions/checkout@v2
# ----------------------------------------------------------------------- Setup Python
- name: Setup Python 3.8
if: matrix.skip-python-install != true
uses: actions/setup-python@v2
with:
python-version: '3.8'
# ----------------------------------------------------------------------- Get LLVM Revision
- name: Get LLVM Revision
id: llvm
run: python .github/workflows/get-llvm-revision.py
# ----------------------------------------------------------------------- Build LLVM
- name: Load cached LLVM build outputs
id: cached-llvm
uses: actions/cache@v2
# If you change this configuration make sure to update keep-cache-warm.yml as well.
with:
key: llvm-output-${{matrix.rid}}-${{steps.llvm.outputs.revision}}
# These are the paths of the files required by ClangSharp.Pathogen.Native and ClangSharp.Pathogen.ClangResources
# (Make sure this is syncronized with "Archive LLVM Outputs" below)
path: |
bin/llvm/${{matrix.rid}}/${{matrix.libclang-subpath}}
bin/llvm/${{matrix.rid}}/lib/clang/
external/llvm-project/clang/LICENSE.TXT
external/llvm-project/clang/tools/libclang/libClangSharp/LICENSE.md
- name: Checkout LLVM
if: steps.cached-llvm.outputs.cache-hit != 'true'
run: git submodule update --init --recursive --depth=1
- name: Install sccache
id: sccache
if: steps.cached-llvm.outputs.cache-hit != 'true'
run: python .github/workflows/install-sccache.py
- name: Load LLVM sccache
id: cached-sccache
# Always save the (potentially partial) sccache database so it can be used to accelerate subsequent builds when an intermittent failure occurs
if: steps.cached-llvm.outputs.cache-hit != 'true' && always()
uses: actions/cache@v2
# If you change this configuration make sure to update keep-cache-warm.yml as well.
with:
# Note that this implicitly includes the sccache log
# sccache writes a startup message to the log so you'll be able to tell which section of the log is the current run
# (and see any logs from previous runs which affected this cache)
path: ${{steps.sccache.outputs.root-directory}}
key: sccache-cache-${{matrix.rid}}-${{steps.llvm.outputs.revision}}
restore-keys: sccache-cache-${{matrix.rid}}-
- name: Start sccache server
if: steps.cached-llvm.outputs.cache-hit != 'true'
run: sccache --start-server
# The GitHub hosted runners do not have Ninja installed by default
# This is not necessary on Windows since Visual Studio comes with a copy of Ninja and we end up picking that one up for Windows
- name: Install Ninja on Linux
if: steps.cached-llvm.outputs.cache-hit != 'true' && runner.os == 'Linux'
run: sudo apt-get install --yes ninja-build
- name: Install Ninja on macOS
if: steps.cached-llvm.outputs.cache-hit != 'true' && runner.os == 'macOS'
run: brew install ninja
- name: Build LLVM
if: steps.cached-llvm.outputs.cache-hit != 'true'
run: ${{matrix.build-command}}
- name: Show sccache statistics
if: steps.cached-llvm.outputs.cache-hit != 'true' && always()
run: |
sccache --show-stats 2>&1 | tee ${{steps.sccache.outputs.root-directory}}/sccache-stats.txt
# Stop the server so it releases the lock on the log on Windows
# (Without this the sccache cache fails to save.)
sccache --stop-server
- name: Save sccache logs
uses: actions/upload-artifact@v2
if: steps.cached-llvm.outputs.cache-hit != 'true' && always()
with:
name: llvm-${{matrix.rid}}-sccache-logs
path: |
${{steps.sccache.outputs.log-file-path}}
${{steps.sccache.outputs.root-directory}}/sccache-stats.txt
# ----------------------------------------------------------------------- Pack Runtime Packages
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.x
- name: Configure versioning
run: python .github/workflows/configure-build.py
env:
github_event_name: ${{github.event_name}}
github_run_number: ${{github.run_number}}
release_version: ${{github.event.release.tag_name}}
workflow_dispatch_version: ${{github.event.inputs.version}}
# SourceLink will complain about the LLVM submodule missing even though it doesn't need it
# If we didn't clone the LLVM submodule we need to delete .gitmodules so it can chill
# (Workaround for https://github.com/dotnet/sourcelink/issues/675)
- name: Clear .gitmodules
if: steps.cached-llvm.outputs.cache-hit == 'true'
run: rm .gitmodules
- name: Restore ClangSharp.Pathogen.Native
run: dotnet restore ClangSharp.Pathogen.Native
- name: Pack ClangSharp.Pathogen.Native.${{matrix.rid}}
run: dotnet pack ClangSharp.Pathogen.Native --no-build --configuration Release /p:RuntimeIdentifier=${{matrix.rid}}
# The Clang resources are the same across all platforms so we only publish a single package based on the linux-x64 build
- name: Pack ClangSharp.Pathogen.ClangResources
if: matrix.rid == 'linux-x64'
run: |
dotnet restore ClangSharp.Pathogen.ClangResources
dotnet pack ClangSharp.Pathogen.ClangResources --no-build --configuration Release
# ----------------------------------------------------------------------- Upload Artifacts
# The GitHub Actions cache gets confused by the symlink so we need to remove it
- name: Unsymlink libclang
if: steps.cached-llvm.outputs.cache-hit != 'true' && runner.os == 'Linux'
run: |
cp bin/llvm/${{matrix.rid}}/${{matrix.libclang-subpath}} bin/llvm/${{matrix.rid}}/${{matrix.libclang-subpath}}-nosymlink
rm bin/llvm/${{matrix.rid}}/${{matrix.libclang-subpath}}
mv bin/llvm/${{matrix.rid}}/${{matrix.libclang-subpath}}-nosymlink bin/llvm/${{matrix.rid}}/${{matrix.libclang-subpath}}
- name: Collect Build Outputs
uses: actions/upload-artifact@v2
# We always want to collect any build outputs that were created even if building failed
if: always()
with:
name: llvm-${{matrix.rid}}
if-no-files-found: error
# The paths listed here must match "Load cached LLVM build outputs" above
path: |
bin/llvm/${{matrix.rid}}/${{matrix.libclang-subpath}}
bin/llvm/${{matrix.rid}}/lib/clang/
external/llvm-project/clang/LICENSE.TXT
external/llvm-project/clang/tools/libclang/libClangSharp/LICENSE.md
- name: Collect NuGet Packages
uses: actions/upload-artifact@v2
# We always want to collect any packages that were created even if building failed
if: always()
with:
name: llvm-${{matrix.rid}}-packages
if-no-files-found: error
path: packages/**
# =====================================================================================================================================================================
# Build ClangSharp.Pathogen
# =====================================================================================================================================================================
build-dotnet:
name: Build ClangSharp.Pathogen
runs-on: ubuntu-latest
steps:
# ----------------------------------------------------------------------- Checkout
- name: Checkout
uses: actions/checkout@v2
# SourceLink will complain about the LLVM submodule missing even though it doesn't need it
# If we didn't clone the LLVM submodule we need to delete .gitmodules so it can chill
# (Workaround for https://github.com/dotnet/sourcelink/issues/675)
- name: Clear .gitmodules
run: rm .gitmodules
# ----------------------------------------------------------------------- Setup Python
- name: Setup Python 3.8
uses: actions/setup-python@v2
with:
python-version: '3.8'
# ----------------------------------------------------------------------- Setup .NET
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.x
# ----------------------------------------------------------------------- Configure Versioning
- name: Configure build
run: python .github/workflows/configure-build.py
env:
github_event_name: ${{github.event_name}}
github_run_number: ${{github.run_number}}
release_version: ${{github.event.release.tag_name}}
workflow_dispatch_version: ${{github.event.inputs.version}}
# ----------------------------------------------------------------------- Build and Pack ClangSharp.Pathogen
- name: Restore
run: dotnet restore ClangSharp.Pathogen
- name: Build
run: dotnet build ClangSharp.Pathogen --no-restore --configuration Release
- name: Pack
id: pack
run: dotnet pack ClangSharp.Pathogen --no-build --configuration Release
# ----------------------------------------------------------------------- Collect Artifacts
- name: Collect Build Outputs
uses: actions/upload-artifact@v2
# We always want to collect any build outputs that were created even if building failed
if: always()
with:
name: ClangSharp.Pathogen-build-output
path: |
bin/**
obj/**
- name: Collect NuGet Packages
uses: actions/upload-artifact@v2
# We always want to collect packages when they were produced
if: steps.pack.outcome == 'success' && always()
with:
name: ClangSharp.Pathogen-packages
if-no-files-found: error
path: packages/**
# =====================================================================================================================================================================
# Coalesce Packages
# =====================================================================================================================================================================
coalesce-packages:
name: Coalesce Packages
runs-on: ubuntu-latest
needs: [build-llvm, build-dotnet]
steps:
# ----------------------------------------------------------------------- Download Packages
- name: Download LLVM Windows x64 packages
uses: actions/download-artifact@v2
with:
name: llvm-win-x64-packages
- name: Download LLVM Linux x64 packages
uses: actions/download-artifact@v2
with:
name: llvm-linux-x64-packages
- name: Download LLVM Linux ARM64 packages
uses: actions/download-artifact@v2
with:
name: llvm-linux-arm64-packages
- name: Download LLVM macOS x64 packages
uses: actions/download-artifact@v2
with:
name: llvm-osx-x64-packages
- name: Download ClangSharp.Pathogen packages
uses: actions/download-artifact@v2
with:
name: ClangSharp.Pathogen-packages
# ----------------------------------------------------------------------- Upload Combined Packages Artifact
- name: Collect NuGet Packages
uses: actions/upload-artifact@v2
with:
name: Packages
if-no-files-found: error
path: '**'
# =====================================================================================================================================================================
# Verify Clang Resources Match
# =====================================================================================================================================================================
# We only use the linux-x64 build to publish ClangSharp.Pathogen.ClangResources, so we want to ensure they match across all builds
verify-clang-resources:
name: Verify Clang Resources
runs-on: ubuntu-latest
needs: build-llvm
steps:
# ----------------------------------------------------------------------- Download LLVM Build Outputs
- name: Download LLVM Windows x64 build output
if: always()
uses: actions/download-artifact@v2
with:
name: llvm-win-x64
- name: Download LLVM Linux x64 build output
if: always()
uses: actions/download-artifact@v2
with:
name: llvm-linux-x64
- name: Download LLVM Linux ARM64 build output
if: always()
uses: actions/download-artifact@v2
with:
name: llvm-linux-arm64
- name: Download LLVM macOS x64 build output
if: always()
uses: actions/download-artifact@v2
with:
name: llvm-osx-x64
# ----------------------------------------------------------------------- Verify
- name: Verify Windows x64 matches Linux x64
if: always()
run: diff --unified --strip-trailing-cr --recursive bin/llvm/linux-x64/lib/clang/ bin/llvm/win-x64/lib/clang/
- name: Verify Linux ARM64 matches Linux x64
if: always()
run: diff --unified --strip-trailing-cr --recursive bin/llvm/linux-x64/lib/clang/ bin/llvm/linux-arm64/lib/clang/
- name: Verify macOS x64 matches Linux x64
if: always()
run: diff --unified --strip-trailing-cr --recursive bin/llvm/linux-x64/lib/clang/ bin/llvm/osx-x64/lib/clang/
# =====================================================================================================================================================================
# Publish NuGet Packages to GitHub
# =====================================================================================================================================================================
publish-packages-github:
name: Publish to GitHub
runs-on: ubuntu-latest
needs: [coalesce-packages, verify-clang-resources]
# Pushes to main always publish CI packages
# Published releases always publish packages
# A manual workflow only publishes packages if explicitly enabled
if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && github.event.inputs.will_publish_packages == 'true')
steps:
# ----------------------------------------------------------------------- Setup .NET
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.x
# ----------------------------------------------------------------------- Download built packages
- name: Download built packages
uses: actions/download-artifact@v2
with:
name: Packages
# ----------------------------------------------------------------------- Upload release assets
- name: Upload release assets
if: github.event_name == 'release'
uses: actions/github-script@v4
with:
user-agent: actions/github-script for ${{github.repository}}
script: |
const fs = require('fs').promises;
const path = require('path');
const upload_url = context.payload.release.upload_url;
if (!upload_url) {
throw "Missing release asset upload URL!";
}
for (let filePath of await fs.readdir('.')) {
const fileExtension = path.extname(filePath);
if (fileExtension != '.nupkg' && fileExtension != '.snupkg') {
continue;
}
console.log(`Uploading '${filePath}'`);
const contentLength = (await fs.stat(filePath)).size;
const fileContents = await fs.readFile(filePath);
await github.repos.uploadReleaseAsset({
url: upload_url,
headers: {
'content-type': 'application/octet-stream',
'content-length': contentLength
},
name: path.basename(filePath),
data: fileContents
});
}
# ----------------------------------------------------------------------- Push to GitHub Packages
- name: Push to GitHub Packages
run: dotnet nuget push "*.nupkg" --skip-duplicate --no-symbols --api-key ${{secrets.GITHUB_TOKEN}} --source https://nuget.pkg.github.com/${{github.repository_owner}}
env:
# This is a workaround for https://github.com/NuGet/Home/issues/9775
DOTNET_SYSTEM_NET_HTTP_USESOCKETSHTTPHANDLER: 0
# =====================================================================================================================================================================
# Publish NuGet Packages to NuGet.org
# =====================================================================================================================================================================
publish-packages-nuget-org:
name: Publish to NuGet.org
runs-on: ubuntu-latest
needs: [coalesce-packages, verify-clang-resources]
environment: NuGet.org
# Release builds always publish packages to NuGet.org
# Workflow dispatch builds will only publish packages if enabled and an explicit version number is given
if: github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && github.event.inputs.will_publish_packages == 'true' && github.event.inputs.version != '')
steps:
# ----------------------------------------------------------------------- Setup .NET
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.x
# ----------------------------------------------------------------------- Download built packages
- name: Download built packages
uses: actions/download-artifact@v2
with:
name: Packages
# ----------------------------------------------------------------------- Push to NuGet.org
- name: Push to NuGet.org
run: dotnet nuget push "*.nupkg" --api-key ${{secrets.NUGET_API_KEY}} --source ${{secrets.NUGET_API_URL}}
env:
# This is a workaround for https://github.com/NuGet/Home/issues/9775
DOTNET_SYSTEM_NET_HTTP_USESOCKETSHTTPHANDLER: 0
# =====================================================================================================================================================================
# Send CI Failure Notification
# =====================================================================================================================================================================
send-ci-failure-notification:
name: Send CI Failure Notification
needs: [build-llvm, build-dotnet, coalesce-packages, verify-clang-resources, publish-packages-github, publish-packages-nuget-org]
if: failure() && github.event_name != 'pull_request'
continue-on-error: true
runs-on: ubuntu-latest
steps:
# ----------------------------------------------------------------------- Checkout
- name: Checkout
uses: actions/checkout@v2
# ----------------------------------------------------------------------- Setup Python
- name: Setup Python 3.8
uses: actions/setup-python@v2
with:
python-version: '3.8'
# ----------------------------------------------------------------------- Send CI Failure Notification
- name: Send Notification
run: python .github/workflows/send-ci-failure-notification.py
env:
webhook_url: ${{secrets.TEAMS_WEBHOOK_URL}}
github_organization: ${{github.repository_owner}}
github_repo: ${{github.repository}}
github_workflow_name: ${{github.workflow}}
github_run_number: ${{github.run_id}}