GitHub Action
Setup Swift environment for macOS, Linux and Windows
GitHub Action that will setup Swift environment with specified version. This action supports the following functionalities:
- Works on Linux, macOS and Windows(Swift 5.10 and after not supported on Windows).
- Supports installing latest major/minor/patch.
- Provides snapshots as soon as published in
swift.org
. - Verifies toolchain snapshots before installation (
gpg
for Linux and Windows,pkgutil
for macOS) . - Allows development snapshots by enabling
development
flag and optional version. - Prefers existing Xcode installations.
- Caches installed setup in tool cache.
- Allows fetching snapshot metadata without installation (can be used to setup docker images).
Release Type | Latest Available |
---|---|
Stable | |
Development | |
Trunk Development |
To run the action with the latest stable release swift version available, simply add the action as a step in your workflow:
- uses: SwiftyLab/setup-swift@latest
Or use the latest development snapshots by enabling the development
flag:
- uses: SwiftyLab/setup-swift@latest
with:
development: true
After the environment is configured you can run swift and xcode commands using the standard run
step:
- uses: SwiftyLab/setup-swift@latest
- name: Get swift version
run: swift --version
- name: Get swift version in macOS
if: runner.os == 'macOS'
run: xcrun --toolchain ${{ env.TOOLCHAINS }} swift --version
A specific Swift version can be set using the swift-version
input, see the format:
- uses: SwiftyLab/setup-swift@latest
with:
swift-version: "5.1.0"
- name: Get swift version
run: swift --version # Swift 5.1.0
- name: Get swift version in macOS
if: runner.os == 'macOS'
run: xcrun --toolchain ${{ env.TOOLCHAINS }} swift --version # Swift 5.1.0
Works perfect together with job matrixes:
name: Swift ${{ matrix.swift }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
swift: ["5.4.3", "5.2.4"]
steps:
- uses: SwiftyLab/setup-swift@latest
with:
swift-version: ${{ matrix.swift }}
- name: Get swift version
run: swift --version
See action.yml for complete list of inputs and outputs.
This project uses strict semantic versioning to determine what version of Swift to configure. This differs slightly from the official convention used by Swift.
For example, Swift is available as version 5.1
but using this as value for swift-version
will be interpreted as a version range of 5.1.X
where X
is the latest patch version available for that major and minor version.
In other words specifying...
"5.1"
will resolve to latest patch version (aka5.1.5
)"5.1.0"
will resolve to version5.1
"4"
will resolve to latest minor and patch version (aka4.2.4
)"4.0.0"
will resolve to version4.0
YAML interprets eg. 4.0
as a float, this action will then interpret that as 4
which will result in eg. Swift 4.2.4
being resolved. Quote your inputs! Thus surround version input with quotations:
- uses: SwiftyLab/setup-swift@v1
with:
swift-version: '5.0'
Not:
- uses: SwiftyLab/setup-swift@v1
with:
swift-version: 5.0
You have two options for keeping this action up-to-date: either use the latest
tag to always have the latest changes or define a specific version (like v1.0.0
).
You can use the latest
tag to always have the latest changes. This action is updated automatically as soon as new toolchain snapshots are published in swift.org, by using the latest
tag you have access to these data automagically.
You can the specific version tag together with Dependabot to keep the action up-to-date. You will automatically get notifed when the action updates and you can read the changelog directly in the PR opened by dependabot.
setup-swift
is released under the MIT license. See LICENSE for details.
The Swift logo is a trademark of Apple Inc.