@@ -90,6 +90,14 @@ inputs:
90
90
required : false
91
91
type : string
92
92
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 : ' '
93
101
94
102
runs :
95
103
using : " composite"
@@ -103,9 +111,13 @@ runs:
103
111
. /etc/os-release
104
112
echo "osidpair=${ID}${VERSION_ID}" >> $GITHUB_OUTPUT
105
113
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
106
116
elif [ ${RUNNER_OS} == 'macOS' ]; then
107
117
echo "osidpair=macos" >> $GITHUB_OUTPUT
108
118
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
109
121
else
110
122
echo "::error::Unsupported platform: ${RUNNER_OS}"
111
123
exit 1
@@ -209,12 +221,13 @@ runs:
209
221
- name : Cache Swift ${{ steps.setup.outputs.swift-version }} Host Toolchain
210
222
uses : actions/cache@v4
211
223
id : cache-swift
224
+ if : ${{ inputs.installed-swift == '' }}
212
225
with :
213
226
path : ${{ runner.temp }}/swift-download
214
227
key : " swift-${{ steps.setup.outputs.swift-version }}-${{ steps.setup.outputs.osid }}"
215
228
216
229
- 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 == '' }}
218
231
shell : bash
219
232
run : |
220
233
mkdir -p ${{ runner.temp }}/swift-download
@@ -235,60 +248,39 @@ runs:
235
248
fi
236
249
237
250
- name : Install Swift Host Toolchain
251
+ if : ${{ inputs.installed-swift == '' }}
238
252
shell : bash
239
253
run : |
240
254
cd ${{ runner.temp }}/swift-download
241
255
if [ ${RUNNER_OS} == 'Linux' ]; then
242
256
mkdir -p ${HOME}/swift/toolchains/${{ steps.setup.outputs.swift-id }}
243
257
tar -xzf swift.tar.gz -C ${HOME}/swift/toolchains/${{ steps.setup.outputs.swift-id }} --strip 1
244
258
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
247
259
elif [ ${RUNNER_OS} == 'macOS' ]; then
248
260
/usr/sbin/installer -pkg swift.pkg -target CurrentUserHomeDirectory
249
261
SWIFT_INSTALLATION=${HOME}/Library/Developer/Toolchains/${{ steps.setup.outputs.swift-id }}.xctoolchain/usr
250
262
# do not add the toolchains variable, which might mess up Xcode builds
251
263
#echo "TOOLCHAINS=$(plutil -extract CFBundleIdentifier raw ${SWIFT_INSTALLATION}/../Info.plist)" >> $GITHUB_ENV
252
- which patchelf 2>&1 > /dev/null || brew install patchelf
253
264
else
254
265
echo "::error::Unsupported platform: ${RUNNER_OS}"
255
266
exit 1
256
267
fi
257
268
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
260
270
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
261
278
262
279
- name : Install Swift Android SDK
263
280
id : install
264
281
shell : bash
265
282
run : |
266
283
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
-
292
284
if [ ${RUNNER_OS} == 'Linux' ]; then
293
285
SWIFT_SDK_ROOT="${HOME}/.config/swiftpm/swift-sdks"
294
286
elif [ ${RUNNER_OS} == 'macOS' ]; then
@@ -298,7 +290,35 @@ runs:
298
290
exit 1
299
291
fi
300
292
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
302
322
303
323
# extract the artifact ID from the info.plist in the SDK root
304
324
SWIFT_SDK_ARTIFACT_ID=$(cat ${SWIFT_SDK_BUNDLE}/info.json | jq -r '.artifacts[] | .variants[0].path')
@@ -310,8 +330,6 @@ runs:
310
330
311
331
echo "SWIFT_SDK_BUNDLE=${SWIFT_SDK_BUNDLE}" >> $GITHUB_ENV
312
332
313
- echo "swiftroot=${SWIFT_INSTALLATION}" >> $GITHUB_OUTPUT
314
-
315
333
# plugin-path is a workaround for https://github.com/swiftlang/swift-package-manager/issues/8362
316
334
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
317
335
echo "swift-sdk=${SWIFT_SDK_TARGET}" >> $GITHUB_OUTPUT
0 commit comments