Skip to content

Commit ff6dea9

Browse files
authored
[CI] Add Windows matrix build (#2929)
# Motivation In the long term we want to add support for Windows in our Swift packages. To do this we need a CI setup to ensure that our packages are building and the tests are passing. # Modification This PR adds a windows job to our swift matrix that installs Swift on the runner and then uses Swift PM to build and test the package. Windows jobs are disabled by default since most of our packages require some work to add Windows support. # Result We have a Windows CI pipeline that allows us to verify that our packages are working.
1 parent 8666af5 commit ff6dea9

File tree

3 files changed

+196
-0
lines changed

3 files changed

+196
-0
lines changed

.github/workflows/swift_matrix.yml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,32 @@ on:
6767
type: string
6868
description: "The command of the nightly main Swift version linux matrix job to execute."
6969

70+
matrix_windows_command:
71+
type: string
72+
description: "The command of the current Swift version windows matrix job to execute."
73+
default: ""
74+
matrix_windows_6_0_enabled:
75+
type: boolean
76+
description: "Boolean to enable the 6.0 Swift version matrix job. Defaults to true."
77+
default: false
78+
matrix_windows_6_0_command_override:
79+
type: string
80+
description: "The command of the 6.0 Swift version windows matrix job to execute."
81+
matrix_windows_nightly_6_0_enabled:
82+
type: boolean
83+
description: "Boolean to enable the nightly 6.0 Swift version matrix job. Defaults to true."
84+
default: false
85+
matrix_windows_nightly_6_0_command_override:
86+
type: string
87+
description: "The command of the nightly 6.0 Swift version windows matrix job to execute."
88+
matrix_windows_nightly_main_enabled:
89+
type: boolean
90+
description: "Boolean to enable the nightly main Swift version matrix job. Defaults to true."
91+
default: false
92+
matrix_windows_nightly_main_command_override:
93+
type: string
94+
description: "The command of the nightly main Swift version windows matrix job to execute."
95+
7096
# We are cancelling previously triggered workflow runs
7197
concurrency:
7298
group: ${{ github.workflow }}-${{ github.ref }}-${{ inputs.name }}
@@ -121,3 +147,64 @@ jobs:
121147
run: |
122148
apt-get -qq update && apt-get -qq -y install curl
123149
curl -s https://raw.githubusercontent.com/apple/swift-nio/main/scripts/check-matrix-job.sh | bash
150+
151+
windows:
152+
name: Windows (${{ matrix.swift.swift_version }})
153+
runs-on: windows-2022
154+
if: ${{ inputs.matrix_windows_6_0_enabled }}
155+
strategy:
156+
fail-fast: false
157+
matrix:
158+
# We are specifying only the major and minor of the docker images to automatically pick up the latest patch release
159+
swift:
160+
- image: swift:6.0-windowsservercore-ltsc2022
161+
swift_version: "6.0"
162+
enabled: ${{ inputs.matrix_windows_6_0_enabled }}
163+
steps:
164+
- name: Pull Docker image
165+
if: ${{ matrix.swift.enabled }}
166+
run: docker pull ${{ matrix.swift.image }}
167+
- name: Checkout repository
168+
if: ${{ matrix.swift.enabled }}
169+
uses: actions/checkout@v4
170+
with:
171+
persist-credentials: false
172+
- name: Donwload matrix script
173+
if: ${{ matrix.swift.enabled }}
174+
run: curl -s https://raw.githubusercontent.com/apple/swift-nio/main/scripts/check-matrix-job.ps1 -o __check-matrix-job.ps1
175+
- name: Run matrix job
176+
if: ${{ matrix.swift.enabled }}
177+
run: |
178+
docker run --env SWIFT_VERSION="${{ matrix.swift.swift_version }}" --env COMMAND="${{ inputs.matrix_windows_command }}" --env COMMAND_OVERRIDE_6_0="${{ inputs.matrix_windows_6_0_command_override }}" -v ${{ github.workspace }}:C:\source ${{ matrix.swift.image }} cmd /s /c "swift --version & cd C:\source\ & powershell -File __check-matrix-job.ps1"
179+
180+
windows-nightly:
181+
name: Windows (${{ matrix.swift.swift_version }})
182+
runs-on: windows-2019
183+
if: ${{ inputs.matrix_windows_nightly_6_0_enabled }} && ${{ inputs.matrix_windows_nightly_main_enabled }}
184+
strategy:
185+
fail-fast: false
186+
matrix:
187+
# We are specifying only the major and minor of the docker images to automatically pick up the latest patch release
188+
swift:
189+
- image: swiftlang/swift:nightly-6.0-windowsservercore-1809
190+
swift_version: "nightly-6.0"
191+
enabled: ${{ inputs.matrix_windows_nightly_6_0_enabled }}
192+
- image: swiftlang/swift:nightly-main-windowsservercore-1809
193+
swift_version: "nightly-main"
194+
enabled: ${{ inputs.matrix_windows_nightly_main_enabled }}
195+
steps:
196+
- name: Pull Docker image
197+
if: ${{ matrix.swift.enabled }}
198+
run: docker pull ${{ matrix.swift.image }}
199+
- name: Checkout repository
200+
if: ${{ matrix.swift.enabled }}
201+
uses: actions/checkout@v4
202+
with:
203+
persist-credentials: false
204+
- name: Donwload matrix script
205+
if: ${{ matrix.swift.enabled }}
206+
run: curl -s https://raw.githubusercontent.com/apple/swift-nio/main/scripts/check-matrix-job.ps1 -o __check-matrix-job.ps1
207+
- name: Run matrix job
208+
if: ${{ matrix.swift.enabled }}
209+
run: |
210+
docker run --env SWIFT_VERSION="${{ matrix.swift.swift_version }}" --env COMMAND="${{ inputs.matrix_windows_command }}" --env COMMAND_OVERRIDE_NIGHTLY_6_0="${{ inputs.matrix_windows_nightly_6_0_command_override }}" --env COMMAND_OVERRIDE_NIGHTLY_MAIN="${{ inputs.matrix_windows_nightly_main_command_override }}" -v ${{ github.workspace }}:C:\source ${{ matrix.swift.image }} cmd /s /c "swift --version & cd C:\source\ & powershell -File __check-matrix-job.ps1"

.github/workflows/unit_tests.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,31 @@ on:
4444
description: "The arguments passed to swift test in the Linux nightly main Swift version matrix job."
4545
default: ""
4646

47+
windows_6_0_enabled:
48+
type: boolean
49+
description: "Boolean to enable the Windows 6.0 Swift version matrix job. Defaults to true."
50+
default: false
51+
windows_6_0_arguments_override:
52+
type: string
53+
description: "The arguments passed to swift test in the Windows 6.0 Swift version matrix job."
54+
default: ""
55+
windows_nightly_6_0_enabled:
56+
type: boolean
57+
description: "Boolean to enable the Windows nightly 6.0 Swift version matrix job. Defaults to true."
58+
default: false
59+
windows_nightly_6_0_arguments_override:
60+
type: string
61+
description: "The arguments passed to swift test in the Windows nightly 6.0 Swift version matrix job."
62+
default: ""
63+
windows_nightly_main_enabled:
64+
type: boolean
65+
description: "Boolean to enable the Windows nightly main Swift version matrix job. Defaults to true."
66+
default: false
67+
windows_nightly_main_arguments_override:
68+
type: string
69+
description: "The arguments passed to swift test in the Windows nightly main Swift version matrix job."
70+
default: ""
71+
4772
jobs:
4873
unit-tests:
4974
name: Unit tests
@@ -62,3 +87,9 @@ jobs:
6287
matrix_linux_nightly_6_0_command_override: "swift test ${{ inputs.linux_nightly_6_0_arguments_override }}"
6388
matrix_linux_nightly_main_enabled: ${{ inputs.linux_nightly_main_enabled }}
6489
matrix_linux_nightly_main_command_override: "swift test ${{ inputs.linux_nightly_main_arguments_override }}"
90+
matrix_windows_6_0_enabled: ${{ inputs.windows_6_0_enabled }}
91+
matrix_windows_6_0_command_override: "swift test ${{ inputs.windows_6_0_arguments_override }}"
92+
matrix_windows_nightly_6_0_enabled: ${{ inputs.windows_nightly_6_0_enabled }}
93+
matrix_windows_nightly_6_0_command_override: "swift test ${{ inputs.windows_nightly_6_0_arguments_override }}"
94+
matrix_windows_nightly_main_enabled: ${{ inputs.windows_nightly_main_enabled }}
95+
matrix_windows_nightly_main_command_override: "swift test ${{ inputs.windows_nightly_main_arguments_override }}"

scripts/check-matrix-job.ps1

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
##===----------------------------------------------------------------------===##
2+
##
3+
## This source file is part of the SwiftNIO open source project
4+
##
5+
## Copyright (c) 2024 Apple Inc. and the SwiftNIO project authors
6+
## Licensed under Apache License v2.0
7+
##
8+
## See LICENSE.txt for license information
9+
## See CONTRIBUTORS.txt for the list of SwiftNIO project authors
10+
##
11+
## SPDX-License-Identifier: Apache-2.0
12+
##
13+
##===----------------------------------------------------------------------===##
14+
15+
# Set strict mode to catch errors
16+
Set-StrictMode -Version Latest
17+
18+
function Log {
19+
param (
20+
[string]$Message
21+
)
22+
Write-Host ("** " + $Message) -ForegroundColor Yellow
23+
}
24+
25+
function Error {
26+
param (
27+
[string]$Message
28+
)
29+
Write-Host ("** ERROR: " + $Message) -ForegroundColor Red
30+
}
31+
32+
function Fatal {
33+
param (
34+
[string]$Message
35+
)
36+
Error $Message
37+
exit 1
38+
}
39+
40+
# Check if SWIFT_VERSION is set
41+
if (-not $env:SWIFT_VERSION) {
42+
Fatal "SWIFT_VERSION unset"
43+
}
44+
45+
# Check if COMMAND is set
46+
if (-not $env:COMMAND) {
47+
Fatal "COMMAND unset"
48+
}
49+
50+
$swift_version = $env:SWIFT_VERSION
51+
$command = $env:COMMAND
52+
$command_5_9 = $env:COMMAND_OVERRIDE_5_9
53+
$command_5_10 = $env:COMMAND_OVERRIDE_5_10
54+
$command_6_0 = $env:COMMAND_OVERRIDE_6_0
55+
$command_nightly_6_0 = $env:COMMAND_OVERRIDE_NIGHTLY_6_0
56+
$command_nightly_main = $env:COMMAND_OVERRIDE_NIGHTLY_MAIN
57+
58+
if ($swift_version -eq "5.9" -and $command_5_9) {
59+
Log "Running 5.9 command override"
60+
Invoke-Expression $command_5_9
61+
} elseif ($swift_version -eq "5.10" -and $command_5_10) {
62+
Log "Running 5.10 command override"
63+
Invoke-Expression $command_5_10
64+
} elseif ($swift_version -eq "6.0" -and $command_6_0) {
65+
Log "Running 6.0 command override"
66+
Invoke-Expression $command_6_0
67+
} elseif ($swift_version -eq "nightly-6.0" -and $command_nightly_6_0) {
68+
Log "Running nightly 6.0 command override"
69+
Invoke-Expression $command_nightly_6_0
70+
} elseif ($swift_version -eq "nightly-main" -and $command_nightly_main) {
71+
Log "Running nightly main command override"
72+
Invoke-Expression $command_nightly_main
73+
} else {
74+
Log "Running default command"
75+
Invoke-Expression $command
76+
}
77+
78+
Exit $LASTEXITCODE

0 commit comments

Comments
 (0)