Skip to content

Commit 461d602

Browse files
authored
GHA: rename parameters
Rename the `branch` and `tag` to `swift-version` and `swift-build` to aid in clarity. Additionally, correct the custom source handling on macOS and Linux. Fixes: #19
1 parent 8e4876a commit 461d602

File tree

3 files changed

+101
-32
lines changed

3 files changed

+101
-32
lines changed

.github/workflows/test-install.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ jobs:
2828
- name: Install Swift
2929
uses: ./
3030
with:
31-
branch: development
32-
tag: DEVELOPMENT-SNAPSHOT-2025-02-24-a
31+
swift-version: development
32+
swift-build: DEVELOPMENT-SNAPSHOT-2025-08-26-a
3333

3434
- name: Check Swift version
3535
run: swift --version
@@ -58,8 +58,8 @@ jobs:
5858
- name: Install Swift without the IDE component
5959
uses: ./
6060
with:
61-
branch: development
62-
tag: DEVELOPMENT-SNAPSHOT-2025-02-24-a
61+
swift-version: development
62+
swift-build: DEVELOPMENT-SNAPSHOT-2025-08-26-a
6363
installer-args: OptionsInstallIDE=0
6464

6565
- name: Assert that we find swiftc.exe

README.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ Setup Swift (on Windows) on GitHub Actions Builders
33

44
Automates installation of the Swift toolchain for Windows hosts on GitHub Actions runners.
55

6-
## Usage
7-
86
> [!NOTE]
97
> Windows requires Swift 5.4.2+
108
9+
## Usage
10+
1111
* Sample workflow using official Swift releases
1212

1313
```yaml
@@ -19,8 +19,8 @@ jobs:
1919
steps:
2020
- uses: compnerd/gha-setup-swift@main
2121
with:
22-
branch: swift-5.5-release
23-
tag: 5.5-RELEASE
22+
swift-version: swift-5.5-release
23+
swift-build: 5.5-RELEASE
2424

2525
- uses: actions/checkout@v2
2626
- run: swift build
@@ -50,14 +50,15 @@ jobs:
5050
### Parameters
5151
5252
#### When using official Swift releases:
53-
- `branch`: (**Note:** this is not a git branch name) the Swift "version" to be installed. This may be either a pre-release branch (e.g. `swift-5.5-branch`), a release branch (e.g. `swift-5.5-release`) or the development branch (`swift-development`).
54-
- `tag`: (**Note:** this is not a git tag name) the actual build tag to install, minus the “`swift-`” prefix. May indicate a release snapshot (e.g. `5.5-DEVELOPMENT-SNAPSHOT-2021-09-18-a`), development snapshot (e.g. `DEVELOPMENT-SNAPSHOT-2021-09-28-a`), or a release (e.g. `5.5-RELEASE`).
53+
- `swift-version`: (**Note:** this is not a git branch name) the Swift "version" to be installed. This may be either a pre-release branch (e.g. `swift-5.5-branch`), a release branch (e.g. `swift-5.5-release`) or the development branch (`swift-development`).
54+
- `swift-build`: (**Note:** this is not a git tag name) the actual build tag to install, minus the "`swift-`" prefix. May indicate a release snapshot (e.g. `5.5-DEVELOPMENT-SNAPSHOT-2021-09-18-a`), development snapshot (e.g. `DEVELOPMENT-SNAPSHOT-2021-09-28-a`), or a release (e.g. `5.5-RELEASE`).
55+
56+
#### Deprecated Parameters (will be removed in a future version):
57+
- `branch`: **[DEPRECATED]** Use `swift-version` instead.
58+
- `tag`: **[DEPRECATED]** Use `swift-build` instead.
5559

5660
#### When using Swift builds from a Github repository release:
5761
- `github-repo`: Github repo in "owner/repo" format
58-
5962
- `release-tag-name`: Release tag name, can be found in `github.com/<owner>/<repo>/releases`
60-
6163
- `release-asset-name`: Asset name for the Swift installer executable in the release
62-
6364
- `github-token`: Optional Github token for fetching a release from a private repository

action.yml

Lines changed: 87 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,25 @@ inputs:
1212
- custom
1313

1414
# for swift.org toolchains:
15-
branch:
16-
description: 'Branch for swift.org builds. Only specifiy when using official Swift toolchains from swift.org'
15+
swift-version:
16+
description: 'Swift version identifier for swift.org builds (e.g., swift-5.5-release, development). Only specify when using official Swift toolchains from swift.org'
1717
required: false
18-
tag:
19-
description: 'Tag for swift.org builds. Only specifiy when using official Swift toolchains from swift.org'
18+
swift-build:
19+
description: 'Swift build identifier for swift.org builds (e.g., 5.5-RELEASE, DEVELOPMENT-SNAPSHOT-2021-09-18-a). Only specify when using official Swift toolchains from swift.org'
2020
required: false
2121
build_arch:
22-
description: 'Build architecture (amd64 or arm64). Only specifiy when using official Swift toolchains from swift.org'
22+
description: 'Build architecture (amd64 or arm64). Only specify when using official Swift toolchains from swift.org'
2323
default: 'amd64'
2424
required: true
2525

26+
# deprecated parameters (for backward compatibility)
27+
branch:
28+
description: '[DEPRECATED] Use swift-version instead. Branch for swift.org builds. Only specify when using official Swift toolchains from swift.org'
29+
required: false
30+
tag:
31+
description: '[DEPRECATED] Use swift-build instead. Tag for swift.org builds. Only specify when using official Swift toolchains from swift.org'
32+
required: false
33+
2634
# for custom toolchains:
2735
github-repo:
2836
description: 'Github repo in "owner/repo" format. Only specify when using custom toolchains from Github releases.'
@@ -46,6 +54,66 @@ inputs:
4654
runs:
4755
using: 'composite'
4856
steps:
57+
- name: Handle deprecated parameters and validate inputs
58+
run: |
59+
# Handle backward compatibility for deprecated parameters
60+
$SwiftVersion = "${{ inputs.swift-version }}"
61+
$SwiftBuild = "${{ inputs.swift-build }}"
62+
63+
# Ensure that only the deprecated or the new parameter set is used at one time.
64+
$errors = @(
65+
if (![String]::IsNullOrEmpty("${{ inputs.branch }}") -and ![String]::IsNullOrEmpty($SwiftVersion)) { "Cannot specify both 'branch' (deprecated) and 'swift-version'. Please use only 'swift-version'." }
66+
if (![String]::IsNullOrEmpty("${{ inputs.tag }}") -and ![String]::IsNullOrEmpty($SwiftBuild)) { "Cannot specify both 'tag' (deprecated) and 'swift-build'. Please use only 'swift-build'." }
67+
)
68+
foreach ($error in $errors) { Write-Host "::error::$error" }
69+
if ($errors) { exit 1 }
70+
71+
# Handle deprecated parameters with warnings.
72+
if (![String]::IsNullOrEmpty("${{ inputs.branch }}")) {
73+
Write-Host "::warning::The 'branch' input is deprecated and will be removed in a future version. Please use 'swift-version' instead."
74+
$SwiftVersion = "${{ inputs.branch }}"
75+
}
76+
77+
if (![String]::IsNullOrEmpty("${{ inputs.tag }}")) {
78+
Write-Host "::warning::The 'tag' input is deprecated and will be removed in a future version. Please use 'swift-build' instead."
79+
$SwiftBuild = "${{ inputs.tag }}"
80+
}
81+
82+
switch ("${{ inputs.source }}") {
83+
"swift.org" {
84+
if (-not $SwiftVersion) {
85+
Write-Host "::error::swift-version is required when using swift.org source"
86+
exit 1
87+
}
88+
89+
if (-not $SwiftBuild) {
90+
Write-Host "::error::swift-build is required when using swift.org source"
91+
exit 1
92+
}
93+
}
94+
95+
"custom" {
96+
if (-not "${{ inputs.github-repo }}") {
97+
Write-Host "::error::github-repo is required when using custom source"
98+
exit 1
99+
}
100+
101+
if (-not "${{ inputs.release-tag-name }}") {
102+
Write-Host "::error::release-tag-name is required when using custom source"
103+
exit 1
104+
}
105+
106+
if (-not "${{ inputs.release-asset-name }}") {
107+
Write-Host "::error::release-asset-name is required when using custom source"
108+
exit 1
109+
}
110+
}
111+
}
112+
113+
# Export resolved values for use in subsequent steps.
114+
Write-Output "RESOLVED_SWIFT_VERSION=$SwiftVersion" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
115+
Write-Output "RESOLVED_SWIFT_BUILD=$SwiftBuild" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
116+
shell: pwsh
49117
- name: Fetch installer from GitHub release
50118
if: inputs.source == 'custom'
51119
env:
@@ -58,9 +126,9 @@ runs:
58126
if: runner.os == 'Windows' && inputs.source == 'swift.org'
59127
run: |
60128
$URL = if ("${{ inputs.build_arch }}" -eq "amd64") {
61-
"https://download.swift.org/${{ inputs.branch }}/windows10/swift-${{ inputs.tag }}/swift-${{ inputs.tag }}-windows10.exe"
129+
"https://download.swift.org/${env:RESOLVED_SWIFT_VERSION}/windows10/swift-${env:RESOLVED_SWIFT_BUILD}/swift-${env:RESOLVED_SWIFT_BUILD}-windows10.exe"
62130
} else {
63-
"https://download.swift.org/${{ inputs.branch }}/windows10-${{ inputs.build_arch }}/swift-${{ inputs.tag }}/swift-${{ inputs.tag }}-windows10-${{ inputs.build_arch }}.exe"
131+
"https://download.swift.org/${env:RESOLVED_SWIFT_VERSION}/windows10-${{ inputs.build_arch }}/swift-${env:RESOLVED_SWIFT_BUILD}/swift-${env:RESOLVED_SWIFT_BUILD}-windows10-${{ inputs.build_arch }}.exe"
64132
}
65133
66134
$Path = [IO.Path]::Combine(${env:Temp}, "installer.exe")
@@ -73,7 +141,7 @@ runs:
73141
}
74142
shell: pwsh
75143

76-
- name: Install Swift ${{ inputs.tag }}
144+
- name: Install Swift
77145
id: install-swift
78146
if: runner.os == 'Windows'
79147
run: |
@@ -148,7 +216,7 @@ runs:
148216
Copy-Item "$env:SDKROOT\usr\share\winsdk.modulemap" -destination "$env:UniversalCRTSdkDir\Include\$env:UCRTVersion\um\module.modulemap"
149217
shell: pwsh
150218

151-
- name: Install Swift ${{ inputs.tag }}
219+
- name: Install Swift
152220
if: runner.os == 'Linux'
153221
run: |
154222
source /etc/os-release
@@ -157,10 +225,10 @@ runs:
157225
ubuntu)
158226
case ${VERSION_ID} in
159227
16.04|18.04|20.04|22.04|24.04)
160-
if [[ "${{ steps.validation.outputs.use_custom_url }}" == "1" ]]; then
228+
if [[ "${{ inputs.source }}" == "custom" ]]; then
161229
mv "${{ inputs.release-asset-name }}" swift-toolchain.tar.gz
162230
else
163-
curl -sL https://download.swift.org/${{ inputs.branch }}/ubuntu${VERSION_ID/./}/swift-${{ inputs.tag }}/swift-${{ inputs.tag }}-ubuntu${VERSION_ID}.tar.gz -o swift-toolchain.tar.gz
231+
curl -sL https://download.swift.org/${RESOLVED_SWIFT_VERSION}/ubuntu${VERSION_ID/./}/swift-${RESOLVED_SWIFT_BUILD}/swift-${RESOLVED_SWIFT_BUILD}-ubuntu${VERSION_ID}.tar.gz -o swift-toolchain.tar.gz
164232
fi
165233
tar zxf swift-toolchain.tar.gz -C ${HOME}
166234
rm -f swift-toolchain.tar.gz
@@ -178,17 +246,17 @@ runs:
178246
echo "${HOME}/usr/bin" >> $GITHUB_PATH
179247
shell: bash
180248

181-
- name: Install Swift ${{ inputs.tag }}
249+
- name: Install Swift
182250
if: runner.os == 'macOS'
183251
run: |
184-
if [[ "${{ steps.validation.outputs.use_custom_url }}" == "1" ]]; then
185-
mv "${{ inputs.release-asset-name }}" swift-${{ inputs.tag }}-osx.pkg
252+
if [[ "${{ inputs.source }}" == "custom" ]]; then
253+
mv "${{ inputs.release-asset-name }}" swift-${RESOLVED_SWIFT_BUILD}-osx.pkg
186254
else
187-
curl -sOL https://download.swift.org/${{ inputs.branch }}/xcode/swift-${{ inputs.tag }}/swift-${{ inputs.tag }}-osx.pkg
255+
curl -sOL https://download.swift.org/${RESOLVED_SWIFT_VERSION}/xcode/swift-${RESOLVED_SWIFT_BUILD}/swift-${RESOLVED_SWIFT_BUILD}-osx.pkg
188256
fi
189-
xattr -dr com.apple.quarantine swift-${{ inputs.tag }}-osx.pkg
190-
installer -pkg swift-${{ inputs.tag }}-osx.pkg -target CurrentUserHomeDirectory
191-
rm -f swift-${{ inputs.tag }}-osx.pkg
257+
xattr -dr com.apple.quarantine swift-${RESOLVED_SWIFT_BUILD}-osx.pkg
258+
installer -pkg swift-${RESOLVED_SWIFT_BUILD}-osx.pkg -target CurrentUserHomeDirectory
259+
rm -f swift-${RESOLVED_SWIFT_BUILD}-osx.pkg
192260
193-
echo "TOOLCHAINS=$(plutil -extract 'CFBundleIdentifier' xml1 ${HOME}/Library/Developer/Toolchains/swift-${{ inputs.tag }}.xctoolchain/Info.plist | xmllint --xpath '//plist/string/text()' -)" >> $GITHUB_ENV
261+
echo "TOOLCHAINS=$(plutil -extract 'CFBundleIdentifier' xml1 ${HOME}/Library/Developer/Toolchains/swift-${RESOLVED_SWIFT_BUILD}.xctoolchain/Info.plist | xmllint --xpath '//plist/string/text()' -)" >> $GITHUB_ENV
194262
shell: bash

0 commit comments

Comments
 (0)