-
Notifications
You must be signed in to change notification settings - Fork 44
282 lines (277 loc) · 12.1 KB
/
swift_package_test.yml
File metadata and controls
282 lines (277 loc) · 12.1 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
name: Swift Matrix
on:
workflow_call:
inputs:
macos_xcode_versions:
type: string
description: "Xcode version list (JSON)"
default: "[\"16.0\", \"16.1\", \"16.2\", \"16.3\"]"
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: "[\"sequoia\"]"
macos_archs:
type: string
description: "macOS arch list (JSON)"
default: "[\"ARM64\"]"
linux_swift_versions:
type: string
description: "Include Linux Swift version list (JSON)"
default: "[ \"5.9\", \"5.10\", \"6.0\", \"6.1\", \"nightly-main\", \"nightly-6.1\", \"nightly-6.2\"]"
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_swift_versions:
type: string
description: "Include Windows Swift version list (JSON)"
default: "[\"5.9\", \"6.0\", \"6.1\", \"nightly\", \"nightly-6.1\"]"
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: ""
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_release_build_command:
type: string
description: "macOS command to build and test the package"
default: "xcrun swift test -c release"
linux_build_command:
type: string
description: "Linux command to build and test the package"
default: "swift test"
linux_release_build_command:
type: string
description: "Linux command to build and test the package"
default: "swift test -c release"
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"
macos_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_macos_checks:
type: boolean
description: "Boolean to enable macOS 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
enable_release_tests:
type: boolean
description: "Boolean to enable building and running tests in release mode in addition to the default debug mode. Defaults to false"
default: false
needs_token:
type: boolean
description: "Boolean to enable providing the GITHUB_TOKEN to downstream job."
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 }}
run: |
for i in "${{ inputs.macos_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: Pre-build
run: ${{ inputs.macos_pre_build_command }}
- name: Build / Test [debug]
run: ${{ inputs.macos_build_command }} ${{ (contains(matrix.swift_version, 'nightly') && inputs.swift_nightly_flags) || inputs.swift_flags }}
timeout-minutes: 60
- name: Build / Test [release]
if: ${{ inputs.enable_release_tests }}
run: ${{ inputs.macos_release_build_command }} ${{ (contains(matrix.swift_version, 'nightly') && inputs.swift_nightly_flags) || inputs.swift_flags }}
linux-build:
name: Linux (${{ matrix.swift_version }} - ${{ matrix.os_version }})
if: ${{ inputs.enable_linux_checks }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
swift_version: ${{ fromJson(inputs.linux_swift_versions) }}
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
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.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 }}
- name: Build / Test [release]
if: ${{ inputs.enable_release_tests }}
run: ${{ inputs.linux_release_build_command }} ${{ (contains(matrix.swift_version, 'nightly') && inputs.swift_nightly_flags) || inputs.swift_flags }}
windows-build:
name: Windows (${{ matrix.swift_version }} - ${{ inputs.enable_windows_docker && contains(matrix.swift_version, 'nightly') && 'windows-2019' || 'windows-2022' }})
if: ${{ inputs.enable_windows_checks }}
runs-on: ${{ inputs.enable_windows_docker && contains(matrix.swift_version, 'nightly') && 'windows-2019' || 'windows-2022' }}
strategy:
fail-fast: false
matrix:
swift_version: ${{ fromJson(inputs.windows_swift_versions) }}
exclude:
- ${{ fromJson(inputs.windows_exclude_swift_versions) }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- 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 }}
run: |
$lines = "${{ inputs.windows_env_vars }}" -split "`r`n"
foreach ($line in $lines) {
echo $line | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
}
- 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-1809"
} else {
$Image = "swift:${{ matrix.swift_version }}-windowsservercore-ltsc2022"
}
docker pull $Image
echo "image=$Image" >> "$env:GITHUB_OUTPUT"
- name: Install Visual Studio Build Tools
if: ${{ !inputs.enable_windows_docker }}
run: |
Invoke-WebRequest -Uri https://raw.githubusercontent.com/swiftlang/github-workflows/refs/heads/main/.github/workflows/scripts/windows/install-vsb.ps1 -OutFile $env:TEMP\install-vsb.ps1
. $env:TEMP\install-vsb.ps1
del $env:TEMP\install-vsb.ps1
- name: Install Swift
if: ${{ !inputs.enable_windows_docker }}
run: |
Invoke-WebRequest -Uri https://raw.githubusercontent.com/swiftlang/github-workflows/refs/heads/main/.github/workflows/scripts/windows/swift/install-swift.ps1 -OutFile $env:TEMP\install-swift.ps1
Invoke-WebRequest -Uri https://raw.githubusercontent.com/swiftlang/github-workflows/refs/heads/main/.github/workflows/scripts/windows/swift/install-swift-${{ matrix.swift_version }}.ps1 -OutFile $env:TEMP\install-swift-${{ matrix.swift_version }}.ps1
. $env:TEMP\install-swift-${{ matrix.swift_version }}.ps1
del $env:TEMP\install-swift*.ps1
- name: Create test script
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 cd $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
# Docker build
- name: Docker Build / Test
timeout-minutes: 60
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: 60
if: ${{ !inputs.enable_windows_docker }}
run: |
Import-Module $env:ChocolateyInstall\helpers\chocolateyProfile.psm1
RefreshEnv
powershell.exe -NoLogo -File $env:TEMP\test-script\run.ps1; exit $LastExitCode