Skip to content
You're viewing an older version of this GitHub Action. Do you want to see the latest version instead?
command

GitHub Action

Setup Swift

v1.9.1

Setup Swift

command

Setup Swift

Setup a Swift environment on Ubuntu or macOS

Installation

Copy and paste the following snippet into your .yml file.

              

- name: Setup Swift

uses: swift-actions/[email protected]

Learn more about this action in swift-actions/setup-swift

Choose a version

Setup Swift

GitHub Action Supports macOS and Ubuntu Swift 5.5 Latest release

GitHub Action that will setup a Swift environment with a specific version. Works on both Ubuntu and macOS runners.

Usage

To run the action with the latest swift version available, simply add the action as a step in your workflow:

- uses: fwal/setup-swift@v1

After the environment is configured you can run swift commands using the standard run step:

- uses: fwal/setup-swift@v1
- name: Get swift version
  run: swift --version # Swift 5.5

A specific Swift version can be set using the swift-version input:

- uses: fwal/setup-swift@v1
  with:
    swift-version: "5.1.0"
- name: Get swift version
  run: swift --version # Swift 5.1.0

Works perfect together with 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: fwal/setup-swift@v1
  with:
    swift-version: ${{ matrix.swift }}
- name: Get swift version
  run: swift --version

Note about versions

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 this 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.0" will resolve to version 5.1
  • "5.1" will resolve to latest patch version (aka 5.1.1)
  • "5" will resolve to latest minor and patch version (aka 5.5)

Caveats

YAML interprets eg. 5.0 as a float, this action will then interpret that as 5 which will result in eg. Swift 5.5 being resolved. Quote your inputs! Thus:

- uses: fwal/setup-swift@v1
  with:
    swift-version: '5.0'

Not:

- uses: fwal/setup-swift@v1
  with:
    swift-version: 5.0

Legal

Uses MIT license. The Swift logo is a trademark of Apple Inc.