https://github.com/mxcl/get-swift-version
https://github.com/mxcl/get-swift-version
Last synced: over 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/mxcl/get-swift-version
- Owner: mxcl
- Created: 2021-06-23T15:19:58.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2024-02-22T11:03:21.000Z (over 2 years ago)
- Last Synced: 2025-03-25T02:12:14.583Z (over 1 year ago)
- Language: JavaScript
- Size: 122 KB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# mxcl/get-swift-version
A multiplatform action to extract the active Swift version into various step outputs.
## [Sponsor @mxcl](https://github.com/sponsors/mxcl)
I can only afford to maintain projects I need or that are sponsored. Thanks.
## Usage
```yaml
jobs:
my-job:
runs-on: ubuntu-latest
steps:
- use: mxcl/get-swift-version@v1
id: swift
- run: echo ${{ steps.swift.outputs.version }}
- run: echo ${{ steps.swift.outputs.major-version }}
- run: echo ${{ steps.swift.outputs.minor-version }}
- run: echo ${{ steps.swift.outputs.patch-version }}
- run: echo ${{ steps.swift.outputs.marketing-version }}
```
Will output:
```
5.4.1
5
4
1
5.4
```
## Enforce Swift Version
Optionally this action can enforce an expected Swift version:
```yaml
jobs:
my-job:
runs-on: ubuntu-latest
steps:
- use: mxcl/get-swift-version@v1
with:
requires: ~5.4 # a semantically versioned constraint
```
If the Swift version is not >=5.4 and < 5.5 the action will fail.
# Suggested with `actions/cache`
```yaml
- uses: mxcl/get-swift-version@v1
id: swift
- uses: actions/cache@v2
with:
path: .build
key: ${{ runner.os }}-swift-${{ steps.swift.outputs.marketing-version }}-${{ hashFiles('Package.resolved') }}
restore-keys: ${{ runner.os }}-swift-${{ steps.swift.outputs.marketing-version }}
if: ${{ steps.swift.outputs.marketing-version > 5.1 }}
```
With Swift >=5.5 this will save you quite a bit of build time while ensuring major changes
to the build files formats with new marketing versions will not break your CI.
# The `marketing-version` is more useful than you think
```yaml
jobs:
my-job:
runs-on: ubuntu-latest
steps:
- use: mxcl/get-swift-version@v1
id: swift
- run: echo ARGS=--enable-code-coverage >> $GITHUB_ENV
if: ${{ steps.swift.outputs.marketing-version > 5.1 }}
```
Because `marketing-version` is always “floaty”, GHA can do a numeric comparison operator on it.