-
Notifications
You must be signed in to change notification settings - Fork 43
135 lines (131 loc) · 5.55 KB
/
swift_package_test.yml
File metadata and controls
135 lines (131 loc) · 5.55 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
name: Swift Linux Matrix
on:
workflow_call:
inputs:
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\"]"
windows_exclude_swift_versions:
type: string
description: "Exclude Windows Swift version list (JSON)"
default: "[{\"swift_version\": \"\"}]"
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_build_command:
type: string
description: "Linux command to build and test the package"
default: "swift test"
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: "swift test"
linux_env_vars:
description: "List of environment variables"
type: string
enable_windows_checks:
type: boolean
description: "Boolean to enable windows testing. Defaults to true"
default: true
jobs:
linux-build:
name: Linux (${{ matrix.swift_version }} - ${{ matrix.os_version }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
swift_version: ['5.8', '5.9', '5.10', '6.0', 'nightly-main', 'nightly-6.0']
os_version: ${{ fromJson(inputs.linux_os_versions) }}
exclude:
- ${{ fromJson(inputs.linux_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: Checkout repository
if: env.ACT != 'true'
uses: actions/checkout@v4
with:
ref: ${{ github.ref }} # Include changes to the target branch when action is re-run https://github.com/actions/checkout/issues/1036
- name: Set environment variables
if: ${{ inputs.linux_env_vars }}
run: |
for i in "${{ inputs.linux_env_vars }}"
do
printf "%s\n" $i >> $GITHUB_ENV
done
- name: Pre-build
run: ${{ inputs.linux_pre_build_command }}
- name: Build / Test
run: ${{ inputs.linux_build_command }} ${{ (contains(matrix.swift_version, 'nightly') && inputs.swift_nightly_flags) || inputs.swift_flags }}
windows-build:
name: Windows (${{ matrix.swift_version }} - ${{ contains(matrix.swift_version, 'nightly') && 'windows-2019' || 'windows-2022' }})
if: ${{ inputs.enable_windows_checks }}
runs-on: ${{ contains(matrix.swift_version, 'nightly') && 'windows-2019' || 'windows-2022' }}
strategy:
fail-fast: false
matrix:
swift_version: ['5.9', '6.0', 'nightly', 'nightly-6.0']
exclude:
- ${{ fromJson(inputs.windows_exclude_swift_versions) }}
steps:
- name: Checkout repository
if: env.ACT != 'true'
uses: actions/checkout@v4
with:
ref: ${{ github.ref }} # Include changes to the target branch when action is re-run https://github.com/actions/checkout/issues/1036
- name: Pull Docker image
id: pull_docker_image
run: |
if ("${{ matrix.swift_version }}".Contains("nightly")) {
$Image = "swiftlang/swift:${{ matrix.swift_version }}-windowsservercore-1809"
} else {
$Image = "swift:${{ matrix.swift_version }}-windowsservercore-ltsc2022"
}
docker pull $Image
echo "image=$Image" >> "$env:GITHUB_OUTPUT"
- name: Create test script
run: |
mkdir $env:TEMP\test-script
echo @'
Set-PSDebug -Trace 1
# 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 cd C:\source\
${{ inputs.windows_pre_build_command }}
Invoke-Program ${{ inputs.windows_build_command }} ${{ (contains(matrix.swift_version, 'nightly') && inputs.swift_nightly_flags) || inputs.swift_flags }}
'@ >> $env:TEMP\test-script\run.ps1
- name: Build / Test
timeout-minutes: 60
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