Skip to content

Commit a5b7ff7

Browse files
committed
GHA: rename parameters
Rename the `branch` and `tag` to `swift-version` and `swift-build` to aid in clarity. Fixes: #19
1 parent 8e4876a commit a5b7ff7

File tree

3 files changed

+102
-30
lines changed

3 files changed

+102
-30
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: 88 additions & 17 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,69 @@ 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+
if ("${{ inputs.branch }}" -and $SwiftVersion) {
65+
Write-Host "::error::Cannot specify both 'branch' (deprecated) and 'swift-version'. Please use only 'swift-version'."
66+
exit 1
67+
}
68+
69+
if ("${{ inputs.tag }}" -and $SwiftBuild) {
70+
Write-Host "::error::Cannot specify both 'tag' (deprecated) and 'swift-build'. Please use only 'swift-build'."
71+
exit 1
72+
}
73+
74+
# Handle deprecated parameters with warnings.
75+
if ("${{ inputs.branch }}") {
76+
Write-Host "::warning::The 'branch' input is deprecated and will be removed in a future version. Please use 'swift-version' instead."
77+
$SwiftVersion = "${{ inputs.branch }}"
78+
}
79+
80+
if ("${{ inputs.tag }}") {
81+
Write-Host "::warning::The 'tag' input is deprecated and will be removed in a future version. Please use 'swift-build' instead."
82+
$SwiftBuild = "${{ inputs.tag }}"
83+
}
84+
85+
switch ("${{ inputs.source }}") {
86+
"swift.org" {
87+
if (-not $SwiftVersion) {
88+
Write-Host "::error::swift-version is required when using swift.org source"
89+
exit 1
90+
}
91+
92+
if (-not $SwiftBuild) {
93+
Write-Host "::error::swift-build is required when using swift.org source"
94+
exit 1
95+
}
96+
}
97+
98+
"custom" {
99+
if (-not "${{ inputs.github-repo }}") {
100+
Write-Host "::error::github-repo is required when using custom source"
101+
exit 1
102+
}
103+
104+
if (-not "${{ inputs.release-tag-name }}") {
105+
Write-Host "::error::release-tag-name is required when using custom source"
106+
exit 1
107+
}
108+
109+
if (-not "${{ inputs.release-asset-name }}") {
110+
Write-Host "::error::release-asset-name is required when using custom source"
111+
exit 1
112+
}
113+
}
114+
}
115+
116+
# Export resolved values for use in subsequent steps.
117+
Write-Output "RESOLVED_SWIFT_VERSION=$SwiftVersion" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
118+
Write-Output "RESOLVED_SWIFT_BUILD=$SwiftBuild" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
119+
shell: pwsh
49120
- name: Fetch installer from GitHub release
50121
if: inputs.source == 'custom'
51122
env:
@@ -58,9 +129,9 @@ runs:
58129
if: runner.os == 'Windows' && inputs.source == 'swift.org'
59130
run: |
60131
$URL = if ("${{ inputs.build_arch }}" -eq "amd64") {
61-
"https://download.swift.org/${{ inputs.branch }}/windows10/swift-${{ inputs.tag }}/swift-${{ inputs.tag }}-windows10.exe"
132+
"https://download.swift.org/${env:RESOLVED_SWIFT_VERSION}/windows10/swift-${env:RESOLVED_SWIFT_BUILD}/swift-${env:RESOLVED_SWIFT_BUILD}-windows10.exe"
62133
} else {
63-
"https://download.swift.org/${{ inputs.branch }}/windows10-${{ inputs.build_arch }}/swift-${{ inputs.tag }}/swift-${{ inputs.tag }}-windows10-${{ inputs.build_arch }}.exe"
134+
"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"
64135
}
65136
66137
$Path = [IO.Path]::Combine(${env:Temp}, "installer.exe")
@@ -73,7 +144,7 @@ runs:
73144
}
74145
shell: pwsh
75146

76-
- name: Install Swift ${{ inputs.tag }}
147+
- name: Install Swift
77148
id: install-swift
78149
if: runner.os == 'Windows'
79150
run: |
@@ -148,7 +219,7 @@ runs:
148219
Copy-Item "$env:SDKROOT\usr\share\winsdk.modulemap" -destination "$env:UniversalCRTSdkDir\Include\$env:UCRTVersion\um\module.modulemap"
149220
shell: pwsh
150221

151-
- name: Install Swift ${{ inputs.tag }}
222+
- name: Install Swift
152223
if: runner.os == 'Linux'
153224
run: |
154225
source /etc/os-release
@@ -160,7 +231,7 @@ runs:
160231
if [[ "${{ steps.validation.outputs.use_custom_url }}" == "1" ]]; then
161232
mv "${{ inputs.release-asset-name }}" swift-toolchain.tar.gz
162233
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
234+
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
164235
fi
165236
tar zxf swift-toolchain.tar.gz -C ${HOME}
166237
rm -f swift-toolchain.tar.gz
@@ -178,17 +249,17 @@ runs:
178249
echo "${HOME}/usr/bin" >> $GITHUB_PATH
179250
shell: bash
180251

181-
- name: Install Swift ${{ inputs.tag }}
252+
- name: Install Swift
182253
if: runner.os == 'macOS'
183254
run: |
184255
if [[ "${{ steps.validation.outputs.use_custom_url }}" == "1" ]]; then
185-
mv "${{ inputs.release-asset-name }}" swift-${{ inputs.tag }}-osx.pkg
256+
mv "${{ inputs.release-asset-name }}" swift-${RESOLVED_SWIFT_BUILD}-osx.pkg
186257
else
187-
curl -sOL https://download.swift.org/${{ inputs.branch }}/xcode/swift-${{ inputs.tag }}/swift-${{ inputs.tag }}-osx.pkg
258+
curl -sOL https://download.swift.org/${RESOLVED_SWIFT_VERSION}/xcode/swift-${RESOLVED_SWIFT_BUILD}/swift-${RESOLVED_SWIFT_BUILD}-osx.pkg
188259
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
260+
xattr -dr com.apple.quarantine swift-${RESOLVED_SWIFT_BUILD}-osx.pkg
261+
installer -pkg swift-${RESOLVED_SWIFT_BUILD}-osx.pkg -target CurrentUserHomeDirectory
262+
rm -f swift-${RESOLVED_SWIFT_BUILD}-osx.pkg
192263
193-
echo "TOOLCHAINS=$(plutil -extract 'CFBundleIdentifier' xml1 ${HOME}/Library/Developer/Toolchains/swift-${{ inputs.tag }}.xctoolchain/Info.plist | xmllint --xpath '//plist/string/text()' -)" >> $GITHUB_ENV
264+
echo "TOOLCHAINS=$(plutil -extract 'CFBundleIdentifier' xml1 ${HOME}/Library/Developer/Toolchains/swift-${RESOLVED_SWIFT_BUILD}.xctoolchain/Info.plist | xmllint --xpath '//plist/string/text()' -)" >> $GITHUB_ENV
194265
shell: bash

0 commit comments

Comments
 (0)