-
-
Notifications
You must be signed in to change notification settings - Fork 1
328 lines (293 loc) · 13 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
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:
strategy:
fail-fast: false
matrix:
include:
- os: windows-latest
name: Windows
lib-path: build/bin/libclang.dll
build-command: ./build-native.cmd
artifact-name: LlvmBuildOutputs-Windows
# 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
lib-path: build-linux/lib/libclang.so
clang-resource-dir: build-linux/lib/clang/
build-command: ./build-native.sh
artifact-name: LlvmBuildOutputs-Linux
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
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-${{runner.os}}-${{steps.llvm.outputs.revision}}
# These are the paths of the external files required in ClangSharp.Pathogen.Runtime.csproj
# (Make sure this is syncronized with "Archive LLVM Outputs" below)
path: |
${{matrix.lib-path}}
${{matrix.clang-resource-dir}}
- 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
if: steps.cached-llvm.outputs.cache-hit != 'true'
uses: actions/cache@v2
# If you change this configuration make sure to update keep-cache-warm.yml as well.
with:
path: ${{steps.sccache.outputs.root-directory}}
key: sccache-cache-${{runner.os}}-${{steps.llvm.outputs.revision}}
restore-keys: sccache-cache-${{runner.os}}-
- 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
# We only need to do this on Linux since Visual Studio comes with a copy of Ninja and we end up picking that one up for Windows
- name: Install Ninja
if: steps.cached-llvm.outputs.cache-hit != 'true' && runner.os == 'Linux'
run: sudo apt install --yes ninja-build
- 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'
run: sccache --show-stats
# 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 ${{matrix.lib-path}} ${{matrix.lib-path}}-nosymlink
rm ${{matrix.lib-path}}
mv ${{matrix.lib-path}}-nosymlink ${{matrix.lib-path}}
- name: Upload LLVM build artifacts
uses: actions/upload-artifact@v2
with:
name: ${{matrix.artifact-name}}
if-no-files-found: error
# The paths listed here must match "Load cached LLVM build outputs" above
path: |
${{matrix.lib-path}}
${{matrix.clang-resource-dir}}
build-dotnet:
name: Build ClangSharp.Pathogen
runs-on: ubuntu-latest
needs: build-llvm
outputs:
publish-to-github: ${{steps.configuration.outputs.publish-to-github}}
steps:
# ----------------------------------------------------------------------- Checkout
- name: Checkout
uses: actions/checkout@v2
# Sadly we need to check out submodules here to make SourceLink happy.
# (Ideally we'd just archive libclang.dll along with the handful of files ClangSharp.Pathogen.Runtime needs to build the NuGet package.)
with:
submodules: 'recursive'
# ----------------------------------------------------------------------- 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: 5.0.x
# ----------------------------------------------------------------------- Download LLVM Build
- name: Download LLVM Windows build artifacts
uses: actions/download-artifact@v2
with:
name: LlvmBuildOutputs-Windows
path: build/bin/
- name: Download LLVM Linux build artifacts
uses: actions/download-artifact@v2
with:
name: LlvmBuildOutputs-Linux
path: build-linux/lib/
# ----------------------------------------------------------------------- Configure versioning
- name: Configure build
id: configuration
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 ClangSharp.Pathogen
- name: Restore
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Pack
id: pack
run: dotnet pack --no-build
# ----------------------------------------------------------------------- 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: BuildOutputs
# The build* folders is fine here because LLVM was built in another job so these will just be the stuff required to build
path: |
bin/**
obj/**
build*/**
!build-*.*
- 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: Packages
if-no-files-found: error
path: packages/**
publish-packages-github:
name: Publish to GitHub
runs-on: ubuntu-latest
needs: build-dotnet
# 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: 5.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 true --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-packages-nuget-org:
name: Publish to NuGet.org
runs-on: ubuntu-latest
needs: build-dotnet
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: 5.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:
name: Send CI Failure Notification
needs: [build-llvm, build-dotnet, 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}}