Skip to content

Commit f5c4bc4

Browse files
committed
Handle installed-sdk and installed-swift inputs
1 parent 80e40c5 commit f5c4bc4

File tree

2 files changed

+54
-34
lines changed

2 files changed

+54
-34
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ or the most recent snapshot/nightly build can be specified with `nightly-6.1`.
9494
| swift-configuration | Whether to build with debug or release configuration | debug |
9595
| swift-build-flags | Additional flags to pass to the swift build command | |
9696
| swift-test-flags | Additional flags to pass to the swift test command | |
97+
| installed-sdk | The name of a pre-installed Swift SDK to use | |
98+
| installed-swift | The path to a pre-installed host Swift toolchain | |
9799
| test-env | Test environment variables key=value | |
98100
| build-package | Whether to build the Swit package | true |
99101
| build-tests | Whether to build the package tests or just the sources | true |

action.yml

Lines changed: 52 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ inputs:
9090
required: false
9191
type: string
9292
default: 'aosp_atd'
93+
installed-sdk:
94+
required: false
95+
type: string
96+
default: ''
97+
installed-swift:
98+
required: false
99+
type: string
100+
default: ''
93101

94102
runs:
95103
using: "composite"
@@ -103,9 +111,13 @@ runs:
103111
. /etc/os-release
104112
echo "osidpair=${ID}${VERSION_ID}" >> $GITHUB_OUTPUT
105113
echo "osid=${ID}$(echo ${VERSION_ID} | tr -d '.')" >> $GITHUB_OUTPUT
114+
# patchelf is needed to check whether an ELF binary contains the Testing library
115+
which patchelf 2>&1 > /dev/null || apt install patchelf
106116
elif [ ${RUNNER_OS} == 'macOS' ]; then
107117
echo "osidpair=macos" >> $GITHUB_OUTPUT
108118
echo "osid=macos" >> $GITHUB_OUTPUT
119+
# patchelf is needed to check whether an ELF binary contains the Testing library
120+
which patchelf 2>&1 > /dev/null || brew install patchelf
109121
else
110122
echo "::error::Unsupported platform: ${RUNNER_OS}"
111123
exit 1
@@ -209,12 +221,13 @@ runs:
209221
- name: Cache Swift ${{ steps.setup.outputs.swift-version }} Host Toolchain
210222
uses: actions/cache@v4
211223
id: cache-swift
224+
if: ${{ inputs.installed-swift == '' }}
212225
with:
213226
path: ${{ runner.temp }}/swift-download
214227
key: "swift-${{ steps.setup.outputs.swift-version }}-${{ steps.setup.outputs.osid }}"
215228

216229
- name: Download Swift Host Toolchain
217-
if: steps.cache-swift.outputs.cache-hit != 'true'
230+
if: ${{ steps.cache-swift.outputs.cache-hit != 'true' && inputs.installed-swift == '' }}
218231
shell: bash
219232
run: |
220233
mkdir -p ${{ runner.temp }}/swift-download
@@ -235,60 +248,39 @@ runs:
235248
fi
236249
237250
- name: Install Swift Host Toolchain
251+
if: ${{ inputs.installed-swift == '' }}
238252
shell: bash
239253
run: |
240254
cd ${{ runner.temp }}/swift-download
241255
if [ ${RUNNER_OS} == 'Linux' ]; then
242256
mkdir -p ${HOME}/swift/toolchains/${{ steps.setup.outputs.swift-id }}
243257
tar -xzf swift.tar.gz -C ${HOME}/swift/toolchains/${{ steps.setup.outputs.swift-id }} --strip 1
244258
SWIFT_INSTALLATION=$HOME/swift/toolchains/${{ steps.setup.outputs.swift-id }}/usr
245-
# patchelf is needed to check whether an ELF binary contains the Testing library
246-
which patchelf 2>&1 > /dev/null || apt install patchelf
247259
elif [ ${RUNNER_OS} == 'macOS' ]; then
248260
/usr/sbin/installer -pkg swift.pkg -target CurrentUserHomeDirectory
249261
SWIFT_INSTALLATION=${HOME}/Library/Developer/Toolchains/${{ steps.setup.outputs.swift-id }}.xctoolchain/usr
250262
# do not add the toolchains variable, which might mess up Xcode builds
251263
#echo "TOOLCHAINS=$(plutil -extract CFBundleIdentifier raw ${SWIFT_INSTALLATION}/../Info.plist)" >> $GITHUB_ENV
252-
which patchelf 2>&1 > /dev/null || brew install patchelf
253264
else
254265
echo "::error::Unsupported platform: ${RUNNER_OS}"
255266
exit 1
256267
fi
257268
echo "SWIFT_INSTALLATION=${SWIFT_INSTALLATION}" >> $GITHUB_ENV
258-
# needed to override locally-installed `swift` command
259-
#echo "${SWIFT_INSTALLATION}/bin" >> $GITHUB_PATH
269+
echo "swiftroot=${SWIFT_INSTALLATION}" >> $GITHUB_OUTPUT
260270
271+
- name: Setup Swift Host Toolchain
272+
if: ${{ inputs.installed-swift != '' }}
273+
shell: bash
274+
run: |
275+
SWIFT_INSTALLATION=${{ inputs.installed-swift }}/usr
276+
echo "SWIFT_INSTALLATION=${SWIFT_INSTALLATION}" >> $GITHUB_ENV
277+
echo "swiftroot=${SWIFT_INSTALLATION}" >> $GITHUB_OUTPUT
261278
262279
- name: Install Swift Android SDK
263280
id: install
264281
shell: bash
265282
run: |
266283
set +x
267-
SWIFT_SDK_ANROID_API="24"
268-
echo "SWIFT_SDK_ANROID_API=${SWIFT_SDK_ANROID_API}" >> $GITHUB_ENV
269-
270-
SWIFT_SDK_ID="${{ steps.setup.outputs.swift-id }}-android-${SWIFT_SDK_ANROID_API}-0.1"
271-
echo "SWIFT_SDK_TARGET=${SWIFT_SDK_TARGET}" >> $GITHUB_ENV
272-
273-
# variant that identifies the SDK
274-
SWIFT_SDK_ID_SHORT="${{ steps.setup.outputs.swift-branch }}-android-${SWIFT_SDK_ANROID_API}-sdk"
275-
echo "SWIFT_SDK_ID_SHORT=${SWIFT_SDK_ID_SHORT}" >> $GITHUB_ENV
276-
277-
SWIFT_SDK_TARGET="${{ steps.setup.outputs.android-sdk-arch }}-unknown-linux-android${SWIFT_SDK_ANROID_API}"
278-
echo "SWIFT_SDK_TARGET=${SWIFT_SDK_TARGET}" >> $GITHUB_ENV
279-
280-
mkdir -p ${RUNNER_TEMP}/swift-android-toolchain
281-
cd ${RUNNER_TEMP}/swift-android-toolchain
282-
283-
ANDROID_SDK_URL="https://github.com/skiptools/swift-android-toolchain/releases/download/${{ steps.setup.outputs.swift-version }}/${SWIFT_SDK_ID}.artifactbundle.tar.gz"
284-
echo "ANDROID_SDK_URL: ${ANDROID_SDK_URL}"
285-
curl -fsSL --retry 8 --retry-connrefused ${ANDROID_SDK_URL} --output ${SWIFT_SDK_ID}.artifactbundle.tar.gz
286-
287-
# first check if it already installed (we may be running this workflow multiple times for an action, in which case it will already be present)
288-
${SWIFT_INSTALLATION}/bin/swift sdk configure --show-configuration ${SWIFT_SDK_ID} ${SWIFT_SDK_TARGET} &> /dev/null || ${SWIFT_INSTALLATION}/bin/swift sdk install ${SWIFT_SDK_ID}.artifactbundle.tar.gz
289-
290-
${SWIFT_INSTALLATION}/bin/swift sdk configure --show-configuration ${SWIFT_SDK_ID} ${SWIFT_SDK_TARGET}
291-
292284
if [ ${RUNNER_OS} == 'Linux' ]; then
293285
SWIFT_SDK_ROOT="${HOME}/.config/swiftpm/swift-sdks"
294286
elif [ ${RUNNER_OS} == 'macOS' ]; then
@@ -298,7 +290,35 @@ runs:
298290
exit 1
299291
fi
300292
301-
SWIFT_SDK_BUNDLE="${SWIFT_SDK_ROOT}/${SWIFT_SDK_ID}.artifactbundle"
293+
if [[ "${{ inputs.installed-sdk }}" == '' ]]; then
294+
# we already have an SDK installed
295+
SWIFT_SDK_TARGET="${{ inputs.installed-sdk }}"
296+
echo "SWIFT_SDK_TARGET=${SWIFT_SDK_TARGET}" >> $GITHUB_ENV
297+
# for the bundle, we just grab the most recently installed one
298+
SWIFT_SDK_BUNDLE=$(ls -1rt ${SWIFT_SDK_ROOT}/*.artifactbundle | tail -n 1)
299+
else
300+
SWIFT_SDK_ANROID_API="24"
301+
echo "SWIFT_SDK_ANROID_API=${SWIFT_SDK_ANROID_API}" >> $GITHUB_ENV
302+
303+
SWIFT_SDK_ID="${{ steps.setup.outputs.swift-id }}-android-${SWIFT_SDK_ANROID_API}-0.1"
304+
305+
SWIFT_SDK_TARGET="${{ steps.setup.outputs.android-sdk-arch }}-unknown-linux-android${SWIFT_SDK_ANROID_API}"
306+
echo "SWIFT_SDK_TARGET=${SWIFT_SDK_TARGET}" >> $GITHUB_ENV
307+
308+
mkdir -p ${RUNNER_TEMP}/swift-android-toolchain
309+
cd ${RUNNER_TEMP}/swift-android-toolchain
310+
311+
ANDROID_SDK_URL="https://github.com/skiptools/swift-android-toolchain/releases/download/${{ steps.setup.outputs.swift-version }}/${SWIFT_SDK_ID}.artifactbundle.tar.gz"
312+
echo "ANDROID_SDK_URL: ${ANDROID_SDK_URL}"
313+
curl -fsSL --retry 8 --retry-connrefused ${ANDROID_SDK_URL} --output ${SWIFT_SDK_ID}.artifactbundle.tar.gz
314+
315+
# first check if it already installed (we may be running this workflow multiple times for an action, in which case it will already be present)
316+
${SWIFT_INSTALLATION}/bin/swift sdk configure --show-configuration ${SWIFT_SDK_ID} ${SWIFT_SDK_TARGET} &> /dev/null || ${SWIFT_INSTALLATION}/bin/swift sdk install ${SWIFT_SDK_ID}.artifactbundle.tar.gz
317+
318+
${SWIFT_INSTALLATION}/bin/swift sdk configure --show-configuration ${SWIFT_SDK_ID} ${SWIFT_SDK_TARGET}
319+
320+
SWIFT_SDK_BUNDLE="${SWIFT_SDK_ROOT}/${SWIFT_SDK_ID}.artifactbundle"
321+
fi
302322
303323
# extract the artifact ID from the info.plist in the SDK root
304324
SWIFT_SDK_ARTIFACT_ID=$(cat ${SWIFT_SDK_BUNDLE}/info.json | jq -r '.artifacts[] | .variants[0].path')
@@ -310,8 +330,6 @@ runs:
310330
311331
echo "SWIFT_SDK_BUNDLE=${SWIFT_SDK_BUNDLE}" >> $GITHUB_ENV
312332
313-
echo "swiftroot=${SWIFT_INSTALLATION}" >> $GITHUB_OUTPUT
314-
315333
# plugin-path is a workaround for https://github.com/swiftlang/swift-package-manager/issues/8362
316334
echo "swiftcmd=TARGET_OS_ANDROID=1 SKIP_BRIDGE=1 ${SWIFT_INSTALLATION}/bin/swift build --swift-sdk ${SWIFT_SDK_TARGET} -Xswiftc -plugin-path -Xswiftc ${SWIFT_INSTALLATION}/lib/swift/host/plugins/testing -Xswiftc -DTARGET_OS_ANDROID -Xswiftc -DSKIP_BRIDGE ${{ inputs.swift-build-flags }}" >> $GITHUB_OUTPUT
317335
echo "swift-sdk=${SWIFT_SDK_TARGET}" >> $GITHUB_OUTPUT

0 commit comments

Comments
 (0)