"Install Swift" GitHub Action

Hi folks :wave: I’d like to pitch my GitHub Action slashmo/install-swift to be endorsed by the SSWG. The action lets you install any* version of Swift available on swift.org, while caching previously installed versions to make subsequent CI runs as fast as possible.

* While the action currently only supports Ubuntu I’d love to add support for other platforms as well. See future direction for more details.


Recently, I needed to test a Swift library using different toolchains, with both release and development versions on GitHub Actions. While there were actions available like fwal/setup-swift which use a hard-coded list of installable Swift versions, I wanted to create one that’s more dynamic so that users can specify any version available on swift.org/downloads.

install-swift will figure out which version of Ubuntu it runs on to assemble the correct download URL. Based on the combination of Ubuntu & Swift version, it caches the downloaded toolchain so that on future executions of the CI running in the same context, it can be downloaded directly from GitHub instead. This enables a significant speed-up. In a demo project using the action, the cached toolchain installed in 16 seconds as opposed to the original 41 seconds.

Future Direction

Support more platforms

GitHub Actions have three ways of running:

  1. Hosted runners (Ubuntu, macOS, Windows)
  2. Self-hosted runners (Supports other Linux distributions and architectures)
  3. Docker (Runs inside a given Docker container)

Currently, the action only supports the Ubuntu based GitHub Actions runners (that is ubuntu-18.04 & ubuntu-20.04). There shouldn’t be anything standing in the way of it also supporting other runners like macOS & Windows. This addition is already being tracked in GitHub Issues. We might also want to support all the distributions and architectures Swift is supported on, so that the action can also be useful for self-hosted runners and running in docker.

Support wildcard installs

If there’s interest, the action could also handle installing Swift versions based on wildcards like 5, then figure out the latest version of Swift 5 and install it.

To support this it would be nice for swift.org to expose some kind of list of all available versions. This could also enable wildcards like latest-main.

Example Workflow

Here’s an example of the action in action. You can check it out in the example repo: https://github.com/slashmo/xctest-async-linux/blob/main/.github/workflows/test.yaml

name: Test

    runs-on: ubuntu-20.04

    - name: Install Swift
      uses: slashmo/install-swift@v0.1.0
        version: swift-DEVELOPMENT-SNAPSHOT-2021-11-12-a

    - name: Checkout
      uses: actions/checkout@v2

    - name: Run Tests
      run: swift test --parallel

Further reading


Fantastic work, this looks great!

It would be very beneficial to have one "blessed" repo to consolidate all the efforts of doing this and we can collaborate there.

I know @compnerd also worked on the Windows portion of this: GitHub - compnerd/gha-setup-swift: Setup Swift (on Windows) on GitHub Actions Builders so we should combine the two efforts.


I'm especially excited about the ability to build with snapshot toolchains so easily :grinning_face_with_smiling_eyes:


Great work! +1 from me

This already exists today and is used when building the nightly docker images. For ubuntu 20.04 the lookup url is:


The url is constructed here:

Something similar can be found in all other nightly images as well.


Fabian I believe the latest.yml is only available for development builds. I don't know of any reporting of the latest version of a release.

If this GitHub action can be extended to support other Linux platforms, macOS and Windows it will be awesome. Well done @slashmo


Awesome @slashmo, thanks!

If the work of @futurejones (New Swift Package Repository for Ubuntu/Debian Linux Distributions) and @stevapple (GitHub - stevapple/swiftbox: Use Swift out of the Box on Ubuntu, CentOS(RHEL) and Amazon Linux) and this script would have an offspring that was officially blessed... :-)


Nice, I wrote a separate small CI job to get the latest Swift release, devel, and trunk toolchain for my Android CI on github Actions. I'd gladly switch to your setup instead, but it looks like you don't support the development tag builds from the release/5.5 branch yet. If you add that and a way to just get the latest of each sort of release or snapshot toolchain, I'll switch over to your Action.


As @ktoso mentioned, GitHub - compnerd/gha-setup-swift: Setup Swift (on Windows) on GitHub Actions Builders supports Windows. I've added Linux support as well to it, and I know that adding macOS is fairly trivial, just needs a bit of testing - I have something on a branch for that already).

The design choice difference was that I did not want the automatic update functionality. This is to ensure that re-runs of jobs use the same configuration and it is controllable (sometimes there is an issue in a snapshot, and you cannot control it if it is fully automatic). Yes, it could be the default is the latest, but to me it is less cognitive load to have everything be spelt out.

There is one thing that I dislike about my actions's implementation - namely the branch/tag pair feels like it should be possible to derive from a singular value. I'd be happy to have someone else help improve that if they are interested.

1 Like

This is great! +1

1 Like

cc @mishal_shah can help with that

also +1 great to see this

1 Like

You would think for people who work together would be better at talking :laughing: I've been sherlocked!

+1 from me, very useful and lots of extra features that can be added over time


Hi all! :wave:

I'm the author of the "setup-swift" action mentioned (GitHub - fwal/setup-swift: GitHub Action that setup a Swift environment).
Just wanted to pitch in that I think that a consolidated effort in this area would be great, it seems like the current different solutions all solve different parts of the equation of a fully fledged solution :slightly_smiling_face:

Terms of Service

Privacy Policy

Cookie Policy