Skip to content

Add keep-running option to keep the emulator running for subsequent steps#472

Open
takahirom wants to merge 2 commits into
ReactiveCircus:mainfrom
takahirom:keep-alive-option
Open

Add keep-running option to keep the emulator running for subsequent steps#472
takahirom wants to merge 2 commits into
ReactiveCircus:mainfrom
takahirom:keep-alive-option

Conversation

@takahirom

Copy link
Copy Markdown

Hi, and thanks for maintaining this action — it makes running Android emulators in CI painless. 🙏

Motivation: I'd like to boot the emulator once and then drive it from one or more later steps in the same job — in my case, running a separate tool against the booted emulator over adb — instead of having to cram everything into this action's single script. That isn't possible today: the action always kills the emulator when script finishes, so the emulator never survives into the next step.

What it does:

  • New input keep-running (default false — fully backward compatible).
  • When true, the action skips killEmulator and force-exits so the step finishes while the emulator keeps running. The process.exit(process.exitCode ?? 0) is needed because the backgrounded emulator inherits the action's stdio, so without killing it the Node event loop never drains and the step hangs; the exit code is propagated so a failing script isn't masked as success. The error path still kills the emulator.

Tests: added validator tests for keep-running; npm test passes.

- uses: reactivecircus/android-emulator-runner@v2
  with:
    api-level: 29
    keep-running: true
    script: echo "booted; kept alive for later steps"
- run: adb -s emulator-5554 shell getprop sys.boot_completed

@ychescale9

Copy link
Copy Markdown
Member

Thanks for the PR! I'll try to take a closer look next week, but if this works well I'd be keen to consider a v3 so we can remove the script block and kill the emulator in a post step.

@takahirom

Copy link
Copy Markdown
Author

FYI — I've prepared a follow-up on top of this PR that makes keep-running more ergonomic and covers cleanup, in line with the post-step idea you mentioned for v3:

  • exports EMULATOR_PORT / ANDROID_SERIAL to subsequent steps, so adb targets the emulator without an explicit -s
  • adds a post: entrypoint that automatically kills the emulator at the end of the job when keep-running: true, so nothing leaks on self-hosted runners (killing it early in a later step with adb emu kill still works — the double kill is harmless)

Diff: takahirom/android-emulator-runner@keep-alive-option...keep-running-env-and-cleanup

Happy to open it as a separate stacked PR once this one lands, or fold it into this PR if you'd prefer to review them together.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants