Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/swiftylab/setup-swift
GitHub Action to setup Swift environment
https://github.com/swiftylab/setup-swift
action actions ci github-actions setup-swift setup-swift-action swift swift-package-manager swift-server swift-windows
Last synced: about 5 hours ago
JSON representation
GitHub Action to setup Swift environment
- Host: GitHub
- URL: https://github.com/swiftylab/setup-swift
- Owner: SwiftyLab
- License: mit
- Created: 2023-08-24T14:11:50.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-01-01T07:43:08.000Z (about 1 month ago)
- Last Synced: 2025-01-01T08:19:11.359Z (about 1 month ago)
- Topics: action, actions, ci, github-actions, setup-swift, setup-swift-action, swift, swift-package-manager, swift-server, swift-windows
- Language: TypeScript
- Homepage: https://github.com/marketplace/actions/setup-swift-environment-for-macos-linux-and-windows
- Size: 4.86 MB
- Stars: 12
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Setup Swift
[![GitHub Action](https://img.shields.io/github/v/tag/SwiftyLab/setup-swift?logo=github&label=GitHub)](https://github.com/marketplace/actions/setup-swift-environment-for-macos-linux-and-windows)
[![Supports macOS, Linux & Windows](https://img.shields.io/badge/platform-macOS%20%7C%20Linux%20%7C%20Windows-blue?label=platform)](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/virtual-environments-for-github-hosted-runners#supported-runners-and-hardware-resources)
[![CI/CD](https://github.com/SwiftyLab/setup-swift/actions/workflows/main.yml/badge.svg)](https://github.com/SwiftyLab/setup-swift/actions/workflows/main.yml)
[![CodeFactor](https://www.codefactor.io/repository/github/swiftylab/setup-swift/badge)](https://www.codefactor.io/repository/github/swiftylab/setup-swift)
[![codecov](https://codecov.io/gh/SwiftyLab/setup-swift/graph/badge.svg?token=XWfSpWQ6gC)](https://codecov.io/gh/SwiftyLab/setup-swift)
[![Get it from Marketplace](https://img.shields.io/badge/Get_it-from_Marketplace-blue?logo=github)](https://github.com/marketplace/actions/setup-swift-environment-for-macos-linux-and-windows)[GitHub Action](https://github.com/features/actions) that will setup [Swift](https://swift.org) environment with specified version.
This action supports the following functionalities:- Works on Linux, macOS and Windows.
- Supports [installing latest major/minor/patch](#specifying-version).
- 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 and actions cache(Swift 5.10 and after does not support caching on Windows).
- Allows fetching snapshot metadata without installation (can be used to setup docker images).## Latest supported toolchains
| Release Type | Latest Available |
|--------------|------------------|
| Stable | [![Latest Release](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fswiftylab.github.io%2Fsetup-swift%2Fmetadata.json&query=%24.release.name&logo=swift&logoColor=white&label=Swift&color=orange)](https://www.swift.org/download/#releases)
[![Latest Release Tag](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fswiftylab.github.io%2Fsetup-swift%2Fmetadata.json&query=%24.release.tag&logo=swift&logoColor=white&label=tag&color=orange)](https://www.swift.org/download/#releases) |
| Development | [![Latest Development Snapshot](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fswiftylab.github.io%2Fsetup-swift%2Fmetadata.json&query=%24.dev.name&logo=swift&logoColor=white&label=Swift&color=orange)](https://www.swift.org/download/#snapshots)
[![Latest Development Snapshot Tag](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fswiftylab.github.io%2Fsetup-swift%2Fmetadata.json&query=%24.dev.tag&logo=swift&logoColor=white&label=tag&color=orange)](https://www.swift.org/download/#snapshots)
[![Latest Development Snapshot Date](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fswiftylab.github.io%2Fsetup-swift%2Fmetadata.json&query=%24.dev.date&logo=swift&logoColor=white&label=date)](https://www.swift.org/download/#snapshots) |
| Trunk Development | [![Latest Trunk Development Snapshot Tag](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fswiftylab.github.io%2Fsetup-swift%2Fmetadata.json&query=%24.snapshot.tag&logo=swift&logoColor=white&label=tag&color=orange)](https://www.swift.org/download/#snapshots)
[![Latest Trunk Development Snapshot Date](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fswiftylab.github.io%2Fsetup-swift%2Fmetadata.json&query=%24.snapshot.date&logo=swift&logoColor=white&label=date)](https://www.swift.org/download/#snapshots) |## Usage
To run the action with the latest stable release swift version available, simply add the action as a step in your workflow:
```yml
- uses: SwiftyLab/setup-swift@latest
```Or use the latest development snapshots by enabling the `development` flag:
```yml
- uses: SwiftyLab/setup-swift@latest
with:
development: true
```After the environment is configured you can run swift and xcode commands using the standard [`run`](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions#jobsjob_idstepsrun) step:
```yml
- 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](#specifying-version):
```yml
- 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:
```yml
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](action.yml) for complete list of inputs and outputs, see [wiki](https://github.com/SwiftyLab/setup-swift/wiki) for inner workings of this action.**
## Specifying version
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 (aka `5.1.5`)
- `"5.1.0"` will resolve to version `5.1`
- `"4"` will resolve to latest minor and patch version (aka `4.2.4`)
- `"4.0.0"` will resolve to version `4.0`Additionally, to use custom toolchains, download URL can be provided. The download URL must point to a `tar` archive for `Linux`, `pkg` file for `macOS` and `exe` file for `Windows`.
i.e. for `macOS`: https://github.com/swiftwasm/swift/releases/download/swift-wasm-5.10-SNAPSHOT-2024-03-30-a/swift-wasm-5.10-SNAPSHOT-2024-03-30-a-macos_x86_64.pkg
for `Linux`: https://github.com/swiftwasm/swift/releases/download/swift-wasm-5.10-SNAPSHOT-2024-03-30-a/swift-wasm-5.10-SNAPSHOT-2024-03-30-a-ubuntu22.04_x86_64.tar.gz> [!IMPORTANT]
> When using custom toolchains, please ensure that the toolchain can be installed and used on the GitHub runner, this action won't be able to validate this for custom toolchains.### Caveats
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:
```yml
- uses: SwiftyLab/setup-swift@v1
with:
swift-version: '5.0'
```Not:
```yml
- uses: SwiftyLab/setup-swift@v1
with:
swift-version: 5.0
```## Keeping the action up-to-date
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`).
### Latest version tag (Recommended)
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](https://github.com/apple/swift-org-website), by using the `latest` tag you have access to these data automagically.
### Specific version
You can the specific version tag together with [Dependabot](https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/about-dependabot-version-updates) 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.
## License
`setup-swift` is released under the MIT license. [See LICENSE](LICENSE) for details.
The Swift logo is a trademark of Apple Inc.