Skip to content

Commit adf54ab

Browse files
committed
Update action script
1 parent 80d788a commit adf54ab

File tree

2 files changed

+59
-64
lines changed

2 files changed

+59
-64
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ jobs:
5858

5959
runs-on: ${{ matrix.os }}
6060
steps:
61+
- uses: actions/checkout@v4
62+
6163
- name: Free Disk Space
6264
if: runner.os == 'Linux'
6365
run: |
@@ -204,70 +206,6 @@ jobs:
204206
adb push $ANDROID_NDK_HOME/toolchains/llvm/prebuilt/*/sysroot/usr/lib/${ANDROID_EMULATOR_ARCH_TRIPLE}-linux-android/libc++_shared.so /data/local/tmp/
205207
adb shell /data/local/tmp/hello
206208
207-
- name: Create android-ci script
208-
run: |
209-
cat > android-ci.sh << "EOF"
210-
#!/bin/bash -ex
211-
212-
if [[ -z "${2}" ]]; then
213-
echo "$0: Usage: $0 build/test org/package
214-
exit 1
215-
fi
216-
217-
ACT=${1}
218-
ORG=$(echo "${2}" | cut -d '/' -f 1)
219-
PACKAGE=$(echo "${2}" | cut -d '/' -f 2)
220-
221-
git clone https://github.com/${ORG}/${PACKAGE}
222-
cd ${PACKAGE}
223-
224-
TRIPLE="${ANDROID_EMULATOR_ARCH_TRIPLE}-unknown-linux-android${ANDROID_API}"
225-
swiftly run swift build --swift-sdk "${TRIPLE}" --build-tests +"${SWIFT_TOOLCHAIN_VERSION}"
226-
227-
if [[ "${ACT}" == "build" ]]; then
228-
# build-only, not test
229-
exit 0
230-
fi
231-
232-
if [[ "${ACT}" != "test" ]]; then
233-
# build-only, not test
234-
echo "$0: Usage: $0 build/test org/package
235-
exit 1
236-
fi
237-
238-
STAGING="android-test-${PACKAGE}"
239-
rm -rf .build/"${STAGING}"
240-
mkdir .build/"${STAGING}"
241-
242-
# for the common case of tests referencing their own files as hardwired resource paths
243-
cp -a Tests .build/"${STAGING}"
244-
245-
cd .build/
246-
cp -a debug/*.xctest "${STAGING}"
247-
cp -a debug/*.resources "${STAGING}" || true
248-
cp -a ${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/*/sysroot/usr/lib/${ANDROID_EMULATOR_ARCH_TRIPLE}-linux-android/libc++_shared.so "${STAGING}"
249-
cp -a ${SWIFT_ANDROID_SDK_HOME}/swift-android/swift-resources/usr/lib/swift-${ANDROID_EMULATOR_ARCH_TRIPLE}/android/*.so "${STAGING}"
250-
251-
adb push ${STAGING} /data/local/tmp/
252-
253-
cd -
254-
255-
TEST_CMD="./${PACKAGE}PackageTests.xctest"
256-
TEST_SHELL="cd /data/local/tmp/${STAGING}"
257-
TEST_SHELL="${TEST_SHELL} && ${TEST_CMD}"
258-
259-
# Run a second time with the Swift Testing library
260-
# We additionally need to handle the special exit code EXIT_NO_TESTS_FOUND (69 on Android),
261-
# which can happen when the tests link to Testing, but no tests are executed
262-
# see: https://github.com/swiftlang/swift-package-manager/blob/1b593469e8ad3daf2cc10e798340bd2de68c402d/Sources/Commands/SwiftTestCommand.swift#L1542
263-
TEST_SHELL="${TEST_SHELL} && ${TEST_CMD} --testing-library swift-testing && [ \$? -eq 0 ] || [ \$? -eq 69 ]"
264-
265-
adb shell "${TEST_SHELL}"
266-
EOF
267-
268-
chmod +x android-ci.sh
269-
cat android-ci.sh
270-
271209
- name: Run swift-numerics tests
272210
run: ./android-ci.sh test apple/swift-numerics
273211

android-ci.sh

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/bin/bash -ex
2+
3+
if [[ -z "${2}" ]]; then
4+
echo "$0: Usage: $0 build/test org/package"
5+
exit 1
6+
fi
7+
8+
ACT=${1}
9+
ORG=$(echo "${2}" | cut -d '/' -f 1)
10+
PACKAGE=$(echo "${2}" | cut -d '/' -f 2)
11+
12+
git clone https://github.com/${ORG}/${PACKAGE}
13+
cd ${PACKAGE}
14+
15+
TRIPLE="${ANDROID_EMULATOR_ARCH_TRIPLE}-unknown-linux-android${ANDROID_API}"
16+
swiftly run swift build --swift-sdk "${TRIPLE}" --build-tests +"${SWIFT_TOOLCHAIN_VERSION}"
17+
18+
if [[ "${ACT}" == "build" ]]; then
19+
# build-only, not test, so we are done
20+
exit 0
21+
fi
22+
23+
if [[ "${ACT}" != "test" ]]; then
24+
# build-only, not test
25+
echo "$0: Usage: $0 build/test org/package"
26+
exit 1
27+
fi
28+
29+
STAGING="android-test-${PACKAGE}"
30+
rm -rf .build/"${STAGING}"
31+
mkdir .build/"${STAGING}"
32+
33+
# for the common case of tests referencing their own files as hardwired resource paths
34+
cp -a Tests .build/"${STAGING}"
35+
36+
cd .build/
37+
cp -a debug/*.xctest "${STAGING}"
38+
cp -a debug/*.resources "${STAGING}" || true
39+
cp -a ${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/*/sysroot/usr/lib/${ANDROID_EMULATOR_ARCH_TRIPLE}-linux-android/libc++_shared.so "${STAGING}"
40+
cp -a ${SWIFT_ANDROID_SDK_HOME}/swift-android/swift-resources/usr/lib/swift-${ANDROID_EMULATOR_ARCH_TRIPLE}/android/*.so "${STAGING}"
41+
42+
adb push ${STAGING} /data/local/tmp/
43+
44+
cd -
45+
46+
TEST_CMD="./${PACKAGE}PackageTests.xctest"
47+
TEST_SHELL="cd /data/local/tmp/${STAGING}"
48+
TEST_SHELL="${TEST_SHELL} && ${TEST_CMD}"
49+
50+
# Run a second time with the Swift Testing library
51+
# We additionally need to handle the special exit code EXIT_NO_TESTS_FOUND (69 on Android),
52+
# which can happen when the tests link to Testing, but no tests are executed
53+
# see: https://github.com/swiftlang/swift-package-manager/blob/1b593469e8ad3daf2cc10e798340bd2de68c402d/Sources/Commands/SwiftTestCommand.swift#L1542
54+
TEST_SHELL="${TEST_SHELL} && ${TEST_CMD} --testing-library swift-testing && [ \$? -eq 0 ] || [ \$? -eq 69 ]"
55+
56+
adb shell "${TEST_SHELL}"
57+

0 commit comments

Comments
 (0)