Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:

| Input | Required | Default | Description |
| --- | --- | --- | --- |
| `swift-version` | yes | | Exact toolchain version, e.g. `6.4.1` or `6.3.3`. Ranges and `latest` are not supported. |
| `swift-version` | no | | Exact toolchain version, e.g. `6.4.1` or `6.3.3`. Ranges and `latest` are not supported. If empty, the version is read from `.swift-version` in the working directory (surrounding whitespace removed) and must also be an exact version. |
| `swift-sdks` | no | | Cross-compilation Swift SDKs to install after the toolchain: `static-linux`, `wasm`, `android` (comma or space separated). |
| `use-preinstalled` | no | `false` | **Unverified opt-in.** If `swift` on `PATH` already reports exactly `swift-version`, run and use it instead of installing. By default no pre-existing binary is ever executed. |
| `windows-toolchain-variant` | no | `asserts` | Windows only. `asserts` keeps the installer's default `+Asserts` toolchain; `noasserts` installs the `+NoAsserts` one instead. Use `noasserts` on win-arm64, where the `+Asserts` `swift-package.exe` fails to start ([swiftlang/swift#92379](https://github.com/swiftlang/swift/issues/92379)). |
Expand Down
28 changes: 21 additions & 7 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ branding:
color: orange
inputs:
swift-version:
description: Exact toolchain version, e.g. "6.4.1".
required: true
description: >-
Exact toolchain version, e.g. "6.4.1". If empty, the version is read from .swift-version in the
working directory (surrounding whitespace removed); it must be an exact version too.
required: false
default: ""
swift-sdks:
description: >-
Comma or space separated Swift SDKs to install after the toolchain: static-linux, wasm, android.
Expand Down Expand Up @@ -67,10 +70,21 @@ runs:
USE_PREINSTALLED: ${{ inputs.use-preinstalled }}
run: |
set -euo pipefail
if [ -z "$SWIFT_VERSION" ]; then
if [ ! -f .swift-version ]; then
echo "::error::swift-version is empty and no .swift-version file was found in $PWD"
exit 1
fi
SWIFT_VERSION="$(< .swift-version)"
SWIFT_VERSION="${SWIFT_VERSION#"${SWIFT_VERSION%%[![:space:]]*}"}"
SWIFT_VERSION="${SWIFT_VERSION%"${SWIFT_VERSION##*[![:space:]]}"}"
echo "Read Swift version '$SWIFT_VERSION' from .swift-version"
fi
if [[ ! "$SWIFT_VERSION" =~ ^[0-9]+\.[0-9]+(\.[0-9]+)?$ ]]; then
echo "::error::swift-version must be an exact version like 6.4.1, got '$SWIFT_VERSION'"
exit 1
fi
echo "swift-version=$SWIFT_VERSION" >> "$GITHUB_OUTPUT"
# Pre-existing binaries are executed only on explicit opt-in.
pattern="Swift version ${SWIFT_VERSION//./\\.}[ (]"
if [ "$USE_PREINSTALLED" = true ] && command -v swift > /dev/null && swift --version 2>&1 | grep -Eq "$pattern"; then
Expand All @@ -86,7 +100,7 @@ runs:
if: steps.existing.outputs.found != 'true' && runner.os == 'Linux'
shell: bash
env:
SWIFT_VERSION: ${{ inputs.swift-version }}
SWIFT_VERSION: ${{ steps.existing.outputs.swift-version }}
run: bash "$GITHUB_ACTION_PATH/plan-linux.sh"

- name: Restore Swift toolchain cache
Expand All @@ -112,15 +126,15 @@ runs:
if: steps.existing.outputs.found != 'true' && runner.os == 'macOS'
shell: bash
env:
SWIFT_VERSION: ${{ inputs.swift-version }}
SWIFT_VERSION: ${{ steps.existing.outputs.swift-version }}
run: bash "$GITHUB_ACTION_PATH/install-macos.sh"

- name: Install Swift (Windows, Authenticode verified)
id: windows
if: steps.existing.outputs.found != 'true' && runner.os == 'Windows'
shell: pwsh
env:
SWIFT_VERSION: ${{ inputs.swift-version }}
SWIFT_VERSION: ${{ steps.existing.outputs.swift-version }}
WINDOWS_TOOLCHAIN_VARIANT: ${{ inputs.windows-toolchain-variant }}
WINDOWS_MINIMAL: ${{ inputs.windows-minimal }}
run: '& "$env:GITHUB_ACTION_PATH/install-windows.ps1"'
Expand All @@ -129,7 +143,7 @@ runs:
id: report
shell: bash
env:
SWIFT_VERSION: ${{ inputs.swift-version }}
SWIFT_VERSION: ${{ steps.existing.outputs.swift-version }}
SOURCE: ${{ steps.linux.outputs.source || steps.macos.outputs.source || steps.windows.outputs.source || 'preinstalled' }}
run: |
set -euo pipefail
Expand All @@ -148,6 +162,6 @@ runs:
if: inputs.swift-sdks != ''
shell: bash
env:
SWIFT_VERSION: ${{ inputs.swift-version }}
SWIFT_VERSION: ${{ steps.existing.outputs.swift-version }}
SWIFT_SDKS: ${{ inputs.swift-sdks }}
run: bash "$GITHUB_ACTION_PATH/install-sdks.sh"