-
Notifications
You must be signed in to change notification settings - Fork 39
662 lines (545 loc) · 20.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
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
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
name: Build and test
on:
push:
# Empty configuration means use default (ie. test all branches)
branches-ignore:
# Everything would have passed bors before going into devel
- devel
# Bors temporary branches
- staging.tmp
- trying.tmp
- staging-squash-merge.tmp
# Github Merge Queue temporary branches
- gh-readonly-queue/**
pull_request:
# Only take PRs to devel
branches:
- devel
# Type of events to run CI on
types:
- opened
- synchronize
- reopened
- ready_for_review
merge_group:
# Test all additions to merge queue
# Run every script actions in bash
defaults:
run:
shell: bash
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
jobs:
pre_run:
name: Provide additional context for the workflow
runs-on: ubuntu-latest
outputs:
skip: ${{ steps.skip_result.outputs.result }}
target_matrix: ${{ steps.matrix.outputs.result }}
shared_builder: ${{ steps.matrix.outputs.shared }}
steps:
- id: skip_result
name: Whether to skip checks
run: |
if [[ $IS_DRAFT == true ]]; then
echo "Pull request is in draft state, skipping"
echo "result=true" >> $GITHUB_OUTPUT
else
echo "result=false" >> $GITHUB_OUTPUT
fi
env:
IS_DRAFT: ${{ github.event.pull_request.draft }}
- id: matrix
name: Obtain build target matrix
run: |
# This matrix will be shared by the jobs following it.
#
# The schema is:
# [
# {
# name: String, ## The name of the target being tested
# runner: String ## The runner to use of this target
# shared_builder?: Bool ## Whether this target should be used to
# ## build artifacts shared between
# ## platforms. Only one target may have
# ## this attribute.
# }
# ]
cat << "EOF" > matrix.json
[
{
"name": "Linux",
"runner": "ubuntu-20.04",
"shared_builder": true
},
{
"name": "macOS",
"runner": "macos-12"
},
{
"name": "macOS (M1)",
"runner": "macos-14"
},
{
"name": "Windows",
"runner": "windows-2022"
}
]
EOF
# Use jq to compact the matrix into one line to be used as the result
echo "result=$(jq -c . matrix.json)" >> $GITHUB_OUTPUT
# Isolate the shared builder into its own thing as well
echo "shared=$(jq -c '.[] | select(.shared_builder)' matrix.json)" >> $GITHUB_OUTPUT
binaries:
needs: [pre_run]
if: needs.pre_run.outputs.skip != 'true'
strategy:
fail-fast: false
matrix:
target: ${{ fromJson(needs.pre_run.outputs.target_matrix) }}
name: Build release binaries (${{ matrix.target.name }})
runs-on: ${{ matrix.target.runner }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
filter: tree:0
- name: Enable annotations
run: echo "::add-matcher::.github/nim-problem-matcher.json"
- name: Install MinGW (Windows)
if: runner.os == 'Windows'
uses: ./.github/actions/setup-mingw
- name: Setup vcpkg (Windows)
if: runner.os == 'Windows'
uses: ./.github/actions/setup-vcpkg
with:
triplet: x64-mingw-dynamic-release
host-triplet: x64-mingw-dynamic-release
revision: 2024.01.12
overlay-triplets: ${{ github.workspace }}/tools/vcpkg/triplets
- name: Install dependencies (Windows)
if: runner.os == 'Windows'
run: vcpkg install pcre sqlite3
- name: Download CA certificates (Windows)
if: runner.os == 'Windows'
run: |
$binPath = Join-Path $PWD "vcpkg" "installed" "x64-mingw-dynamic-release" "bin"
Invoke-WebRequest https://curl.se/ca/cacert.pem -OutFile (Join-Path $binPath "cacert.pem")
shell: pwsh
- name: Set Xcode version (macOS M1)
if: runner.os == 'macOS' && runner.arch == 'ARM64'
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: "15.0.1"
- name: Set macOS SDK version (macOS M1)
if: runner.os == 'macOS' && runner.arch == 'ARM64'
run: |
sdkpath=$(xcrun --sdk macosx14.0 --show-sdk-path)
echo "SDKROOT=$sdkpath" >> "$GITHUB_ENV"
- name: Build release binaries
run: ./koch.py all-strict
- name: Upload workspace to artifacts
uses: ./.github/actions/upload-compiler
test:
needs: [pre_run, binaries]
strategy:
fail-fast: false
matrix:
target: ${{ fromJson(needs.pre_run.outputs.target_matrix) }}
# This controls the testament "batch" feature.
#
# If any additional batches are added, increment `total_batch` as well.
#
# This feature allow us to parallelize testing.
batch: [0, 1]
# This tells testament how many batches are used. Have to be placed in
# an array due to how Github Actions process matrices.
total_batch: [2]
name: "Test the compiler and stdlib (${{ matrix.target.name }}, batch #${{ matrix.batch }})"
runs-on: ${{ matrix.target.runner }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
filter: tree:0
- uses: ./.github/actions/download-compiler
- name: Install NodeJS
uses: actions/setup-node@v4
with:
node-version: "16"
- name: Install dependencies (Linux)
if: runner.os == 'Linux'
run: |
deps=(
# Required by ARC/ORC memory leak tests (only enabled on linux x64)
libc6-dbg
valgrind
)
sudo apt-get update
sudo apt-get install "${deps[@]}"
- name: Set Xcode version (macOS M1)
if: runner.os == 'macOS' && runner.arch == 'ARM64'
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: "15.0.1"
- name: Set macOS SDK version (macOS M1)
if: runner.os == 'macOS' && runner.arch == 'ARM64'
run: |
sdkpath=$(xcrun --sdk macosx14.0 --show-sdk-path)
echo "SDKROOT=$sdkpath" >> "$GITHUB_ENV"
- name: Install dependencies (macOS)
if: runner.os == 'macOS'
run: |
brew update
- name: Install MinGW (Windows)
if: runner.os == 'Windows'
uses: ./.github/actions/setup-mingw
- name: Add DLLs to PATH (Windows)
if: runner.os == 'Windows'
run: |
$binPath = Join-Path $PWD "vcpkg" "installed" "x64-mingw-dynamic-release" "bin"
$binPath | Out-File -Append $env:GITHUB_PATH
shell: pwsh
- name: Run tester
run: ./koch.py test --batch:"$TEST_BATCH" --tryFailing all
env:
TEST_BATCH: ${{ matrix.batch }}_${{ matrix.total_batch }}
- name: Print all test errors
if: failure()
run: bin/nim r tools/ci_testresults
tooling:
needs: [pre_run, binaries]
strategy:
fail-fast: false
matrix:
target: ${{ fromJson(needs.pre_run.outputs.target_matrix) }}
name: Build and test tooling (${{ matrix.target.name }})
runs-on: ${{ matrix.target.runner }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
filter: tree:0
- name: Install MinGW (Windows)
if: runner.os == 'Windows'
uses: ./.github/actions/setup-mingw
- name: Add DLLs to PATH (Windows)
if: runner.os == 'Windows'
run: |
$binPath = Join-Path $PWD "vcpkg" "installed" "x64-mingw-dynamic-release" "bin"
$binPath | Out-File -Append $env:GITHUB_PATH
shell: pwsh
- name: Set Xcode version (macOS M1)
if: runner.os == 'macOS' && runner.arch == 'ARM64'
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: "15.0.1"
- name: Set macOS SDK version (macOS M1)
if: runner.os == 'macOS' && runner.arch == 'ARM64'
run: |
sdkpath=$(xcrun --sdk macosx14.0 --show-sdk-path)
echo "SDKROOT=$sdkpath" >> "$GITHUB_ENV"
- uses: ./.github/actions/download-compiler
- name: Enable annotations
run: echo "::add-matcher::.github/nim-problem-matcher.json"
- name: Test tooling
run: ./koch.py testTools
source:
needs: [pre_run, binaries]
name: Build source archive
runs-on: ${{ fromJson(needs.pre_run.outputs.shared_builder).runner }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
filter: tree:0
- uses: ./.github/actions/download-compiler
- name: Enable annotations
run: echo "::add-matcher::.github/nim-problem-matcher.json"
- name: Generate csources
run: ./koch.py csource -d:danger
- id: archive
name: Build release source
run: |
./koch.py archive
archive=build/archive/$(jq -r .name build/archive/archive.json)
# Rename the archive manifest to avoid collision with manifest of
# other archives
mv build/archive/archive.json build/archive/source.json
echo "archive=$archive" >> $GITHUB_OUTPUT
echo "metadata=build/archive/source.json" >> $GITHUB_OUTPUT
- name: Publish source archive to artifacts
uses: actions/upload-artifact@v4
with:
name: source archive
path: |
${{ steps.archive.outputs.archive }}
${{ steps.archive.outputs.metadata }}
if-no-files-found: error
source_binaries:
needs: [pre_run, source]
strategy:
fail-fast: false
matrix:
target: ${{ fromJson(needs.pre_run.outputs.target_matrix) }}
name: Build release artifacts from source archive (${{ matrix.target.name }})
runs-on: ${{ matrix.target.runner }}
steps:
- name: Get actions
uses: actions/checkout@v4
with:
path: git-src
sparse-checkout: .github/actions
- name: Install MinGW (Windows)
if: runner.os == 'Windows'
uses: ./git-src/.github/actions/setup-mingw
- name: Set Xcode version (macOS M1)
if: runner.os == 'macOS' && runner.arch == 'ARM64'
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: "15.0.1"
- name: Set macOS SDK version (macOS M1)
if: runner.os == 'macOS' && runner.arch == 'ARM64'
run: |
sdkpath=$(xcrun --sdk macosx14.0 --show-sdk-path)
echo "SDKROOT=$sdkpath" >> "$GITHUB_ENV"
- name: Download source archive
uses: actions/download-artifact@v4
with:
name: source archive
path: source-archive
- name: Unpack source archive
run: |
archive=source-archive/$(jq -r .name source-archive/source.json)
# Pipe from zstd to tar because macOS' tar does not support unpacking zstd
zstd -c -d "$archive" | tar -xf - --strip-components 1
- name: Setup vcpkg (Windows)
if: runner.os == 'Windows'
uses: ./git-src/.github/actions/setup-vcpkg
with:
triplet: x64-mingw-dynamic-release
host-triplet: x64-mingw-dynamic-release
revision: 2024.01.12
overlay-triplets: ${{ github.workspace }}/tools/vcpkg/triplets
- name: Install dependencies (Windows)
if: runner.os == 'Windows'
run: vcpkg install pcre sqlite3
- name: Add DLLs to PATH (Windows)
if: runner.os == 'Windows'
run: |
$binPath = Join-Path $PWD "vcpkg" "installed" "x64-mingw-dynamic-release" "bin"
$binPath | Out-File -Append $env:GITHUB_PATH
shell: pwsh
- name: Install DLLs to package (Windows)
if: runner.os == 'Windows'
run: |
$binPath = Join-Path $PWD "vcpkg" "installed" "x64-mingw-dynamic-release" "bin"
$binPath | Out-File -Append $env:GITHUB_PATH
Copy-Item (Join-Path $binPath "libpcre.dll") -Destination bin
shell: pwsh
- name: Build release binaries
run: ./koch.py all
# Note: keep synchronized with package job
- name: Build docs
run: |
./koch.py doc \
--git.url:"https://github.com/$GITHUB_REPOSITORY" \
--git.commit:"$GITHUB_SHA" \
--git.devel:devel
# Remove leftover nimskullcache
rm -rf doc/html/nimskullcache
- id: package
name: Create release package
run: |
releasecmd=unixrelease
if [[ "$RUNNER_OS" == Windows ]]; then
releasecmd=winrelease
fi
./koch.py "$releasecmd"
archive=build/archive/$(jq -r .name build/archive/archive.json)
# Rename the archive manifest to avoid collision with other artifacts
os=$(jq -r .os build/archive/archive.json)
cpu=$(jq -r .cpu build/archive/archive.json)
metadata=build/archive/${os}_${cpu}.json
mv build/archive/archive.json "$metadata"
# Let the uploader know what to upload
echo "archive=$archive" >> $GITHUB_OUTPUT
echo "metadata=$metadata" >> $GITHUB_OUTPUT
- name: Upload release package to artifacts
uses: actions/upload-artifact@v4
with:
name: binaries from source archive ${{ matrix.target.name }}
path: |
${{ steps.package.outputs.archive }}
${{ steps.package.outputs.metadata }}
if-no-files-found: error
package:
needs: [pre_run, binaries]
strategy:
fail-fast: false
matrix:
target: ${{ fromJson(needs.pre_run.outputs.target_matrix) }}
name: Build docs and release artifacts (${{ matrix.target.name }})
runs-on: ${{ matrix.target.runner }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
filter: tree:0
- uses: ./.github/actions/download-compiler
- name: Enable annotations
run: echo "::add-matcher::.github/nim-problem-matcher.json"
- name: Install MinGW (Windows)
if: runner.os == 'Windows'
uses: ./.github/actions/setup-mingw
- name: Add DLLs to PATH (Windows)
if: runner.os == 'Windows'
run: |
$binPath = Join-Path $PWD "vcpkg" "installed" "x64-mingw-dynamic-release" "bin"
$binPath | Out-File -Append $env:GITHUB_PATH
shell: pwsh
- name: Install DLLs to package (Windows)
if: runner.os == 'Windows'
run: |
$binPath = Join-Path $PWD "vcpkg" "installed" "x64-mingw-dynamic-release" "bin"
$binPath | Out-File -Append $env:GITHUB_PATH
Copy-Item (Join-Path $binPath "libpcre.dll") -Destination bin
shell: pwsh
- name: Set Xcode version (macOS M1)
if: runner.os == 'macOS' && runner.arch == 'ARM64'
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: "15.0.1"
- name: Set macOS SDK version (macOS M1)
if: runner.os == 'macOS' && runner.arch == 'ARM64'
run: |
sdkpath=$(xcrun --sdk macosx14.0 --show-sdk-path)
echo "SDKROOT=$sdkpath" >> "$GITHUB_ENV"
# Note: keep synchronized with source_binaries job
- name: Build docs
run: |
./koch.py doc \
--git.url:"https://github.com/$GITHUB_REPOSITORY" \
--git.commit:"$GITHUB_SHA" \
--git.devel:devel
# Remove leftover nimskullcache
rm -rf doc/html/nimskullcache
- id: package
name: Create release package
run: |
releasecmd=unixrelease
if [[ "$RUNNER_OS" == Windows ]]; then
releasecmd=winrelease
fi
./koch.py "$releasecmd"
archive=build/archive/$(jq -r .name build/archive/archive.json)
# Rename the archive manifest to avoid collision with other artifacts
os=$(jq -r .os build/archive/archive.json)
cpu=$(jq -r .cpu build/archive/archive.json)
metadata=build/archive/${os}_${cpu}.json
mv build/archive/archive.json "$metadata"
# Let the uploader know what to upload
echo "archive=$archive" >> $GITHUB_OUTPUT
echo "metadata=$metadata" >> $GITHUB_OUTPUT
- name: Upload release package to artifacts
uses: actions/upload-artifact@v4
with:
name: release binaries ${{ matrix.target.name }}
path: |
${{ steps.package.outputs.archive }}
${{ steps.package.outputs.metadata }}
if-no-files-found: error
test_package:
needs: [pre_run, package, source_binaries]
name: Test release artifacts
runs-on: ${{ fromJSON(needs.pre_run.outputs.shared_builder).runner }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
filter: tree:0
- uses: ./.github/actions/download-compiler
- name: Enable annotations
run: echo "::add-matcher::.github/nim-problem-matcher.json"
- name: Download binaries built from source archive
uses: actions/download-artifact@v4
with:
pattern: binaries from source archive*
path: binary-from-source
merge-multiple: true
- name: Download release package
uses: actions/download-artifact@v4
with:
# Download all release binaries to the same folder
pattern: release binaries*
path: release-binary
merge-multiple: true
- name: Download release source archive
uses: actions/download-artifact@v4
with:
name: source archive
path: source-archive
- name: Install tools
run: |
sudo apt-get update
sudo apt-get install -yqq --no-install-recommends diffoscope
- id: diff
name: Binaries from git and source archive should be the same
run: |
output_html=$RUNNER_TEMP/diffoscope.html
run_diff() {
# Exclude directory metadata as we only care about the files themselves
diffoscope \
--html="$output_html" \
--exclude-directory-metadata=yes \
release-binary/ binary-from-source/
}
if ! run_diff; then
echo "::error::There are differences when building from source archive compared to building from git, check the output uploaded to artifacts for more details"
echo "result=$output_html" >> $GITHUB_OUTPUT
exit 1
else
echo "Success! Binaries built from git and source archive are the same"
fi
- name: Upload difference test result on failure
if: failure() && steps.diff.outputs.result != ''
uses: actions/upload-artifact@v4
with:
name: differences between binary from source archive and git
path: ${{ steps.diff.outputs.result }}
- name: Verify archive manifests
run: |
# Verify them by using the manifest builder tool to create a manifest
# for the full bundle.
bin/nim c tools/release_manifest.nim
cd release-binary
../tools/release_manifest add ../source-archive/*.json *.json
# Print the resulting manifest
echo "Success! Generated manifest:"
jq . manifest.json
# This allow the publisher to run the tool directly without having to
# clone the compiler.
- name: Upload release manifest tool
uses: actions/upload-artifact@v4
with:
name: release manifest tool
path: tools/release_manifest
passed:
name: All check passed
needs:
- binaries
- test
- tooling
- source
- source_binaries
- package
- test_package
if: always()
runs-on: ubuntu-latest
steps:
- name: Raise failure
if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')
run: |
echo "::error::There are failing required jobs"
exit 1