|
| 1 | +name: Run Android e2e tests |
| 2 | + |
| 3 | +# Reusable: runs the Argent flows against a prebuilt APK. Called by `android.yml`. |
| 4 | +on: |
| 5 | + workflow_call: |
| 6 | + inputs: |
| 7 | + artifact-name: |
| 8 | + description: Artifact holding the APK to test. |
| 9 | + required: true |
| 10 | + type: string |
| 11 | + abi: |
| 12 | + description: Emulator ABI. Must match the ABI the APK was built for. |
| 13 | + required: true |
| 14 | + type: string |
| 15 | + |
| 16 | +jobs: |
| 17 | + e2e: |
| 18 | + runs-on: ubuntu-latest |
| 19 | + timeout-minutes: 60 |
| 20 | + |
| 21 | + env: |
| 22 | + # The emulator advertises its gRPC console in |
| 23 | + # $XDG_RUNTIME_DIR/avd/running/pid_*.ini, which is where Argent's Android |
| 24 | + # backend looks for it. The variable is unset on runners and the two fall |
| 25 | + # back to different dirs, so pin it to a path they both check first. |
| 26 | + XDG_RUNTIME_DIR: /tmp/xdg-runtime |
| 27 | + AVD_NAME: test |
| 28 | + SYSTEM_IMAGE: system-images;android-34;google_apis;${{ inputs.abi }} |
| 29 | + |
| 30 | + steps: |
| 31 | + - name: checkout |
| 32 | + uses: actions/checkout@v4 |
| 33 | + |
| 34 | + # sdkmanager and avdmanager are Java tools. |
| 35 | + - name: Use Java 17 |
| 36 | + uses: actions/setup-java@v4 |
| 37 | + with: |
| 38 | + distribution: oracle |
| 39 | + java-version: 17 |
| 40 | + |
| 41 | + # Only needed to run the Argent CLI — the app is downloaded, not built. |
| 42 | + - name: Use Node.js 24 |
| 43 | + uses: actions/setup-node@v6 |
| 44 | + with: |
| 45 | + node-version: 24 |
| 46 | + |
| 47 | + - name: Download APK built by the build workflow |
| 48 | + uses: actions/download-artifact@v4 |
| 49 | + with: |
| 50 | + name: ${{ inputs.artifact-name }} |
| 51 | + path: ${{ runner.temp }}/apk |
| 52 | + |
| 53 | + - name: Enable KVM |
| 54 | + run: | |
| 55 | + echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules |
| 56 | + sudo udevadm control --reload-rules |
| 57 | + sudo udevadm trigger --name-match=kvm |
| 58 | +
|
| 59 | + # The emulator ignores XDG_RUNTIME_DIR if it does not exist, so create it |
| 60 | + # before booting. 0700 per the XDG spec. |
| 61 | + - name: Prepare shared XDG_RUNTIME_DIR |
| 62 | + run: | |
| 63 | + mkdir -p "$XDG_RUNTIME_DIR" |
| 64 | + chmod 700 "$XDG_RUNTIME_DIR" |
| 65 | +
|
| 66 | + # The runner's preinstalled SDK has neither the emulator nor a system |
| 67 | + # image (asking for platform-tools on top of it is a no-op). |
| 68 | + - name: Install Android emulator and system image |
| 69 | + run: | |
| 70 | + CMDLINE_BIN=$(dirname "$(command -v sdkmanager || echo "$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager")") |
| 71 | + yes | "$CMDLINE_BIN/sdkmanager" --licenses > /dev/null || true |
| 72 | + "$CMDLINE_BIN/sdkmanager" --install "emulator" "platform-tools" "$SYSTEM_IMAGE" > /dev/null |
| 73 | + { |
| 74 | + echo "$CMDLINE_BIN" |
| 75 | + echo "$ANDROID_HOME/emulator" |
| 76 | + echo "$ANDROID_HOME/platform-tools" |
| 77 | + } >> "$GITHUB_PATH" |
| 78 | + # By default avdmanager writes to $ANDROID_SDK_HOME/.android/avd while |
| 79 | + # the emulator looks in $ANDROID_SDK_HOME/avd, which fails the boot |
| 80 | + # with "Unknown AVD name". Both check $ANDROID_AVD_HOME first. |
| 81 | + echo "ANDROID_AVD_HOME=$HOME/.android/avd" >> "$GITHUB_ENV" |
| 82 | +
|
| 83 | + - name: Create AVD |
| 84 | + run: | |
| 85 | + mkdir -p "$ANDROID_AVD_HOME" |
| 86 | + echo no | avdmanager create avd --name "$AVD_NAME" --package "$SYSTEM_IMAGE" --force |
| 87 | + test -f "$ANDROID_AVD_HOME/$AVD_NAME.ini" || { |
| 88 | + echo "avdmanager did not create $AVD_NAME.ini in $ANDROID_AVD_HOME; found instead:" >&2 |
| 89 | + find "$HOME" "$ANDROID_HOME" -name "$AVD_NAME.ini" 2>/dev/null >&2 |
| 90 | + exit 1 |
| 91 | + } |
| 92 | +
|
| 93 | + # `-grpc` makes the emulator write grpc.port to the discovery ini Argent |
| 94 | + # reads. `-accel on` fails the boot when KVM didn't take, instead of |
| 95 | + # falling back to a software boot slow enough to hit the job timeout. |
| 96 | + - name: Boot emulator |
| 97 | + run: | |
| 98 | + nohup emulator -avd "$AVD_NAME" -no-snapshot -accel on \ |
| 99 | + -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim \ |
| 100 | + -grpc 8554 -camera-back none > emulator.log 2>&1 & |
| 101 | + EMULATOR_PID=$! |
| 102 | + adb start-server |
| 103 | + # Poll boot state and process liveness (10 min budget): a backgrounded |
| 104 | + # emulator that dies cannot fail the step on its own, and |
| 105 | + # `adb wait-for-device` would just hang without saying why. |
| 106 | + for _ in $(seq 1 120); do |
| 107 | + if ! kill -0 "$EMULATOR_PID" 2>/dev/null; then |
| 108 | + echo "Emulator process exited during boot:" >&2 |
| 109 | + cat emulator.log >&2 |
| 110 | + exit 1 |
| 111 | + fi |
| 112 | + if [ "$(adb shell getprop sys.boot_completed 2>/dev/null | tr -d '\r')" = 1 ]; then |
| 113 | + BOOTED=1 |
| 114 | + break |
| 115 | + fi |
| 116 | + sleep 5 |
| 117 | + done |
| 118 | + if [ -z "${BOOTED:-}" ]; then |
| 119 | + echo "Emulator did not finish booting within 10 minutes" >&2 |
| 120 | + adb devices >&2 |
| 121 | + cat emulator.log >&2 |
| 122 | + exit 1 |
| 123 | + fi |
| 124 | + adb shell input keyevent 82 |
| 125 | + adb shell settings put global window_animation_scale 0.0 |
| 126 | + adb shell settings put global transition_animation_scale 0.0 |
| 127 | + adb shell settings put global animator_duration_scale 0.0 |
| 128 | + SERIAL=$(adb devices | awk 'NR>1 && $2=="device"{print $1; exit}') |
| 129 | + echo "Emulator ready: $SERIAL" |
| 130 | + echo "ANDROID_SERIAL=$SERIAL" >> "$GITHUB_ENV" |
| 131 | +
|
| 132 | + - name: Install app on emulator |
| 133 | + run: | |
| 134 | + APK=$(find "$RUNNER_TEMP/apk" -name '*.apk' | head -1) |
| 135 | + if [ -z "$APK" ]; then |
| 136 | + echo "Downloaded artifact does not contain an APK" >&2 |
| 137 | + ls -la "$RUNNER_TEMP/apk" >&2 |
| 138 | + exit 1 |
| 139 | + fi |
| 140 | + echo "Installing $APK on $ANDROID_SERIAL" |
| 141 | + adb install -r "$APK" |
| 142 | +
|
| 143 | + - name: Install Argent and start the tool-server |
| 144 | + uses: ./.github/actions/argent-server |
| 145 | + with: |
| 146 | + # Logs how the backend discovers the emulator; drop once this is green. |
| 147 | + simulator-server-log: debug |
| 148 | + |
| 149 | + - name: Run E2E tests |
| 150 | + run: argent flow run ./.argent/flows --device "$ANDROID_SERIAL" |
| 151 | + |
| 152 | + - name: Print emulator log |
| 153 | + if: ${{ !success() }} |
| 154 | + run: cat emulator.log 2>/dev/null || echo "no emulator.log" |
| 155 | + |
| 156 | + # The tool-server log also carries the device backend's stderr |
| 157 | + # (`[sim <serial>]` lines), where a failed connection to the emulator is |
| 158 | + # explained. |
| 159 | + - name: Print Argent tool-server log |
| 160 | + if: ${{ !success() }} |
| 161 | + run: cat "$ARGENT_SERVER_LOG" 2>/dev/null || echo "no Argent tool-server log" |
0 commit comments