1+ name : Swift Linux Matrix
2+
3+ on :
4+ workflow_call :
5+ inputs :
6+ linux_exclude_swift_versions :
7+ type : string
8+ description : " Exclude Linux Swift version list (JSON)"
9+ default : " [{\" swift_version\" : \"\" }]"
10+ linux_os_versions :
11+ type : string
12+ description : " Linux OS version list (JSON)"
13+ default : " [\" jammy\" ]"
14+ windows_exclude_swift_versions :
15+ type : string
16+ description : " Exclude Windows Swift version list (JSON)"
17+ default : " [{\" swift_version\" : \"\" }]"
18+ swift_flags :
19+ type : string
20+ description : " Swift flags for release version"
21+ default : " "
22+ swift_nightly_flags :
23+ type : string
24+ description : " Swift flags for nightly version"
25+ default : " "
26+ linux_pre_build_command :
27+ type : string
28+ description : " Linux command to execute before building the Swift package"
29+ default : " "
30+ linux_build_command :
31+ type : string
32+ description : " Linux command to build and test the package"
33+ default : " swift test"
34+ windows_pre_build_command :
35+ type : string
36+ description : " Windows Command Prompt command to execute before building the Swift package"
37+ default : " "
38+ windows_build_command :
39+ type : string
40+ description : " Windows Command Prompt command to build and test the package"
41+ default : " swift test"
42+ linux_env_vars :
43+ description : " List of environment variables"
44+ type : string
45+ windows_env_vars :
46+ description : " List of environment variables"
47+ type : string
48+ enable_linux_checks :
49+ type : boolean
50+ description : " Boolean to enable linux testing. Defaults to true"
51+ default : true
52+ enable_windows_checks :
53+ type : boolean
54+ description : " Boolean to enable windows testing. Defaults to true"
55+ default : true
56+ enable_windows_docker :
57+ type : boolean
58+ description : " Boolean to enable running build in windows docker container. Defaults to true"
59+ default : true
60+
61+ jobs :
62+ linux-build :
63+ name : Linux (${{ matrix.swift_version }} - ${{ matrix.os_version }})
64+ if : ${{ inputs.enable_linux_checks }}
65+ runs-on : ubuntu-latest
66+ strategy :
67+ fail-fast : false
68+ matrix :
69+ swift_version : ['5.8', '5.9', '5.10', '6.0', 'nightly-main', 'nightly-6.0']
70+ os_version : ${{ fromJson(inputs.linux_os_versions) }}
71+ exclude :
72+ - ${{ fromJson(inputs.linux_exclude_swift_versions) }}
73+ container :
74+ image : ${{ (contains(matrix.swift_version, 'nightly') && 'swiftlang/swift') || 'swift' }}:${{ matrix.swift_version }}-${{ matrix.os_version }}
75+ steps :
76+ - name : Swift version
77+ run : swift --version
78+ - name : Checkout repository
79+ uses : actions/checkout@v4
80+ - name : Set environment variables
81+ if : ${{ inputs.linux_env_vars }}
82+ run : |
83+ for i in "${{ inputs.linux_env_vars }}"
84+ do
85+ printf "%s\n" $i | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
86+ done
87+ - name : Pre-build
88+ run : ${{ inputs.linux_pre_build_command }}
89+ - name : Build / Test
90+ run : ${{ inputs.linux_build_command }} ${{ (contains(matrix.swift_version, 'nightly') && inputs.swift_nightly_flags) || inputs.swift_flags }}
91+
92+ windows-build :
93+ name : Windows (${{ matrix.swift_version }} - windows-2022)
94+ if : ${{ inputs.enable_windows_checks }}
95+ runs-on : ${{ contains(matrix.swift_version, 'nightly') && 'windows-2019' || 'windows-2022' }}
96+ outputs :
97+ image : ${{ steps.pull_docker_image.outputs.image }}
98+ strategy :
99+ fail-fast : false
100+ matrix :
101+ swift_version : ['5.9', '5.10', '6.0', 'nightly', 'nightly-6.0']
102+ exclude :
103+ - ${{ fromJson(inputs.windows_exclude_swift_versions) }}
104+ steps :
105+ - name : Checkout repository
106+ uses : actions/checkout@v4
107+ - name : Set environment variables
108+ if : ${{ inputs.windows_env_vars }}
109+ run : |
110+ $lines = "${{ inputs.windows_env_vars }}" -split "`r`n"
111+ foreach ($line in $lines) {
112+ echo $line | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
113+ }
114+ - name : Pull Docker image
115+ id : pull_docker_image
116+ if : ${{ inputs.enable_windows_docker }}
117+ run : |
118+ if ("${{ matrix.swift_version }}".Contains("nightly")) {
119+ $Image = "swiftlang/swift:${{ matrix.swift_version }}-windowsservercore-1809"
120+ } else {
121+ $Image = "swift:${{ matrix.swift_version }}-windowsservercore-ltsc2022"
122+ }
123+ docker pull $Image
124+ echo "image='$Image'" >> $env:GITHUB_OUTPUT
125+ cat "$env:GITHUB_OUTPUT"
126+ - name : Install Visual Studio Build Tools
127+ if : ${{ !inputs.enable_windows_docker }}
128+ run : . .github\workflows\scripts\windows\install-vsb.ps1
129+ - name : Install Swift
130+ if : ${{ !inputs.enable_windows_docker }}
131+ run : . .github\workflows\scripts\windows\swift\install-swift-${{ matrix.swift_version }}.ps1
132+ - name : Create test script
133+ run : |
134+ mkdir $env:TEMP\test-script
135+ echo 'Set-PSDebug -Trace 1' >> $env:TEMP\test-script\run.ps1
136+ echo '$ErrorActionPreference = "Stop"' >> $env:TEMP\test-script\run.ps1
137+ echo 'swift --version' >> $env:TEMP\test-script\run.ps1
138+ echo 'swift test --version' >> $env:TEMP\test-script\run.ps1
139+ echo 'cd C:\source\' >> $env:TEMP\test-script\run.ps1
140+ echo @'
141+ ${{ inputs.windows_pre_build_command }}
142+ '@ >> $env:TEMP\test-script\run.ps1
143+ echo '${{ inputs.windows_build_command }} ${{ (contains(matrix.swift_version, 'nightly') && inputs.swift_nightly_flags) || inputs.swift_flags }}' >> $env:TEMP\test-script\run.ps1
144+ # Docker build
145+ - name : Build / Test
146+ timeout-minutes : 60
147+ if : ${{ !inputs.enable_windows_docker }}
148+ run : |
149+ if ("${{ matrix.swift_version }}".Contains("nightly")) {
150+ $Image = "swiftlang/swift:${{ matrix.swift_version }}-windowsservercore-1809"
151+ } else {
152+ $Image = "swift:${{ matrix.swift_version }}-windowsservercore-ltsc2022"
153+ }
154+ docker run -v ${{ github.workspace }}:C:\source -v $env:TEMP\test-script:C:\test-script "$Image" powershell.exe -NoLogo -File C:\test-script\run.ps1
155+ # Docker-less build
156+ - name : Build / Test
157+ timeout-minutes : 60
158+ if : ${{ inputs.enable_windows_docker }}
159+ run : . $env:TEMP\test-script\run.ps1
0 commit comments