From 06bacc190317edf98d93250925a1a1987dc0ef32 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Wed, 27 Aug 2025 10:52:44 -0700 Subject: [PATCH 1/2] 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 --- .github/workflows/test-install.yml | 8 +-- README.md | 19 +++--- action.yml | 106 +++++++++++++++++++++++------ 3 files changed, 101 insertions(+), 32 deletions(-) diff --git a/.github/workflows/test-install.yml b/.github/workflows/test-install.yml index 41a45e0..86d1c63 100644 --- a/.github/workflows/test-install.yml +++ b/.github/workflows/test-install.yml @@ -28,8 +28,8 @@ jobs: - name: Install Swift uses: ./ with: - branch: development - tag: DEVELOPMENT-SNAPSHOT-2025-02-24-a + swift-version: development + swift-build: DEVELOPMENT-SNAPSHOT-2025-08-26-a - name: Check Swift version run: swift --version @@ -58,8 +58,8 @@ jobs: - name: Install Swift without the IDE component uses: ./ with: - branch: development - tag: DEVELOPMENT-SNAPSHOT-2025-02-24-a + swift-version: development + swift-build: DEVELOPMENT-SNAPSHOT-2025-08-26-a installer-args: OptionsInstallIDE=0 - name: Assert that we find swiftc.exe diff --git a/README.md b/README.md index c21e88c..e0af97f 100644 --- a/README.md +++ b/README.md @@ -3,11 +3,11 @@ Setup Swift (on Windows) on GitHub Actions Builders Automates installation of the Swift toolchain for Windows hosts on GitHub Actions runners. -## Usage - > [!NOTE] > Windows requires Swift 5.4.2+ +## Usage + * Sample workflow using official Swift releases ```yaml @@ -19,8 +19,8 @@ jobs: steps: - uses: compnerd/gha-setup-swift@main with: - branch: swift-5.5-release - tag: 5.5-RELEASE + swift-version: swift-5.5-release + swift-build: 5.5-RELEASE - uses: actions/checkout@v2 - run: swift build @@ -50,14 +50,15 @@ jobs: ### Parameters #### When using official Swift releases: - - `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`). - - `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`). + - `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`). + - `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`). + +#### Deprecated Parameters (will be removed in a future version): + - `branch`: **[DEPRECATED]** Use `swift-version` instead. + - `tag`: **[DEPRECATED]** Use `swift-build` instead. #### When using Swift builds from a Github repository release: - `github-repo`: Github repo in "owner/repo" format - - `release-tag-name`: Release tag name, can be found in `github.com///releases` - - `release-asset-name`: Asset name for the Swift installer executable in the release - - `github-token`: Optional Github token for fetching a release from a private repository diff --git a/action.yml b/action.yml index 6cc42b7..768b44c 100644 --- a/action.yml +++ b/action.yml @@ -12,17 +12,25 @@ inputs: - custom # for swift.org toolchains: - branch: - description: 'Branch for swift.org builds. Only specifiy when using official Swift toolchains from swift.org' + swift-version: + 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' required: false - tag: - description: 'Tag for swift.org builds. Only specifiy when using official Swift toolchains from swift.org' + swift-build: + 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' required: false build_arch: - description: 'Build architecture (amd64 or arm64). Only specifiy when using official Swift toolchains from swift.org' + description: 'Build architecture (amd64 or arm64). Only specify when using official Swift toolchains from swift.org' default: 'amd64' required: true + # deprecated parameters (for backward compatibility) + branch: + description: '[DEPRECATED] Use swift-version instead. Branch for swift.org builds. Only specify when using official Swift toolchains from swift.org' + required: false + tag: + description: '[DEPRECATED] Use swift-build instead. Tag for swift.org builds. Only specify when using official Swift toolchains from swift.org' + required: false + # for custom toolchains: github-repo: description: 'Github repo in "owner/repo" format. Only specify when using custom toolchains from Github releases.' @@ -46,6 +54,66 @@ inputs: runs: using: 'composite' steps: + - name: Handle deprecated parameters and validate inputs + run: | + # Handle backward compatibility for deprecated parameters + $SwiftVersion = "${{ inputs.swift-version }}" + $SwiftBuild = "${{ inputs.swift-build }}" + + # Ensure that only the deprecated or the new parameter set is used at one time. + $errors = @( + if (![String]::IsNullOrEmpty("${{ inputs.branch }}") -and $SwiftVersion) { "Cannot specify both 'branch' (deprecated) and 'swift-version'. Please use only 'swift-version'." } + if (![String]::IsNullOrEmpty("${{ inputs.tag }}") -and $SwiftBuild) { "Cannot specify both 'tag' (deprecated) and 'swift-build'. Please use only 'swift-build'." } + ) + foreach ($error in $errors) { Write-Host "::error::$error" } + if ($errors) { exit 1 } + + # Handle deprecated parameters with warnings. + if (![String]::IsNullOrEmpty("${{ inputs.branch }}")) { + Write-Host "::warning::The 'branch' input is deprecated and will be removed in a future version. Please use 'swift-version' instead." + $SwiftVersion = "${{ inputs.branch }}" + } + + if (![String]::IsNullOrEmpty("${{ inputs.tag }}")) { + Write-Host "::warning::The 'tag' input is deprecated and will be removed in a future version. Please use 'swift-build' instead." + $SwiftBuild = "${{ inputs.tag }}" + } + + switch ("${{ inputs.source }}") { + "swift.org" { + if (-not $SwiftVersion) { + Write-Host "::error::swift-version is required when using swift.org source" + exit 1 + } + + if (-not $SwiftBuild) { + Write-Host "::error::swift-build is required when using swift.org source" + exit 1 + } + } + + "custom" { + if (-not "${{ inputs.github-repo }}") { + Write-Host "::error::github-repo is required when using custom source" + exit 1 + } + + if (-not "${{ inputs.release-tag-name }}") { + Write-Host "::error::release-tag-name is required when using custom source" + exit 1 + } + + if (-not "${{ inputs.release-asset-name }}") { + Write-Host "::error::release-asset-name is required when using custom source" + exit 1 + } + } + } + + # Export resolved values for use in subsequent steps. + Write-Output "RESOLVED_SWIFT_VERSION=$SwiftVersion" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + Write-Output "RESOLVED_SWIFT_BUILD=$SwiftBuild" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + shell: pwsh - name: Fetch installer from GitHub release if: inputs.source == 'custom' env: @@ -58,9 +126,9 @@ runs: if: runner.os == 'Windows' && inputs.source == 'swift.org' run: | $URL = if ("${{ inputs.build_arch }}" -eq "amd64") { - "https://download.swift.org/${{ inputs.branch }}/windows10/swift-${{ inputs.tag }}/swift-${{ inputs.tag }}-windows10.exe" + "https://download.swift.org/${env:RESOLVED_SWIFT_VERSION}/windows10/swift-${env:RESOLVED_SWIFT_BUILD}/swift-${env:RESOLVED_SWIFT_BUILD}-windows10.exe" } else { - "https://download.swift.org/${{ inputs.branch }}/windows10-${{ inputs.build_arch }}/swift-${{ inputs.tag }}/swift-${{ inputs.tag }}-windows10-${{ inputs.build_arch }}.exe" + "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" } $Path = [IO.Path]::Combine(${env:Temp}, "installer.exe") @@ -73,7 +141,7 @@ runs: } shell: pwsh - - name: Install Swift ${{ inputs.tag }} + - name: Install Swift id: install-swift if: runner.os == 'Windows' run: | @@ -148,7 +216,7 @@ runs: Copy-Item "$env:SDKROOT\usr\share\winsdk.modulemap" -destination "$env:UniversalCRTSdkDir\Include\$env:UCRTVersion\um\module.modulemap" shell: pwsh - - name: Install Swift ${{ inputs.tag }} + - name: Install Swift if: runner.os == 'Linux' run: | source /etc/os-release @@ -157,10 +225,10 @@ runs: ubuntu) case ${VERSION_ID} in 16.04|18.04|20.04|22.04|24.04) - if [[ "${{ steps.validation.outputs.use_custom_url }}" == "1" ]]; then + if [[ "${{ inputs.source }}" == "custom" ]]; then mv "${{ inputs.release-asset-name }}" swift-toolchain.tar.gz else - 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 + 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 fi tar zxf swift-toolchain.tar.gz -C ${HOME} rm -f swift-toolchain.tar.gz @@ -178,17 +246,17 @@ runs: echo "${HOME}/usr/bin" >> $GITHUB_PATH shell: bash - - name: Install Swift ${{ inputs.tag }} + - name: Install Swift if: runner.os == 'macOS' run: | - if [[ "${{ steps.validation.outputs.use_custom_url }}" == "1" ]]; then - mv "${{ inputs.release-asset-name }}" swift-${{ inputs.tag }}-osx.pkg + if [[ "${{ inputs.source }}" == "custom" ]]; then + mv "${{ inputs.release-asset-name }}" swift-${RESOLVED_SWIFT_BUILD}-osx.pkg else - curl -sOL https://download.swift.org/${{ inputs.branch }}/xcode/swift-${{ inputs.tag }}/swift-${{ inputs.tag }}-osx.pkg + curl -sOL https://download.swift.org/${RESOLVED_SWIFT_VERSION}/xcode/swift-${RESOLVED_SWIFT_BUILD}/swift-${RESOLVED_SWIFT_BUILD}-osx.pkg fi - xattr -dr com.apple.quarantine swift-${{ inputs.tag }}-osx.pkg - installer -pkg swift-${{ inputs.tag }}-osx.pkg -target CurrentUserHomeDirectory - rm -f swift-${{ inputs.tag }}-osx.pkg + xattr -dr com.apple.quarantine swift-${RESOLVED_SWIFT_BUILD}-osx.pkg + installer -pkg swift-${RESOLVED_SWIFT_BUILD}-osx.pkg -target CurrentUserHomeDirectory + rm -f swift-${RESOLVED_SWIFT_BUILD}-osx.pkg - echo "TOOLCHAINS=$(plutil -extract 'CFBundleIdentifier' xml1 ${HOME}/Library/Developer/Toolchains/swift-${{ inputs.tag }}.xctoolchain/Info.plist | xmllint --xpath '//plist/string/text()' -)" >> $GITHUB_ENV + echo "TOOLCHAINS=$(plutil -extract 'CFBundleIdentifier' xml1 ${HOME}/Library/Developer/Toolchains/swift-${RESOLVED_SWIFT_BUILD}.xctoolchain/Info.plist | xmllint --xpath '//plist/string/text()' -)" >> $GITHUB_ENV shell: bash From 762199d19254be5d444cd5c5821ffc7c086cd4d1 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Wed, 27 Aug 2025 13:06:27 -0700 Subject: [PATCH 2/2] Update action.yml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index 768b44c..e4ebbd6 100644 --- a/action.yml +++ b/action.yml @@ -62,8 +62,8 @@ runs: # Ensure that only the deprecated or the new parameter set is used at one time. $errors = @( - if (![String]::IsNullOrEmpty("${{ inputs.branch }}") -and $SwiftVersion) { "Cannot specify both 'branch' (deprecated) and 'swift-version'. Please use only 'swift-version'." } - if (![String]::IsNullOrEmpty("${{ inputs.tag }}") -and $SwiftBuild) { "Cannot specify both 'tag' (deprecated) and 'swift-build'. Please use only 'swift-build'." } + if (![String]::IsNullOrEmpty("${{ inputs.branch }}") -and ![String]::IsNullOrEmpty($SwiftVersion)) { "Cannot specify both 'branch' (deprecated) and 'swift-version'. Please use only 'swift-version'." } + if (![String]::IsNullOrEmpty("${{ inputs.tag }}") -and ![String]::IsNullOrEmpty($SwiftBuild)) { "Cannot specify both 'tag' (deprecated) and 'swift-build'. Please use only 'swift-build'." } ) foreach ($error in $errors) { Write-Host "::error::$error" } if ($errors) { exit 1 }