From f0e4cceefc3335af49f3077b7b2e184806f757f5 Mon Sep 17 00:00:00 2001 From: Russell Martin Date: Sun, 19 May 2024 19:33:53 -0400 Subject: [PATCH] Introduce action for setting up running Android emulator --- .github/actions/setup-android/action.yml | 39 ++++++++++++++++++++++++ .github/workflows/app-build-verify.yml | 19 ++++-------- 2 files changed, 45 insertions(+), 13 deletions(-) create mode 100644 .github/actions/setup-android/action.yml diff --git a/.github/actions/setup-android/action.yml b/.github/actions/setup-android/action.yml new file mode 100644 index 00000000..ff72ebc8 --- /dev/null +++ b/.github/actions/setup-android/action.yml @@ -0,0 +1,39 @@ +name: Setup to Run Android Emulator +description: Configures Linux for KVM access and returns Briefcase args to run the Android emulator. + +inputs: + emulator-config: + description: 'Configuration definition of emulator; defaults to {"avd":"beePhone"}.' + required: false + default: '{"avd":"beePhone"}' + +outputs: + briefcase-run-args: + value: ${{ steps.briefcase-run-args.outputs.run-args }} + description: "The briefcase arguments to use with `briefcase run android`." + +runs: + using: composite + steps: + + - name: Enable KVM Access + shell: bash + run: | + echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' \ + | sudo tee /etc/udev/rules.d/99-kvm4all.rules + sudo udevadm control --reload-rules + sudo udevadm trigger --name-match=kvm + + - name: Briefcase Run Arguments for Emulator + id: briefcase-run-args + env: + RUN_ARGS: > + --Xemulator=-no-window + --Xemulator=-no-snapshot + --Xemulator=-no-audio + --Xemulator=-no-boot-anim + --shutdown-on-exit + shell: bash + run: | + DEVICE_CONFIG=$(printf -- "--device %q" '${{ inputs.emulator-config }}') + echo "run-args=${DEVICE_CONFIG} ${RUN_ARGS}" | tee -a ${GITHUB_OUTPUT} diff --git a/.github/workflows/app-build-verify.yml b/.github/workflows/app-build-verify.yml index bb7d189d..a2d478e8 100644 --- a/.github/workflows/app-build-verify.yml +++ b/.github/workflows/app-build-verify.yml @@ -437,6 +437,11 @@ jobs: xvfb-run briefcase run linux flatpak briefcase package linux flatpak --adhoc-sign + - name: Setup Android Emulator + id: emulator-setup + if: startsWith(inputs.runner-os, 'ubuntu') + uses: ./beeware-.github/.github/actions/setup-android + - name: Build Android App if: > contains(fromJSON('["", "Android"]'), inputs.target-platform) @@ -452,19 +457,7 @@ jobs: # Only run Android app on Linux since it's duplicative (and slow) on other platforms if [ "${{ startsWith(inputs.runner-os, 'ubuntu') }}" = "true" ]; then - # allow access to KVM to run the emulator - echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' \ - | sudo tee /etc/udev/rules.d/99-kvm4all.rules - sudo udevadm control --reload-rules - sudo udevadm trigger --name-match=kvm - - briefcase run android gradle \ - --device '{"avd":"beePhone"}' \ - --shutdown-on-exit \ - --Xemulator=-no-window \ - --Xemulator=-no-snapshot \ - --Xemulator=-no-audio \ - --Xemulator=-no-boot-anim + briefcase run android gradle ${{ steps.emulator-setup.outputs.briefcase-run-args }} fi briefcase package android gradle --adhoc-sign