|
| 1 | +# Copyright (c) Meta Platforms, Inc. and affiliates. |
| 2 | +# All rights reserved. |
| 3 | +# |
| 4 | +# This source code is licensed under the BSD-style license found in the |
| 5 | +# LICENSE file in the root directory of this source tree. |
| 6 | + |
| 7 | +name: LlamaDemo Android |
| 8 | + |
| 9 | +on: |
| 10 | + pull_request: |
| 11 | + branches: [main] |
| 12 | + paths: |
| 13 | + - 'llm/android/**' |
| 14 | + - '.github/workflows/llm-android.yml' |
| 15 | + workflow_dispatch: |
| 16 | + inputs: |
| 17 | + local_aar: |
| 18 | + description: 'URL to download a local AAR file. When set, the workflow will download the AAR and use it instead of the Maven dependency.' |
| 19 | + required: false |
| 20 | + type: string |
| 21 | + |
| 22 | +permissions: |
| 23 | + contents: read |
| 24 | + |
| 25 | +jobs: |
| 26 | + build: |
| 27 | + runs-on: ubuntu-latest |
| 28 | + name: Build LlamaDemo |
| 29 | + steps: |
| 30 | + - name: Checkout repository |
| 31 | + uses: actions/checkout@v4 |
| 32 | + |
| 33 | + - name: Set up JDK 17 |
| 34 | + uses: actions/setup-java@v4 |
| 35 | + with: |
| 36 | + java-version: '17' |
| 37 | + distribution: 'temurin' |
| 38 | + |
| 39 | + - name: Setup Gradle |
| 40 | + uses: gradle/actions/setup-gradle@v4 |
| 41 | + |
| 42 | + - name: Download local AAR |
| 43 | + if: ${{ inputs.local_aar }} |
| 44 | + run: | |
| 45 | + mkdir -p llm/android/LlamaDemo/app/libs |
| 46 | + curl -fL -o llm/android/LlamaDemo/app/libs/executorch.aar "${{ inputs.local_aar }}" |
| 47 | +
|
| 48 | + - name: Build with Gradle |
| 49 | + working-directory: llm/android/LlamaDemo |
| 50 | + run: | |
| 51 | + if [ -n "${{ inputs.local_aar }}" ]; then |
| 52 | + ./gradlew build --no-daemon -PuseLocalAar=true |
| 53 | + else |
| 54 | + ./gradlew build --no-daemon |
| 55 | + fi |
| 56 | +
|
| 57 | + - name: Upload build artifacts |
| 58 | + uses: actions/upload-artifact@v4 |
| 59 | + with: |
| 60 | + name: LlamaDemo-apk |
| 61 | + path: llm/android/LlamaDemo/app/build/outputs/apk/ |
| 62 | + if-no-files-found: warn |
| 63 | + |
| 64 | + instrumentation-test: |
| 65 | + runs-on: ubuntu-latest |
| 66 | + env: |
| 67 | + API_LEVEL: 34 |
| 68 | + ARCH: x86_64 |
| 69 | + EMULATOR_OPTIONS: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none |
| 70 | + |
| 71 | + name: Instrumentation Test LlamaDemo |
| 72 | + steps: |
| 73 | + - name: Checkout repository |
| 74 | + uses: actions/checkout@v4 |
| 75 | + |
| 76 | + - name: Enable KVM group perms |
| 77 | + run: | |
| 78 | + echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules |
| 79 | + sudo udevadm control --reload-rules |
| 80 | + sudo udevadm trigger --name-match=kvm |
| 81 | +
|
| 82 | + - name: Set up JDK 17 |
| 83 | + uses: actions/setup-java@v4 |
| 84 | + with: |
| 85 | + java-version: '17' |
| 86 | + distribution: 'temurin' |
| 87 | + |
| 88 | + - name: Setup Gradle |
| 89 | + uses: gradle/actions/setup-gradle@v4 |
| 90 | + |
| 91 | + - name: AVD cache |
| 92 | + uses: actions/cache@v4 |
| 93 | + id: avd-cache |
| 94 | + with: |
| 95 | + path: | |
| 96 | + ~/.android/avd/* |
| 97 | + ~/.android/adb* |
| 98 | + key: avd-${{ env.API_LEVEL }}-${{ env.ARCH }} |
| 99 | + |
| 100 | + - name: Create AVD and generate snapshot for caching |
| 101 | + if: steps.avd-cache.outputs.cache-hit != 'true' |
| 102 | + uses: reactivecircus/android-emulator-runner@v2 |
| 103 | + with: |
| 104 | + api-level: ${{ env.API_LEVEL }} |
| 105 | + arch: ${{ env.ARCH }} |
| 106 | + force-avd-creation: false |
| 107 | + ram-size: 16384M |
| 108 | + emulator-options: ${{ env.EMULATOR_OPTIONS }} |
| 109 | + disable-animations: false |
| 110 | + working-directory: llm/android/LlamaDemo |
| 111 | + script: echo "Generated AVD snapshot for caching." |
| 112 | + |
| 113 | + - name: Run instrumentation tests |
| 114 | + uses: reactivecircus/android-emulator-runner@v2 |
| 115 | + with: |
| 116 | + api-level: ${{ env.API_LEVEL }} |
| 117 | + arch: ${{ env.ARCH }} |
| 118 | + force-avd-creation: false |
| 119 | + ram-size: 6144M |
| 120 | + emulator-options: -no-snapshot-save ${{ env.EMULATOR_OPTIONS }} |
| 121 | + disable-animations: true |
| 122 | + working-directory: llm/android/LlamaDemo |
| 123 | + script: | |
| 124 | + ./gradlew connectedCheck |
0 commit comments