@@ -3,6 +3,13 @@ description: 'Cross-compiles a swift package for Android and runs the test cases
3
3
branding :
4
4
icon : ' target'
5
5
color : ' orange'
6
+ outputs :
7
+ swift-build :
8
+ description : ' The swift build command using the installed toolchain and SDK'
9
+ value : ${{ steps.install.outputs.swiftcmd }}
10
+ swift-sdk :
11
+ description : ' The swift SDK that is used to build for Android'
12
+ value : ${{ steps.install.outputs.swift-sdk }}
6
13
inputs :
7
14
swift-version :
8
15
description : ' The version of the Swift toolchain to use'
@@ -20,6 +27,14 @@ inputs:
20
27
description : ' Additional flags to pass to the swift test command'
21
28
required : true
22
29
default : ' '
30
+ android-emulator-test-folder :
31
+ description : ' Emulator folder where tests are copied and run'
32
+ required : true
33
+ default : ' /data/local/tmp/android-xctest'
34
+ test-env :
35
+ description : ' Test environment variables key=value'
36
+ required : true
37
+ default : ' '
23
38
android-emulator-options :
24
39
description : ' Options to pass to the Android emulator'
25
40
required : true
@@ -28,6 +43,14 @@ inputs:
28
43
description : ' Emulator boot timeout in seconds'
29
44
required : true
30
45
default : 600
46
+ build-package :
47
+ description : ' Whether to build the package or just set up the SDK'
48
+ required : true
49
+ default : ' true'
50
+ build-tests :
51
+ description : ' Whether to build the tests or just the sources'
52
+ required : true
53
+ default : ' true'
31
54
run-tests :
32
55
description : ' Whether to run the tests or just the build'
33
56
required : true
@@ -36,14 +59,11 @@ inputs:
36
59
description : ' Additional files to copy to emulator for testing'
37
60
required : true
38
61
default : ' '
39
- build-tests :
40
- description : ' Whether to build the tests or just the sources'
41
- required : true
42
- default : ' true'
43
62
android-api-level :
44
63
description : ' The API level of the Android emulator to run against'
45
64
required : true
46
65
default : 29
66
+
47
67
runs :
48
68
using : " composite"
49
69
steps :
@@ -112,9 +132,9 @@ runs:
112
132
cd ~/swift-download
113
133
SWIFT_ID="swift-${{ steps.setup.outputs.swift-version }}-RELEASE"
114
134
if [ ${RUNNER_OS} == 'Linux' ]; then
115
- mkdir -p ${HOME}/swift/$SWIFT_ID
116
- tar -xzf swift.tar.gz -C ~ /swift/$SWIFT_ID --strip 1
117
- SWIFT_INSTALLATION=$HOME/swift/$SWIFT_ID/usr
135
+ mkdir -p ${HOME}/swift/toolchains/ $SWIFT_ID
136
+ tar -xzf swift.tar.gz -C ${HOME} /swift/toolchains /$SWIFT_ID --strip 1
137
+ SWIFT_INSTALLATION=$HOME/swift/toolchains/ $SWIFT_ID/usr
118
138
elif [ ${RUNNER_OS} == 'macOS' ]; then
119
139
/usr/sbin/installer -pkg swift.pkg -target CurrentUserHomeDirectory
120
140
SWIFT_INSTALLATION=${HOME}/Library/Developer/Toolchains/${SWIFT_ID}.xctoolchain/usr
@@ -124,14 +144,11 @@ runs:
124
144
exit 1
125
145
fi
126
146
echo "SWIFT_INSTALLATION=${SWIFT_INSTALLATION}" >> $GITHUB_ENV
127
- echo "${SWIFT_INSTALLATION}/bin" >> $GITHUB_PATH
128
-
129
- - name : Check Swift Version
130
- shell : bash
131
- run : |
132
- swift --version
147
+ # needed to override locally-installed `swift` command
148
+ #echo "${SWIFT_INSTALLATION}/bin" >> $GITHUB_PATH
133
149
134
150
- name : Install Swift Android SDK
151
+ id : install
135
152
shell : bash
136
153
run : |
137
154
set +x
@@ -153,9 +170,9 @@ runs:
153
170
curl -fsSL https://github.com/skiptools/swift-android-toolchain/releases/download/${{ steps.setup.outputs.swift-version }}/${SWIFT_SDK_ID}.artifactbundle.tar.gz --output ${SWIFT_SDK_ID}.artifactbundle.tar.gz
154
171
155
172
# 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)
156
- swift sdk configure --show-configuration ${SWIFT_SDK_ID} ${SWIFT_SDK_TARGET} &> /dev/null || swift sdk install ${SWIFT_SDK_ID}.artifactbundle.tar.gz
173
+ ${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
157
174
158
- swift sdk configure --show-configuration ${SWIFT_SDK_ID} ${SWIFT_SDK_TARGET}
175
+ ${SWIFT_INSTALLATION}/bin/ swift sdk configure --show-configuration ${SWIFT_SDK_ID} ${SWIFT_SDK_TARGET}
159
176
160
177
if [ ${RUNNER_OS} == 'Linux' ]; then
161
178
SWIFT_SDK_ROOT="${HOME}/.config/swiftpm/swift-sdks"
@@ -178,56 +195,77 @@ runs:
178
195
179
196
echo "SWIFT_SDK_HOME=${SWIFT_SDK_HOME}" >> $GITHUB_ENV
180
197
198
+ echo "swiftcmd=${SWIFT_INSTALLATION}/bin/swift build --swift-sdk ${SWIFT_SDK_TARGET} -Xswiftc -DSKIP_BRIDGE ${{ inputs.swift-build-flags }}" >> $GITHUB_OUTPUT
199
+ echo "swift-sdk=${SWIFT_SDK_TARGET}" >> $GITHUB_OUTPUT
200
+
201
+ - name : Check Swift Version
202
+ shell : bash
203
+ run : |
204
+ echo "Swift Command: ${{ steps.install.outputs.swiftcmd }}"
205
+ ${{ steps.install.outputs.swiftcmd }} --version
206
+
181
207
- name : Build Swift Package with Android SDK
208
+ if : ${{ inputs.build-package == 'true' }}
182
209
shell : bash
183
210
working-directory : ${{ inputs.package-path }}
184
211
run : |
185
212
if [ "${{ inputs.build-tests }}" == 'true' ]; then
186
213
BUILD_TESTS="--build-tests"
187
214
fi
188
- SKIP_BRIDGE=1 swift build ${BUILD_TESTS} --swift-sdk ${SWIFT_SDK_TARGET} -Xswiftc -Xclang-linker -Xswiftc -fuse-ld=lld -Xswiftc -DSKIP_BRIDGE ${{ inputs.swift-build-flags } }
215
+ SKIP_BRIDGE=1 ${{ steps.install.outputs.swiftcmd }} ${BUILD_TESTS }
189
216
190
217
- name : Prepare Android Emulator Test Script
191
- if : ${{ inputs.run-tests == 'true' && inputs.build-tests == 'true' }}
218
+ if : ${{ inputs.run-tests == 'true' && inputs.build-tests == 'true' && inputs.build-package == 'true' }}
192
219
shell : bash
193
- working-directory : ${{ inputs.package-path }}/.build
220
+ working-directory : ${{ inputs.package-path }}
194
221
run : |
195
- set -x
196
-
197
222
if [ ${RUNNER_ARCH} == 'ARM64' ] && [ ${RUNNER_OS} == 'macOS' ]; then
198
223
echo "::error::Cannot run tests on ARM64 macOS due to HVF error: HV_UNSUPPORTED. See https://github.com/ReactiveCircus/android-emulator-runner/issues/350#issuecomment-2030065889"
199
224
exit 1
200
225
fi
201
226
202
- mkdir android-xctest
227
+ #inputs.android-emulator-test-folder = /data/local/tmp/android-xctest
228
+ REMOTE_FOLDER=$(dirname "${{ inputs.android-emulator-test-folder }}")
229
+ TEST_BASE_FOLDER=$(basename "${{ inputs.android-emulator-test-folder }}")
230
+ BUILD_DIR=".build"
231
+ PACK_DIR="${BUILD_DIR}/${TEST_BASE_FOLDER}"
232
+
233
+ mkdir -p ${PACK_DIR}
203
234
204
235
# copy the built test binary
205
- cp -va ${SWIFT_SDK_TARGET}/debug/*.xctest android-xctest
236
+ cp -va ${BUILD_DIR}/${ SWIFT_SDK_TARGET}/debug/*.xctest ${PACK_DIR}
206
237
207
238
# copy any optional resource bundles
208
- cp -vaf ${SWIFT_SDK_TARGET}/debug/*.resources android-xctest || true
209
-
239
+ cp -vaf ${BUILD_DIR}/${SWIFT_SDK_TARGET}/debug/*.resources ${PACK_DIR} || true
210
240
# 6.0.2 keeps libraries in per-API folders
211
- cp -vaf ${SWIFT_SDK_HOME}/usr/lib/${{ steps.setup.outputs.android-sdk-arch }}-linux-android/${SWIFT_SDK_ANROID_API}/lib*.so android-xctest || true
241
+ cp -vaf ${SWIFT_SDK_HOME}/usr/lib/${{ steps.setup.outputs.android-sdk-arch }}-linux-android/${SWIFT_SDK_ANROID_API}/lib*.so ${PACK_DIR} || true
212
242
213
243
# 6.0.3 keeps libraries in the parent folder
214
- cp -vaf ${SWIFT_SDK_HOME}/usr/lib/${{ steps.setup.outputs.android-sdk-arch }}-linux-android/lib*.so android-xctest || true
244
+ cp -vaf ${SWIFT_SDK_HOME}/usr/lib/${{ steps.setup.outputs.android-sdk-arch }}-linux-android/lib*.so ${PACK_DIR} || true
215
245
216
- rm -v android-xctest/lib{c,dl,log,m,z}.so
246
+ # clear out libraries that are already provided by Android
247
+ rm -v ${PACK_DIR}/lib{c,dl,log,m,z}.so || true
217
248
218
249
if [ "${{ inputs.copy-files }}" != '' ]; then
219
- cp -vaf ${{ inputs.copy-files }} android-xctest
250
+ cp -vaf ${{ inputs.copy-files }} ${PACK_DIR}
220
251
fi
221
252
222
- echo "adb push android-xctest /data/local/tmp" > run-android-tests.sh
223
- for XCTEST in android-xctest/*.xctest; do
224
- echo "adb shell /data/local/tmp/${XCTEST} ${{ inputs.swift-test-flags }}" >> run-android-tests.sh
253
+ # create the script that will be run once the emulator is launched
254
+ SCRIPT_FILE="run-android-tests.sh"
255
+
256
+ cd ${BUILD_DIR}
257
+ echo "adb push ${TEST_BASE_FOLDER} ${REMOTE_FOLDER}" > ${SCRIPT_FILE}
258
+ for XCTEST in ${TEST_BASE_FOLDER}/*.xctest; do
259
+ XCTEST_BASE=$(basename "${XCTEST}")
260
+ echo "adb shell 'cd ${REMOTE_FOLDER}/${TEST_BASE_FOLDER} && ${{ inputs.test-env }} ./${XCTEST_BASE} ${{ inputs.swift-test-flags }}'" >> ${SCRIPT_FILE}
225
261
done
226
262
227
- chmod +x run-android-tests.sh
263
+ cat ${SCRIPT_FILE}
264
+
265
+ chmod +x ${SCRIPT_FILE}
228
266
229
267
- name : Setup Android Emulator Cache
230
- if : ${{ inputs.run-tests == 'true' && inputs.build-tests == 'true' }}
268
+ if : ${{ inputs.run-tests == 'true' && inputs.build-tests == 'true' && inputs.build-package == 'true' }}
231
269
uses : actions/cache@v4
232
270
id : avd-cache
233
271
with :
@@ -237,7 +275,7 @@ runs:
237
275
key : avd-${{ inputs.android-api-level }}-${{ steps.setup.outputs.android-emulator-arch }}
238
276
239
277
- name : Create Android Emulator Cache
240
- if : ${{ inputs.run-tests == 'true' && inputs.build-tests == 'true' && steps.avd-cache.outputs.cache-hit != 'true' }}
278
+ if : ${{ inputs.run-tests == 'true' && inputs.build-tests == 'true' && inputs.build-package == 'true' && steps.avd-cache.outputs.cache-hit != 'true' }}
241
279
uses : reactivecircus/android-emulator-runner@v2
242
280
with :
243
281
force-avd-creation : false
@@ -250,7 +288,7 @@ runs:
250
288
script : echo "Generated Android Emulator snapshot for caching."
251
289
252
290
- name : Run Tests on Android emulator
253
- if : ${{ inputs.run-tests == 'true' && inputs.build-tests == 'true' }}
291
+ if : ${{ inputs.run-tests == 'true' && inputs.build-tests == 'true' && inputs.build-package == 'true' }}
254
292
uses : reactivecircus/android-emulator-runner@v2
255
293
with :
256
294
force-avd-creation : false
0 commit comments