forked from swiftlang/github-workflows
-
Notifications
You must be signed in to change notification settings - Fork 0
864 lines (848 loc) · 36.8 KB
/
swift_package_test.yml
File metadata and controls
864 lines (848 loc) · 36.8 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
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
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
name: Swift Matrix
permissions:
contents: read
on:
workflow_call:
inputs:
macos_xcode_versions:
type: string
description: "Xcode version list (JSON)"
default: "[\"16.4\", \"26.3\", \"26.4\"]"
macos_exclude_xcode_versions:
type: string
description: "Exclude Xcode version list (JSON)"
default: "[{\"xcode_version\": \"\"}]"
macos_versions:
type: string
description: "macOS version list (JSON)"
default: "[\"tahoe\"]"
macos_archs:
type: string
description: "macOS arch list (JSON)"
default: "[\"ARM64\"]"
ios_host_xcode_versions:
type: string
description: "Xcode version list (JSON)"
default: null
ios_host_exclude_xcode_versions:
type: string
description: "Exclude Xcode version list (JSON)"
default: null
ios_host_versions:
type: string
description: "iOS host (macOS) version list (JSON)"
default: null
ios_host_archs:
type: string
description: "iOS host (macOS) arch list (JSON)"
default: null
linux_swift_versions:
type: string
description: "Include Linux Swift version list (JSON)"
default: "[ \"5.9\", \"5.10\", \"6.0\", \"6.1\", \"6.2\", \"nightly-main\", \"nightly-6.3\"]"
linux_exclude_swift_versions:
type: string
description: "Exclude Linux Swift version list (JSON)"
default: "[{\"swift_version\": \"\"}]"
linux_os_versions:
type: string
description: "Linux OS version list (JSON)"
default: "[\"jammy\"]"
linux_host_archs:
type: string
description: "Linux arch list (JSON)"
default: "[\"x86_64\"]"
linux_static_sdk_versions:
type: string
description: "Static Linux Swift SDK version list (JSON)"
default: "[\"nightly-main\", \"nightly-6.2\", \"6.2\"]"
linux_static_sdk_exclude_swift_versions:
type: string
description: "Exclude Static Linux Swift SDK version list (JSON)"
default: "[{\"swift_version\": \"\"}]"
wasm_sdk_versions:
type: string
description: "Wasm Swift SDK version list (JSON)"
default: "[\"nightly-main\", \"nightly-6.3\", \"6.2\"]"
wasm_exclude_swift_versions:
type: string
description: "Exclude Wasm Swift SDK version list (JSON)"
default: "[{\"swift_version\": \"\"}]"
android_sdk_versions:
type: string
description: "Android Swift SDK version list (JSON)"
default: "[\"nightly-main\", \"nightly-6.3\"]"
android_exclude_swift_versions:
type: string
description: "Exclude Android Swift SDK version list (JSON)"
default: "[{\"swift_version\": \"\"}]"
windows_swift_versions:
type: string
description: "Include Windows Swift version list (JSON)"
# "5.10" is omitted for Windows because the container image is broken.
default: "[\"5.9\", \"6.0\", \"6.1\", \"6.2\", \"nightly-main\", \"nightly-6.3\"]"
windows_exclude_swift_versions:
type: string
description: "Exclude Windows Swift version list (JSON)"
default: "[{\"swift_version\": \"\"}]"
windows_os_versions:
type: string
description: "Windows OS version label list (JSON)"
default: "[\"windows-2022\"]"
swift_flags:
type: string
description: "Swift flags for release version"
default: ""
swift_nightly_flags:
type: string
description: "Swift flags for nightly version"
default: ""
linux_pre_build_command:
type: string
description: "Linux command to execute before building the Swift package"
default: ""
linux_static_sdk_pre_build_command:
type: string
description: "Linux command to execute before building the Swift package with the Static Linux Swift SDK"
default: ""
wasm_sdk_pre_build_command:
type: string
description: "Linux command to execute before building the Swift package with the Embedded Swift SDK for Wasm"
default: ""
android_sdk_pre_build_command:
type: string
description: "Linux command to execute before building the Swift package with the Embedded Swift SDK for Android"
default: ""
macos_pre_build_command:
type: string
description: "macOS command to execute before building the Swift package"
default: ""
macos_build_command:
type: string
description: "macOS command to build and test the package"
default: "xcrun swift test"
macos_build_timeout:
type: number
description: "The default step timeout in minutes"
default: 60
ios_pre_build_command:
type: string
description: "macOS command to execute before building the Swift package for iOS"
default: ""
ios_build_command:
type: string
description: "macOS command to build the package for iOS"
default: "\"$(xcrun -f swift)\" build --build-tests --sdk \"$(xcrun --sdk iphoneos --show-sdk-path)\" --triple arm64-apple-ios"
ios_build_timeout:
type: number
description: "The default step timeout in minutes"
default: 60
linux_build_command:
type: string
description: "Linux command to build and test the package"
default: "swift test"
linux_static_sdk_build_command:
type: string
description: "Command to use when building the package with the Static Linux Swift SDK"
default: "swift build"
wasm_sdk_build_command:
type: string
description: "Command to use when building the package with the Swift SDK for Wasm"
default: "swift build"
android_sdk_build_command:
type: string
description: "Command to use when building the package with the Swift SDK for Android"
default: "swift build"
android_sdk_triples:
type: string
description: "The triples to use when building with the Swift SDK for Android. The final triple in the list will be used for the emulator testing and should match the host architecture."
default: "[\"aarch64-unknown-linux-android28\", \"x86_64-unknown-linux-android28\"]"
android_ndk_versions:
type: string
description: "The NDK versions to use when building with the Swift SDK for Android"
default: "[\"r27d\"]"
windows_pre_build_command:
type: string
description: "Windows Command Prompt command to execute before building the Swift package"
default: ""
windows_build_command:
type: string
description: |
Windows Command Prompt command to build and test the package.
Note that Powershell does not automatically exit if a subcommand fails. The Invoke-Program utility is available to propagate non-zero exit codes.
It is strongly encouraged to run all command using `Invoke-Program` unless you want to continue on error eg. `Invoke-Program git apply patch.diff` instead of `git apply patch.diff`.
default: "Invoke-Program swift test"
windows_build_timeout:
type: number
description: "The default step timeout in minutes"
default: 60
macos_env_vars:
description: "Newline separated list of environment variables"
type: string
ios_host_env_vars:
description: "Newline separated list of environment variables"
type: string
linux_env_vars:
description: "Newline separated list of environment variables"
type: string
windows_env_vars:
description: "Newline separated list of environment variables"
type: string
enable_linux_checks:
type: boolean
description: "Boolean to enable linux testing. Defaults to true"
default: true
enable_linux_static_sdk_build:
type: boolean
description: "Boolean to enable building with the Static Linux Swift SDK. Defaults to false"
default: false
enable_wasm_sdk_build:
type: boolean
description: "Boolean to enable building with the Swift SDK for Wasm. Defaults to false"
default: false
enable_embedded_wasm_sdk_build:
type: boolean
description: "Boolean to enable building with the Embedded Swift SDK for Wasm. Defaults to false"
default: false
enable_android_sdk_build:
type: boolean
description: "Boolean to enable building with the Swift SDK for Android. Defaults to false"
default: false
enable_android_sdk_checks:
type: boolean
description: "Boolean to enable testing with the Swift SDK for Android. Defaults to false"
default: false
enable_macos_checks:
type: boolean
description: "Boolean to enable macOS testing. Defaults to false"
default: false
enable_ios_checks:
type: boolean
description: "Boolean to enable iOS testing. Defaults to false"
default: false
enable_windows_checks:
type: boolean
description: "Boolean to enable windows testing. Defaults to true"
default: true
enable_windows_docker:
type: boolean
description: "Boolean to enable running build in windows docker container. Defaults to true"
default: true
needs_token:
type: boolean
description: "Boolean to enable providing the GITHUB_TOKEN to downstream job."
default: false
enable_cross_pr_testing:
type: boolean
description: "Whether PRs can be tested in combination with other PRs by mentioning them as `Linked PR: <link to PR>` in the PR description"
default: false
jobs:
macos-build:
name: macOS (Xcode ${{ matrix.xcode_version }} - ${{ matrix.os_version }} - ${{ matrix.arch }})
if: ${{ inputs.enable_macos_checks }}
runs-on: [self-hosted, macos, "${{ matrix.os_version }}", "${{ matrix.arch }}"]
strategy:
fail-fast: false
matrix:
xcode_version: ${{ fromJson(inputs.macos_xcode_versions) }}
os_version: ${{ fromJson(inputs.macos_versions) }}
arch: ${{ fromJson(inputs.macos_archs) }}
exclude:
- ${{ fromJson(inputs.macos_exclude_xcode_versions) }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Provide token
if: ${{ inputs.needs_token }}
run: |
echo "GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_ENV
- name: Set environment variables
if: ${{ inputs.macos_env_vars }}
env:
ENV_VARS: ${{ inputs.macos_env_vars }}
run: |
for i in "${ENV_VARS}"
do
printf "%s\n" $i >> $GITHUB_ENV
done
- name: Select Xcode
run: echo "DEVELOPER_DIR=/Applications/Xcode_${{ matrix.xcode_version }}.app" >> $GITHUB_ENV
- name: Swift version
run: xcrun swift --version
- name: Clang version
run: xcrun clang --version
- name: Pre-build
# zizmor: ignore[template-injection]
run: ${{ inputs.macos_pre_build_command }}
- name: Build / Test
# zizmor: ignore[template-injection]
run: ${{ inputs.macos_build_command }} ${{ (contains(matrix.swift_version, 'nightly') && inputs.swift_nightly_flags) || inputs.swift_flags }}
timeout-minutes: ${{ inputs.macos_build_timeout }}
ios-build:
name: iOS (Build Only, Xcode ${{ matrix.xcode_version }} - ${{ matrix.os_version }} - ${{ matrix.arch }})
if: ${{ inputs.enable_ios_checks }}
runs-on: [self-hosted, macos, "${{ matrix.os_version }}", "${{ matrix.arch }}"]
strategy:
fail-fast: false
matrix:
xcode_version: ${{ fromJson(inputs.ios_host_xcode_versions || inputs.macos_xcode_versions) }}
os_version: ${{ fromJson(inputs.ios_host_versions || inputs.macos_versions) }}
arch: ${{ fromJson(inputs.ios_host_archs || inputs.macos_archs) }}
exclude:
- ${{ fromJson(inputs.ios_host_exclude_xcode_versions || inputs.macos_exclude_xcode_versions) }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Provide token
if: ${{ inputs.needs_token }}
run: |
echo "GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_ENV
- name: Set environment variables
if: ${{ inputs.ios_host_env_vars }}
env:
ENV_VARS: ${{ inputs.ios_host_env_vars }}
run: |
for i in "${ENV_VARS}"
do
printf "%s\n" $i >> $GITHUB_ENV
done
- name: Select Xcode
run: echo "DEVELOPER_DIR=/Applications/Xcode_${{ matrix.xcode_version }}.app" >> $GITHUB_ENV
- name: Swift version
run: |
"$(xcrun -f swift)" --version
- name: Pre-build
# zizmor: ignore[template-injection]
run: ${{ inputs.ios_pre_build_command }}
- name: Build
# zizmor: ignore[template-injection]
run: ${{ inputs.ios_build_command }} ${{ (contains(matrix.swift_version, 'nightly') && inputs.swift_nightly_flags) || inputs.swift_flags }}
timeout-minutes: ${{ inputs.ios_build_timeout }}
linux-build:
name: Linux (${{ matrix.swift_version }} - ${{ matrix.os_version }} - ${{ matrix.arch }})
if: ${{ inputs.enable_linux_checks }}
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
swift_version: ${{ fromJson(inputs.linux_swift_versions) }}
os_version: ${{ fromJson(inputs.linux_os_versions) }}
arch: ${{ fromJson(inputs.linux_host_archs) }}
runner: ${{
fromJson(
contains(fromJson(inputs.linux_host_archs), 'x86_64') && !contains(fromJson(inputs.linux_host_archs), 'aarch64')
&& '["ubuntu-24.04"]'
|| contains(fromJson(inputs.linux_host_archs), 'aarch64') && !contains(fromJson(inputs.linux_host_archs), 'x86_64')
&& '["ubuntu-24.04-arm"]'
|| '["ubuntu-24.04","ubuntu-24.04-arm"]'
)
}}
exclude:
- ${{ fromJson(inputs.linux_exclude_swift_versions) }}
- arch: x86_64
runner: ubuntu-24.04-arm
- arch: aarch64
runner: ubuntu-24.04
container:
image: ${{ (contains(matrix.swift_version, 'nightly') && 'swiftlang/swift') || 'swift' }}:${{ matrix.swift_version }}-${{ matrix.os_version }}
steps:
- name: Swift version
run: swift --version
- name: Clang version
run: clang --version
- name: Checkout repository
uses: actions/checkout@v4
if: ${{ matrix.os_version != 'amazonlinux2' }}
- name: Checkout repository
uses: actions/checkout@v1
if: ${{ matrix.os_version == 'amazonlinux2' }}
- name: Checkout swiftlang/github-workflows repository
if: ${{ matrix.os_version != 'amazonlinux2' && github.repository != 'swiftlang/github-workflows' }}
uses: actions/checkout@v4
with:
repository: swiftlang/github-workflows
path: github-workflows
- name: Checkout swiftlang/github-workflows repository
if: ${{ matrix.os_version == 'amazonlinux2' && github.repository != 'swiftlang/github-workflows' }}
uses: actions/checkout@v1
with:
repository: swiftlang/github-workflows
path: ${{ github.event.repository.name }}/github-workflows
ref: main
- name: Determine script-root path
id: script_path
run: |
if [ "${{ github.repository }}" = "swiftlang/github-workflows" ]; then
echo "root=$GITHUB_WORKSPACE" >> $GITHUB_OUTPUT
else
echo "root=$GITHUB_WORKSPACE/github-workflows" >> $GITHUB_OUTPUT
fi
- name: Provide token
if: ${{ inputs.needs_token }}
run: |
echo "GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_ENV
- name: Check out related PRs
if: ${{ inputs.enable_cross_pr_testing && github.event_name == 'pull_request' }}
run: |
cat ${{ steps.script_path.outputs.root }}/.github/workflows/scripts/cross-pr-checkout.swift > /tmp/cross-pr-checkout.swift
swift /tmp/cross-pr-checkout.swift "${{ github.repository }}" "${{ github.event.number }}"
- name: Set environment variables
if: ${{ inputs.linux_env_vars }}
env:
ENV_VARS: ${{ inputs.linux_env_vars }}
run: |
for i in "${ENV_VARS}"
do
printf "%s\n" $i >> $GITHUB_ENV
done
- name: Pre-build
# zizmor: ignore[template-injection]
run: ${{ inputs.linux_pre_build_command }}
- name: Build / Test
# zizmor: ignore[template-injection]
run: ${{ inputs.linux_build_command }} ${{ (contains(matrix.swift_version, 'nightly') && inputs.swift_nightly_flags) || inputs.swift_flags }}
linux-static-sdk-build:
name: Static Linux Swift SDK Build (${{ matrix.swift_version }} - ${{ matrix.os_version }} - ${{ matrix.arch }})
if: ${{ inputs.enable_linux_static_sdk_build }}
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
swift_version: ${{ fromJson(inputs.linux_static_sdk_versions) }}
os_version: ${{ fromJson(inputs.linux_os_versions) }}
arch: ${{ fromJson(inputs.linux_host_archs) }}
runner: ${{
fromJson(
contains(fromJson(inputs.linux_host_archs), 'x86_64') && !contains(fromJson(inputs.linux_host_archs), 'aarch64')
&& '["ubuntu-24.04"]'
|| contains(fromJson(inputs.linux_host_archs), 'aarch64') && !contains(fromJson(inputs.linux_host_archs), 'x86_64')
&& '["ubuntu-24.04-arm"]'
|| '["ubuntu-24.04","ubuntu-24.04-arm"]'
)
}}
exclude:
- ${{ fromJson(inputs.linux_static_sdk_exclude_swift_versions) }}
- arch: x86_64
runner: ubuntu-24.04-arm
- arch: aarch64
runner: ubuntu-24.04
container:
image: ${{ (contains(matrix.swift_version, 'nightly') && 'swiftlang/swift') || 'swift' }}:${{ matrix.swift_version }}-${{ matrix.os_version }}
steps:
- name: Swift version
run: swift --version
- name: Clang version
run: clang --version
- name: Checkout repository
uses: actions/checkout@v4
if: ${{ matrix.os_version != 'amazonlinux2' }}
- name: Checkout repository
uses: actions/checkout@v1
if: ${{ matrix.os_version == 'amazonlinux2' }}
- name: Checkout swiftlang/github-workflows repository
if: ${{ matrix.os_version != 'amazonlinux2' && github.repository != 'swiftlang/github-workflows' }}
uses: actions/checkout@v4
with:
repository: swiftlang/github-workflows
path: github-workflows
- name: Checkout swiftlang/github-workflows repository
if: ${{ matrix.os_version == 'amazonlinux2' && github.repository != 'swiftlang/github-workflows' }}
uses: actions/checkout@v1
with:
repository: swiftlang/github-workflows
path: ${{ github.event.repository.name }}/github-workflows
ref: main
- name: Determine script-root path
id: script_path
run: |
if [ "${{ github.repository }}" = "swiftlang/github-workflows" ]; then
echo "root=$GITHUB_WORKSPACE" >> $GITHUB_OUTPUT
else
echo "root=$GITHUB_WORKSPACE/github-workflows" >> $GITHUB_OUTPUT
fi
- name: Provide token
if: ${{ inputs.needs_token }}
run: |
echo "GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_ENV
- name: Set environment variables
if: ${{ inputs.linux_env_vars }}
env:
ENV_VARS: ${{ inputs.linux_env_vars }}
run: |
for i in "${ENV_VARS}"
do
printf "%s\n" $i >> $GITHUB_ENV
done
- name: Pre-build
# zizmor: ignore[template-injection]
run: ${{ inputs.linux_pre_build_command }}
- name: Install Static Linux Swift SDK and build
env:
BUILD_FLAGS: ${{ (contains(matrix.swift_version, 'nightly') && inputs.swift_nightly_flags) || inputs.swift_flags }}
# zizmor: ignore[template-injection]
run: |
${{ inputs.linux_static_sdk_pre_build_command }}
${{ steps.script_path.outputs.root }}/.github/workflows/scripts/install-and-build-with-sdk.sh --static --flags="$BUILD_FLAGS" --build-command="${{ inputs.linux_static_sdk_build_command }}" ${{ matrix.swift_version }}
wasm-sdk-build:
name: Swift SDK for Wasm Build (${{ matrix.swift_version }} - ${{ matrix.os_version }})
if: ${{ inputs.enable_wasm_sdk_build }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
swift_version: ${{ fromJson(inputs.wasm_sdk_versions) }}
os_version: ${{ fromJson(inputs.linux_os_versions) }}
exclude:
- ${{ fromJson(inputs.wasm_exclude_swift_versions) }}
container:
image: ${{ (contains(matrix.swift_version, 'nightly') && 'swiftlang/swift') || 'swift' }}:${{ matrix.swift_version }}-${{ matrix.os_version }}
steps:
- name: Swift version
run: swift --version
- name: Clang version
run: clang --version
- name: Checkout repository
uses: actions/checkout@v4
if: ${{ matrix.os_version != 'amazonlinux2' }}
- name: Checkout repository
uses: actions/checkout@v1
if: ${{ matrix.os_version == 'amazonlinux2' }}
- name: Checkout swiftlang/github-workflows repository
if: ${{ matrix.os_version != 'amazonlinux2' && github.repository != 'swiftlang/github-workflows' }}
uses: actions/checkout@v4
with:
repository: swiftlang/github-workflows
path: github-workflows
- name: Checkout swiftlang/github-workflows repository
if: ${{ matrix.os_version == 'amazonlinux2' && github.repository != 'swiftlang/github-workflows' }}
uses: actions/checkout@v1
with:
repository: swiftlang/github-workflows
path: ${{ github.event.repository.name }}/github-workflows
ref: main
- name: Determine script-root path
id: script_path
run: |
if [ "${{ github.repository }}" = "swiftlang/github-workflows" ]; then
echo "root=$GITHUB_WORKSPACE" >> $GITHUB_OUTPUT
else
echo "root=$GITHUB_WORKSPACE/github-workflows" >> $GITHUB_OUTPUT
fi
- name: Provide token
if: ${{ inputs.needs_token }}
run: |
echo "GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_ENV
- name: Set environment variables
if: ${{ inputs.linux_env_vars }}
env:
ENV_VARS: ${{ inputs.linux_env_vars }}
run: |
for i in "${ENV_VARS}"
do
printf "%s\n" $i >> $GITHUB_ENV
done
- name: Pre-build
# zizmor: ignore[template-injection]
run: ${{ inputs.linux_pre_build_command }}
- name: Install Swift SDK for Wasm and build
env:
BUILD_FLAGS: ${{ (contains(matrix.swift_version, 'nightly') && inputs.swift_nightly_flags) || inputs.swift_flags }}
# zizmor: ignore[template-injection]
run: |
${{ inputs.wasm_sdk_pre_build_command }}
${{ steps.script_path.outputs.root }}/.github/workflows/scripts/install-and-build-with-sdk.sh --wasm --flags="$BUILD_FLAGS" --build-command="${{ inputs.wasm_sdk_build_command }}" ${{ matrix.swift_version }}
embedded-wasm-sdk-build:
name: Embedded Swift SDK for Wasm Build (${{ matrix.swift_version }} - ${{ matrix.os_version }})
if: ${{ inputs.enable_embedded_wasm_sdk_build }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
swift_version: ${{ fromJson(inputs.wasm_sdk_versions) }}
os_version: ${{ fromJson(inputs.linux_os_versions) }}
exclude:
- ${{ fromJson(inputs.wasm_exclude_swift_versions) }}
container:
image: ${{ (contains(matrix.swift_version, 'nightly') && 'swiftlang/swift') || 'swift' }}:${{ matrix.swift_version }}-${{ matrix.os_version }}
steps:
- name: Swift version
run: swift --version
- name: Clang version
run: clang --version
- name: Checkout repository
uses: actions/checkout@v4
if: ${{ matrix.os_version != 'amazonlinux2' }}
- name: Checkout repository
uses: actions/checkout@v1
if: ${{ matrix.os_version == 'amazonlinux2' }}
- name: Checkout swiftlang/github-workflows repository
if: ${{ matrix.os_version != 'amazonlinux2' && github.repository != 'swiftlang/github-workflows' }}
uses: actions/checkout@v4
with:
repository: swiftlang/github-workflows
path: github-workflows
- name: Checkout swiftlang/github-workflows repository
if: ${{ matrix.os_version == 'amazonlinux2' && github.repository != 'swiftlang/github-workflows' }}
uses: actions/checkout@v1
with:
repository: swiftlang/github-workflows
path: ${{ github.event.repository.name }}/github-workflows
ref: main
- name: Determine script-root path
id: script_path
run: |
if [ "${{ github.repository }}" = "swiftlang/github-workflows" ]; then
echo "root=$GITHUB_WORKSPACE" >> $GITHUB_OUTPUT
else
echo "root=$GITHUB_WORKSPACE/github-workflows" >> $GITHUB_OUTPUT
fi
- name: Provide token
if: ${{ inputs.needs_token }}
run: |
echo "GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_ENV
- name: Set environment variables
if: ${{ inputs.linux_env_vars }}
env:
ENV_VARS: ${{ inputs.linux_env_vars }}
run: |
for i in "${ENV_VARS}"
do
printf "%s\n" $i >> $GITHUB_ENV
done
- name: Pre-build
# zizmor: ignore[template-injection]
run: ${{ inputs.linux_pre_build_command }}
- name: Install Swift SDK for Wasm and build
env:
BUILD_FLAGS: ${{ (contains(matrix.swift_version, 'nightly') && inputs.swift_nightly_flags) || inputs.swift_flags }}
# zizmor: ignore[template-injection]
run: |
${{ inputs.wasm_sdk_pre_build_command }}
${{ steps.script_path.outputs.root }}/.github/workflows/scripts/install-and-build-with-sdk.sh --embedded-wasm --flags="$BUILD_FLAGS" ${{ matrix.swift_version }}
android-sdk-build:
name: Swift SDK for Android Build (${{ matrix.swift_version }} - NDK ${{ matrix.ndk_version }})
if: ${{ inputs.enable_android_sdk_build }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
swift_version: ${{ fromJson(inputs.android_sdk_versions) }}
ndk_version: ${{ fromJson(inputs.android_ndk_versions) }}
exclude:
- ${{ fromJson(inputs.android_exclude_swift_versions) }}
steps:
- name: Swift version
run: swift --version
- name: Clang version
run: clang --version
- name: Checkout repository
uses: actions/checkout@v4
- name: Checkout swiftlang/github-workflows repository
uses: actions/checkout@v4
with:
repository: swiftlang/github-workflows
path: github-workflows
- name: Determine script-root path
id: script_path
run: |
if [ "${{ github.repository }}" = "swiftlang/github-workflows" ]; then
echo "root=$GITHUB_WORKSPACE" >> $GITHUB_OUTPUT
else
echo "root=$GITHUB_WORKSPACE/github-workflows" >> $GITHUB_OUTPUT
fi
- name: Provide token
if: ${{ inputs.needs_token }}
run: |
echo "GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_ENV
- name: Set environment variables
if: ${{ inputs.linux_env_vars }}
env:
ENV_VARS: ${{ inputs.linux_env_vars }}
run: |
for i in "${ENV_VARS}"
do
printf "%s\n" $i >> $GITHUB_ENV
done
- name: Pre-build
# zizmor: ignore[template-injection]
run: ${{ inputs.linux_pre_build_command }}
- name: Install Swift SDK for Android and build
env:
BUILD_FLAGS: ${{ inputs.enable_android_sdk_checks && '--build-tests' || '' }} ${{ (contains(matrix.swift_version, 'nightly') && inputs.swift_nightly_flags) || inputs.swift_flags }}
shell: bash
# zizmor: ignore[template-injection]
run: |
${{ inputs.android_sdk_pre_build_command }}
${{ steps.script_path.outputs.root }}/.github/workflows/scripts/install-and-build-with-sdk.sh --android --flags="$BUILD_FLAGS" --build-command="${{ inputs.android_sdk_build_command }}" --android-sdk-triple=${{ join(fromJson(inputs.android_sdk_triples), ' --android-sdk-triple=') }} --android-ndk-version="${{ matrix.ndk_version }}" ${{ matrix.swift_version }}
- name: Enable KVM and free disk space
if: ${{ inputs.enable_android_sdk_checks }}
run: |
# enable KVM on Linux for tests, else error on emulator launch:
# CPU acceleration status: This user doesn't have permissions to use KVM (/dev/kvm).
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm
# need to free space or the emulator runs out
sudo rm -rf /opt/microsoft /opt/google /opt/az /opt/ghc /usr/share/dotnet /usr/local/share/boost /opt/hostedtoolcache /usr/local/share/chromium
df -h
- name: Install Android Emulator and run tests
if: ${{ inputs.enable_android_sdk_checks }}
shell: bash
# zizmor: ignore[template-injection]
run: |
${{ inputs.android_sdk_pre_build_command }}
${{ steps.script_path.outputs.root }}/.github/workflows/scripts/android/android-emulator-tests.sh --android-sdk-triple=${{ join(fromJson(inputs.android_sdk_triples), ' --android-sdk-triple=') }}
windows-build:
name: Windows (${{ matrix.swift_version }} - ${{ matrix.os_version }})
if: ${{ inputs.enable_windows_checks }}
runs-on: ${{ matrix.os_version }}
strategy:
fail-fast: false
matrix:
swift_version: ${{ fromJson(inputs.windows_swift_versions) }}
os_version: ${{ fromJson(inputs.windows_os_versions) }}
exclude:
- ${{ fromJson(inputs.windows_exclude_swift_versions) }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Checkout swiftlang/github-workflows repository
if: ${{ github.repository != 'swiftlang/github-workflows' }}
uses: actions/checkout@v4
with:
repository: swiftlang/github-workflows
path: github-workflows
- name: Determine script-root path
id: script_path
run: |
if ("${{ inputs.enable_windows_docker }}" -eq "true") {
$source = "C:\source"
} else {
$source = $env:GITHUB_WORKSPACE
}
if ("${{ github.repository }}" -eq "swiftlang/github-workflows") {
echo "root=$source" >> $env:GITHUB_OUTPUT
} else {
echo "root=$source/github-workflows" >> $env:GITHUB_OUTPUT
}
- name: Provide token
if: ${{ inputs.needs_token }}
run: |
echo "GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
- name: Set environment variables
if: ${{ inputs.windows_env_vars }}
env:
WINDOWS_ENV_VARS: ${{ inputs.windows_env_vars }}
run: |
$lines = $env:WINDOWS_ENV_VARS -split "`r`n"
foreach ($line in $lines) {
echo $line | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
}
- name: Ensure Docker engine is ready
if: ${{ inputs.enable_windows_docker }}
run: |
# Start Docker service
Write-Host "Starting Docker service..."
Start-Service docker
# Wait for Docker to be ready with exponential backoff
$maxRetries = 10
$retryCount = 0
$baseDelay = 1
$maxDelay = 30
while ($retryCount -lt $maxRetries) {
try {
docker info | Out-Null
if ($LASTEXITCODE) {
throw "docker engine is not ready"
}
Write-Host "Docker engine is ready"
break
} catch {
$retryCount++
if ($retryCount -lt $maxRetries) {
# Exponential backoff: 2^retryCount * baseDelay, capped at maxDelay
$delay = [Math]::Min([Math]::Pow(2, $retryCount) * $baseDelay, $maxDelay)
Write-Host "Waiting for Docker engine to be ready... (attempt $retryCount/$maxRetries, waiting $delay seconds)"
Start-Sleep -Seconds $delay
}
}
}
if ($retryCount -eq $maxRetries) {
Write-Error "Docker engine failed to start after $maxRetries attempts"
exit 1
}
- name: Pull Docker image
id: pull_docker_image
if: ${{ inputs.enable_windows_docker }}
run: |
if ("${{ matrix.swift_version }}".Contains("nightly")) {
$Image = "swiftlang/swift:${{ matrix.swift_version }}-windowsservercore-ltsc2022"
} else {
$Image = "swift:${{ matrix.swift_version }}-windowsservercore-ltsc2022"
}
docker pull $Image
echo "image=$Image" >> "$env:GITHUB_OUTPUT"
- name: "Install Python 3.10"
if: ${{ !inputs.enable_windows_docker && !(matrix.swift_version == '6.1' || matrix.swift_version == '6.0' || matrix.swift_version == '5.10' || matrix.swift_version == '5.9') }}
uses: actions/setup-python@v6
with:
python-version: "3.10"
architecture: "x64"
- name: "Install Python 3.9"
if: ${{ !inputs.enable_windows_docker && (matrix.swift_version == '6.1' || matrix.swift_version == '6.0' || matrix.swift_version == '5.10' || matrix.swift_version == '5.9') }}
uses: actions/setup-python@v6
with:
python-version: "3.9"
architecture: "x64"
- name: Install Visual Studio Build Tools
if: ${{ !inputs.enable_windows_docker }}
run: . ${{ steps.script_path.outputs.root }}/.github/workflows/scripts/windows/install-vsb.ps1
- name: Install Swift
if: ${{ !inputs.enable_windows_docker }}
run: . ${{ steps.script_path.outputs.root }}/.github/workflows/scripts/windows/swift/install-swift-${{ matrix.swift_version }}.ps1
- name: Create test script
# zizmor: ignore[template-injection]
run: |
mkdir $env:TEMP\test-script
echo @'
Set-PSDebug -Trace 1
if ("${{ inputs.enable_windows_docker }}" -eq "true") {
$Source = "C:\source"
} else {
$Source = $env:GITHUB_WORKSPACE
}
# Run the command following `Invoke-Program`.
# If that command returns a non-zero exit code, return the same exit code from this script.
function Invoke-Program($Executable) {
& $Executable @args
if ($LastExitCode -ne 0) {
exit $LastExitCode
}
}
Invoke-Program swift --version
Invoke-Program swift test --version
Invoke-Program clang --version
Invoke-Program cd $Source
'@ >> $env:TEMP\test-script\run.ps1
if ("${{ inputs.enable_cross_pr_testing && github.event_name == 'pull_request' }}" -eq "true") {
echo @'
# Running in script mode fails on Windows (https://github.com/swiftlang/swift/issues/77263), compile and run the script.
Invoke-Program swiftc -sdk $env:SDKROOT ${{ steps.script_path.outputs.root }}/.github/workflows/scripts/cross-pr-checkout.swift -o $env:TEMP\cross-pr-checkout.exe
Invoke-Program $env:TEMP\cross-pr-checkout.exe "${{ github.repository }}" "${{ github.event.number }}"
'@ >> $env:TEMP\test-script\run.ps1
}
echo @'
${{ inputs.windows_pre_build_command }}
${{ inputs.windows_build_command }} ${{ (contains(matrix.swift_version, 'nightly') && inputs.swift_nightly_flags) || inputs.swift_flags }}
'@ >> $env:TEMP\test-script\run.ps1
# Docker build
- name: Docker Build / Test
timeout-minutes: ${{ inputs.windows_build_timeout }}
if: ${{ inputs.enable_windows_docker }}
run: |
docker run -v ${{ github.workspace }}:C:\source -v $env:TEMP\test-script:C:\test-script ${{ steps.pull_docker_image.outputs.image }} powershell.exe -NoLogo -File C:\test-script\run.ps1
# Docker-less build
- name: Build / Test
timeout-minutes: ${{ inputs.windows_build_timeout }}
if: ${{ !inputs.enable_windows_docker }}
run: powershell.exe -NoLogo -File $env:TEMP\test-script\run.ps1; exit $LastExitCode