You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Modernize Swift CI tutorial (current versions, refreshed pins, cross-platform)
- Update example Swift versions from 5.2/5.3/5.3.3 to 5.10/6.0/6.1
- Refresh swift-actions/setup-swift pin from a 2021 commit to v2.4.0
- Add "Building and testing on Linux with a container" section, linking the
release (swift) and nightly (swiftlang/swift) Docker images, with a nightly example
- Add native "Building and testing for Apple platforms with Xcode" section (xcodebuild
+ simulator destinations), including how to check available Xcode/simulators on the
macOS runner and how to download missing platform runtimes
- Add "Building and testing on Windows" (compnerd/gha-setup-swift) and "Building and
testing on Android" (skiptools/swift-android-action) sections
- Add "Building and testing across multiple platforms with one action"
(brightdigit/swift-build) with per-platform examples for Apple, Linux, Windows,
Android, and WebAssembly, including the download-platform input
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
On {% data variables.product.prodname_dotcom %}-hosted Linux runners, you can run your job inside an official Swift container image, which already includes the Swift toolchain. This means you don't need a separate step to install Swift.
157
+
158
+
Released Swift versions are published as the [`swift`](https://hub.docker.com/_/swift) official images on Docker Hub (for example, `swift:6.3` or `swift:6.3-noble`). To test against unreleased toolchains, use the nightly snapshot images published as [`swiftlang/swift`](https://hub.docker.com/r/swiftlang/swift) (for example, `swiftlang/swift:nightly-main` or `swiftlang/swift:nightly-6.2-noble`). For more information, see [Swift on Docker](https://www.swift.org/documentation/docker/) on Swift.org.
159
+
160
+
```yaml copy
161
+
name: Swift
162
+
163
+
on: [push]
164
+
165
+
jobs:
166
+
linux:
167
+
runs-on: ubuntu-latest
168
+
container: swift:6.3
169
+
steps:
170
+
- uses: {% data reusables.actions.action-checkout %}
171
+
- name: Build
172
+
run: swift build
173
+
- name: Run tests
174
+
run: swift test
175
+
```
176
+
177
+
To test against a nightly toolchain, use a `swiftlang/swift` snapshot image instead.
178
+
179
+
```yaml copy
180
+
name: Swift
181
+
182
+
on: [push]
183
+
184
+
jobs:
185
+
nightly:
186
+
runs-on: ubuntu-latest
187
+
container: swiftlang/swift:nightly-main
188
+
steps:
189
+
- uses: {% data reusables.actions.action-checkout %}
190
+
- name: Build
191
+
run: swift build
192
+
- name: Run tests
193
+
run: swift test
194
+
```
195
+
196
+
## Building and testing for Apple platforms with Xcode
197
+
198
+
To build and test for a specific Apple platform such as iOS, watchOS, tvOS, or visionOS, use `xcodebuild` on a macOS runner and select a simulator with the `-destination` option. {% data variables.product.prodname_dotcom %}-hosted macOS runners come with Xcode and Apple platform simulators preinstalled. To check which Xcode versions, platform SDKs, OS versions, and simulators are available on each macOS runner, see [AUTOTITLE](/actions/using-github-hosted-runners/about-github-hosted-runners#supported-software).
199
+
200
+
```yaml copy
201
+
name: Swift
202
+
203
+
on: [push]
204
+
205
+
jobs:
206
+
ios:
207
+
runs-on: macos-latest
208
+
steps:
209
+
- uses: {% data reusables.actions.action-checkout %}
To target a different platform, change the `-destination` value. For example, use `platform=watchOS Simulator,name=Apple Watch Series 9 (45mm)`, `platform=tvOS Simulator,name=Apple TV`, `platform=visionOS Simulator,name=Apple Vision Pro`, or `platform=macOS` for native macOS. To select a specific installed Xcode version, run `sudo xcode-select -s /Applications/Xcode_16.4.app` before building.
218
+
219
+
If you target a platform whose simulator runtime is not preinstalled on the runner, the build fails until the runtime is available. Download it first with `xcodebuild -downloadPlatform iOS` (replacing `iOS` with the platform you need), or choose a simulator and OS version that the runner already provides.
220
+
221
+
## Building and testing on Windows
222
+
223
+
To build and test on Windows, install the Swift toolchain with the [`compnerd/gha-setup-swift`](https://github.com/compnerd/gha-setup-swift) action, then run `swift build` and `swift test`.
224
+
225
+
```yaml copy
226
+
227
+
{% data reusables.actions.actions-not-certified-by-github-comment %}
228
+
229
+
{% data reusables.actions.actions-use-sha-pinning-comment %}
- uses: {% data reusables.actions.action-checkout %}
244
+
- name: Build
245
+
run: swift build
246
+
- name: Run tests
247
+
run: swift test
248
+
```
249
+
250
+
## Building and testing on Android
251
+
252
+
To build and test on Android, use the [`skiptools/swift-android-action`](https://github.com/skiptools/swift-android-action) action, which installs the Swift SDK for Android and can run your tests on an emulator.
253
+
254
+
```yaml copy
255
+
256
+
{% data reusables.actions.actions-not-certified-by-github-comment %}
257
+
258
+
{% data reusables.actions.actions-use-sha-pinning-comment %}
259
+
260
+
name: Swift
261
+
262
+
on: [push]
263
+
264
+
jobs:
265
+
android:
266
+
runs-on: ubuntu-latest
267
+
steps:
268
+
- uses: {% data reusables.actions.action-checkout %}
## Building and testing across multiple platforms with one action
276
+
277
+
If you want to build and test across several of the platforms above from a single workflow, you can use a community action that wraps the platform-specific setup. For example, the [`brightdigit/swift-build`](https://github.com/brightdigit/swift-build) action can target macOS, Linux, Windows, Apple devices (iOS, watchOS, tvOS, and visionOS), Android, and WebAssembly, selected with its `type` input. It uses `xcodebuild` for Apple platforms, [`compnerd/gha-setup-swift`](https://github.com/compnerd/gha-setup-swift) for Windows, and [`skiptools/swift-android-action`](https://github.com/skiptools/swift-android-action) for Android.
278
+
279
+
```yaml copy
280
+
281
+
{% data reusables.actions.actions-not-certified-by-github-comment %}
282
+
283
+
{% data reusables.actions.actions-use-sha-pinning-comment %}
284
+
285
+
name: Swift
286
+
287
+
on: [push]
288
+
289
+
jobs:
290
+
test:
291
+
runs-on: macos-latest
292
+
steps:
293
+
- uses: {% data reusables.actions.action-checkout %}
To target a specific Apple platform, set the `type` input (`ios`, `watchos`, `tvos`, `visionos`, or `macos`) and, for simulator-based platforms, the `deviceName` and `osVersion`. To check which simulators and OS versions are preinstalled on each macOS runner, see [AUTOTITLE](/actions/using-github-hosted-runners/about-github-hosted-runners#supported-software). If the simulator runtime you request is not already installed on the runner, set `download-platform: true` so the action downloads it before testing.
302
+
303
+
```yaml copy
304
+
305
+
{% data reusables.actions.actions-not-certified-by-github-comment %}
306
+
307
+
{% data reusables.actions.actions-use-sha-pinning-comment %}
308
+
309
+
name: Swift
310
+
311
+
on: [push]
312
+
313
+
jobs:
314
+
ios:
315
+
runs-on: macos-latest
316
+
steps:
317
+
- uses: {% data reusables.actions.action-checkout %}
0 commit comments