Skip to content

Commit 920b351

Browse files
committed
Update action to add swift-branch input
1 parent 41f9062 commit 920b351

File tree

1 file changed

+38
-11
lines changed

1 file changed

+38
-11
lines changed

action.yml

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ inputs:
1818
description: 'The version of the Swift toolchain to use'
1919
required: true
2020
default: 'latest'
21+
swift-branch:
22+
description: 'The branch of the Swift toolchain to use'
23+
required: true
24+
default: ''
2125
package-path:
2226
description: 'The folder where the swift package is checked out'
2327
required: true
@@ -103,17 +107,41 @@ runs:
103107
exit 1
104108
fi
105109
110+
# when the swift-version contains a dash, that means we want to use a development toolchain
111+
# e.g., "6.1-DEVELOPMENT-SNAPSHOT-2025-03-07-a" will result in using the following SDK and host toolchain:
112+
# https://github.com/skiptools/swift-android-toolchain/releases/download/6.1-DEVELOPMENT-SNAPSHOT-2025-03-07-a/swift-6.1-DEVELOPMENT-SNAPSHOT-2025-03-07-a-android-24-0.1.artifactbundle.tar.gz.zip
113+
# https://download.swift.org/swift-6.1-branch/ubuntu2404/swift-6.1-DEVELOPMENT-SNAPSHOT-2025-03-07-a/swift-6.1-DEVELOPMENT-SNAPSHOT-2025-03-07-a-ubuntu24.04.tar.gz
114+
115+
#swift-branch='swift-6.0.3-release'
116+
#swift-branch='swift-6.1-branch'
117+
#swift-branch='development'
106118
# translate swift-version "latest" into our known latest version
107119
if [ "${{ inputs.swift-version }}" == 'latest' ]; then
108120
# fetch the most recent release tag from the toolchain repo
109121
#LATEST_TAG=$(curl -fsSL -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" --retry 10 --retry-max-time 600 https://api.github.com/repos/skiptools/swift-android-toolchain/releases/latest | jq -r '.tag_name')
110122
# disabled because it frequently gives "The requested URL returned error: 403"
111123
LATEST_TAG="6.0.3"
112-
echo "swift-version=${LATEST_TAG}" >> $GITHUB_OUTPUT
124+
SWIFT_VERSION=${LATEST_TAG}
113125
else
114126
echo "swift-version=${{ inputs.swift-version }}" >> $GITHUB_OUTPUT
115127
fi
116128
129+
echo "swift-version=${SWIFT_VERSION}" >> $GITHUB_OUTPUT
130+
131+
if [ "${{ inputs.swift-branch }}" == '' ]; then
132+
echo "swift-branch=swift-${SWIFT_VERSION}-release" >> $GITHUB_OUTPUT
133+
else
134+
echo "swift-branch=${{ inputs.swift-branch }}" >> $GITHUB_OUTPUT
135+
fi
136+
137+
# the swift-id is the basename of the host toolchain download
138+
SWIFT_VERSION_ID="swift-${SWIFT_VERSION}"
139+
if [[ ${SWIFT_VERSION} != *-* ]]; then
140+
# a bare version name like "6.0.3" will have "-RELEASE" tacked on to the end
141+
SWIFT_VERSION_ID="${SWIFT_VERSION_ID}-RELEASE"
142+
fi
143+
echo "swift-id=${SWIFT_VERSION_ID}" >> $GITHUB_OUTPUT
144+
117145
- name: Cache Swift ${{ steps.setup.outputs.swift-version }} Host Toolchain
118146
uses: actions/cache@v4
119147
id: cache-swift
@@ -125,13 +153,13 @@ runs:
125153
if: steps.cache-swift.outputs.cache-hit != 'true'
126154
shell: bash
127155
run: |
128-
SWIFT_ID="swift-${{ steps.setup.outputs.swift-version }}-RELEASE"
129156
mkdir -p ~/swift-download
130157
cd ~/swift-download
158+
BASE_URL="https://download.swift.org/${{ steps.setup.outputs.swift-branch }}"
131159
if [ ${RUNNER_OS} == 'Linux' ]; then
132-
curl -fsSL --retry 8 --retry-connrefused https://download.swift.org/swift-${{ steps.setup.outputs.swift-version }}-release/${{ steps.setup.outputs.osid }}/${SWIFT_ID}/${SWIFT_ID}-${{ steps.setup.outputs.osidpair }}.tar.gz --output swift.tar.gz
160+
curl -fsSL --retry 8 --retry-connrefused ${BASE_URL}/${{ steps.setup.outputs.osid }}/${{ steps.setup.outputs.swift-id }}/${{ steps.setup.outputs.swift-id }}-${{ steps.setup.outputs.osidpair }}.tar.gz --output swift.tar.gz
133161
elif [ ${RUNNER_OS} == 'macOS' ]; then
134-
curl -fsSL --retry 8 --retry-connrefused https://download.swift.org/swift-${{ steps.setup.outputs.swift-version }}-release/xcode/${SWIFT_ID}/${SWIFT_ID}-osx.pkg --output swift.pkg
162+
curl -fsSL --retry 8 --retry-connrefused ${BASE_URL}/xcode/${{ steps.setup.outputs.swift-id }}/${{ steps.setup.outputs.swift-id }}-osx.pkg --output swift.pkg
135163
else
136164
echo "::error::Unsupported platform: ${RUNNER_OS}"
137165
exit 1
@@ -141,14 +169,13 @@ runs:
141169
shell: bash
142170
run: |
143171
cd ~/swift-download
144-
SWIFT_ID="swift-${{ steps.setup.outputs.swift-version }}-RELEASE"
145172
if [ ${RUNNER_OS} == 'Linux' ]; then
146-
mkdir -p ${HOME}/swift/toolchains/$SWIFT_ID
147-
tar -xzf swift.tar.gz -C ${HOME}/swift/toolchains/$SWIFT_ID --strip 1
148-
SWIFT_INSTALLATION=$HOME/swift/toolchains/$SWIFT_ID/usr
173+
mkdir -p ${HOME}/swift/toolchains/${{ steps.setup.outputs.swift-id }}
174+
tar -xzf swift.tar.gz -C ${HOME}/swift/toolchains/${{ steps.setup.outputs.swift-id }} --strip 1}
175+
SWIFT_INSTALLATION=$HOME/swift/toolchains/${{ steps.setup.outputs.swift-id }}/usr
149176
elif [ ${RUNNER_OS} == 'macOS' ]; then
150177
/usr/sbin/installer -pkg swift.pkg -target CurrentUserHomeDirectory
151-
SWIFT_INSTALLATION=${HOME}/Library/Developer/Toolchains/${SWIFT_ID}.xctoolchain/usr
178+
SWIFT_INSTALLATION=${HOME}/Library/Developer/Toolchains/${{ steps.setup.outputs.swift-id }}.xctoolchain/usr
152179
echo "TOOLCHAINS=$(plutil -extract CFBundleIdentifier raw ${SWIFT_INSTALLATION}/Info.plist)" >> $GITHUB_ENV
153180
else
154181
echo "::error::Unsupported platform: ${RUNNER_OS}"
@@ -166,11 +193,11 @@ runs:
166193
SWIFT_SDK_ANROID_API="24"
167194
echo "SWIFT_SDK_ANROID_API=${SWIFT_SDK_ANROID_API}" >> $GITHUB_ENV
168195
169-
SWIFT_SDK_ID="swift-${{ steps.setup.outputs.swift-version }}-RELEASE-android-${SWIFT_SDK_ANROID_API}-0.1"
196+
SWIFT_SDK_ID="${{ steps.setup.outputs.swift-id }}-android-${SWIFT_SDK_ANROID_API}-0.1"
170197
echo "SWIFT_SDK_TARGET=${SWIFT_SDK_TARGET}" >> $GITHUB_ENV
171198
172199
# variant that identifies the SDK
173-
SWIFT_SDK_ID_SHORT="swift-${{ steps.setup.outputs.swift-version }}-release-android-${SWIFT_SDK_ANROID_API}-sdk"
200+
SWIFT_SDK_ID_SHORT="${{ steps.setup.outputs.swift-branch }}-android-${SWIFT_SDK_ANROID_API}-sdk"
174201
echo "SWIFT_SDK_ID_SHORT=${SWIFT_SDK_ID_SHORT}" >> $GITHUB_ENV
175202
176203
SWIFT_SDK_TARGET="${{ steps.setup.outputs.android-sdk-arch }}-unknown-linux-android${SWIFT_SDK_ANROID_API}"

0 commit comments

Comments
 (0)