Hi folks 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.
GitHub Actions have three ways of running:
- Hosted runners (Ubuntu, macOS, Windows)
- Self-hosted runners (Supports other Linux distributions and architectures)
- Docker (Runs inside a given Docker container)
Currently, the action only supports the Ubuntu based GitHub Actions runners (that is
ubuntu-20.04). There shouldn’t be anything standing in the way of it also supporting other runners like
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.
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
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 on: push: jobs: test: runs-on: ubuntu-20.04 steps: - name: Install Swift uses: email@example.com with: version: swift-DEVELOPMENT-SNAPSHOT-2021-11-12-a - name: Checkout uses: actions/checkout@v2 - name: Run Tests run: swift test --parallel