|
| 1 | +name: Android Test |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + pull_request: |
| 6 | + push: |
| 7 | + tags: |
| 8 | + - "v*.*.*" |
| 9 | + branches: |
| 10 | + - master |
| 11 | + - develop |
| 12 | + |
| 13 | +concurrency: |
| 14 | + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} |
| 15 | + cancel-in-progress: true |
| 16 | + |
| 17 | +jobs: |
| 18 | + android-build: |
| 19 | + name: Android NDK Build |
| 20 | + runs-on: ubuntu-latest |
| 21 | + |
| 22 | + # TODO: Add more architectures |
| 23 | + strategy: |
| 24 | + fail-fast: false |
| 25 | + matrix: |
| 26 | + abi: [x86_64] |
| 27 | + api-level: [30] |
| 28 | + build: [release] |
| 29 | + |
| 30 | + env: |
| 31 | + ANDROID_NDK_VERSION: "26.1.10909125" |
| 32 | + |
| 33 | + steps: |
| 34 | + - name: Check out the repository |
| 35 | + uses: actions/checkout@v4 |
| 36 | + with: |
| 37 | + fetch-depth: 0 |
| 38 | + |
| 39 | + - name: Set up JDK 17 |
| 40 | + uses: actions/setup-java@v4 |
| 41 | + with: |
| 42 | + java-version: '17' |
| 43 | + distribution: 'temurin' |
| 44 | + |
| 45 | + - name: Setup Android SDK |
| 46 | + uses: android-actions/setup-android@v3 |
| 47 | + |
| 48 | + - name: Install Android NDK |
| 49 | + run: | |
| 50 | + sdkmanager --install "ndk;${{ env.ANDROID_NDK_VERSION }}" |
| 51 | + echo "ANDROID_NDK_HOME=$ANDROID_HOME/ndk/${{ env.ANDROID_NDK_VERSION }}" >> $GITHUB_ENV |
| 52 | + echo "ANDROID_NDK=$ANDROID_HOME/ndk/${{ env.ANDROID_NDK_VERSION }}" >> $GITHUB_ENV |
| 53 | +
|
| 54 | + # TODO Move to metacall-environment.sh |
| 55 | + - name: Install build dependencies |
| 56 | + run: | |
| 57 | + sudo apt-get update |
| 58 | + sudo apt-get install -y cmake ninja-build |
| 59 | +
|
| 60 | + - name: Create build directory |
| 61 | + run: mkdir -p build |
| 62 | + |
| 63 | + # TODO: Move to metacall-configure.sh |
| 64 | + - name: Configure CMake for Android |
| 65 | + working-directory: ./build |
| 66 | + run: | |
| 67 | + cmake .. \ |
| 68 | + -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake \ |
| 69 | + -DANDROID_ABI=${{ matrix.abi }} \ |
| 70 | + -DANDROID_PLATFORM=android-${{ matrix.api-level }} \ |
| 71 | + -DANDROID_STL=c++_shared \ |
| 72 | + -DCMAKE_BUILD_TYPE=${{ matrix.build == 'debug' && 'Debug' || 'Release' }} \ |
| 73 | + -DOPTION_BUILD_LOADERS=ON \ |
| 74 | + -DOPTION_BUILD_SCRIPTS=OFF \ |
| 75 | + -DOPTION_BUILD_TESTS=ON \ |
| 76 | + -DOPTION_BUILD_EXAMPLES=OFF \ |
| 77 | + -DOPTION_BUILD_PORTS=OFF \ |
| 78 | + -DOPTION_BUILD_CLI=OFF \ |
| 79 | + -G Ninja |
| 80 | +
|
| 81 | + # TODO: Move to metacall-configure.sh |
| 82 | + - name: Build |
| 83 | + working-directory: ./build |
| 84 | + run: ninja |
| 85 | + |
| 86 | + - name: Upload build artifacts |
| 87 | + uses: actions/upload-artifact@v4 |
| 88 | + with: |
| 89 | + name: android-build-${{ matrix.abi }}-api${{ matrix.api-level }}-${{ matrix.build }} |
| 90 | + path: ./build |
| 91 | + |
| 92 | + android-emulator-test: |
| 93 | + name: Android Emulator Test |
| 94 | + needs: android-build |
| 95 | + runs-on: ubuntu-latest |
| 96 | + |
| 97 | + # TODO: Add more architectures |
| 98 | + strategy: |
| 99 | + fail-fast: false |
| 100 | + matrix: |
| 101 | + api-level: [30] |
| 102 | + target: [google_apis] |
| 103 | + arch: [x86_64] |
| 104 | + build: [release] |
| 105 | + |
| 106 | + steps: |
| 107 | + - name: Check out the repository |
| 108 | + uses: actions/checkout@v4 |
| 109 | + with: |
| 110 | + fetch-depth: 0 |
| 111 | + |
| 112 | + - name: Enable KVM |
| 113 | + run: | |
| 114 | + echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules |
| 115 | + sudo udevadm control --reload-rules |
| 116 | + sudo udevadm trigger --name-match=kvm |
| 117 | +
|
| 118 | + - name: Download build artifacts |
| 119 | + uses: actions/download-artifact@v4 |
| 120 | + with: |
| 121 | + name: android-build-${{ matrix.abi }}-api${{ matrix.api-level }}-${{ matrix.build }} |
| 122 | + path: build |
| 123 | + |
| 124 | + - name: Set up JDK 17 |
| 125 | + uses: actions/setup-java@v4 |
| 126 | + with: |
| 127 | + java-version: '17' |
| 128 | + distribution: 'temurin' |
| 129 | + |
| 130 | + - name: Setup Android SDK |
| 131 | + uses: android-actions/setup-android@v3 |
| 132 | + |
| 133 | + - name: Install Android NDK for libc++_shared.so |
| 134 | + run: | |
| 135 | + sdkmanager --install "ndk;26.1.10909125" |
| 136 | + echo "ANDROID_NDK_HOME=$ANDROID_HOME/ndk/26.1.10909125" >> $GITHUB_ENV |
| 137 | +
|
| 138 | + - name: Run tests on Android Emulator |
| 139 | + uses: reactivecircus/android-emulator-runner@v2 |
| 140 | + with: |
| 141 | + api-level: ${{ matrix.api-level }} |
| 142 | + target: ${{ matrix.target }} |
| 143 | + arch: ${{ matrix.arch }} |
| 144 | + force-avd-creation: false |
| 145 | + emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none |
| 146 | + disable-animations: true |
| 147 | + script: | |
| 148 | + echo "=== Pushing test files to emulator ===" |
| 149 | + adb push build/ /data/local/tmp/metacall/ |
| 150 | +
|
| 151 | + echo "" |
| 152 | + echo "=== Files on emulator ===" |
| 153 | + adb shell "ls -la /data/local/tmp/metacall/" |
| 154 | +
|
| 155 | + echo "TODO: Run CTest with emulator" |
0 commit comments