Skip to content
Open
Changes from 53 commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
a75fa8b
e2e-env-action
jake-perkins Jul 9, 2025
ab67bec
add more deps
jake-perkins Jul 9, 2025
22a7b88
fix cursor bug
jake-perkins Jul 9, 2025
610d928
new action shas
jake-perkins Jul 10, 2025
6ebb0f3
yarn install
jake-perkins Jul 10, 2025
f6e583d
yarn cache
jake-perkins Jul 10, 2025
e4322a4
cache act
jake-perkins Jul 10, 2025
4a81330
fix sim device
jake-perkins Jul 10, 2025
bc2f52f
bundler-cache
jake-perkins Jul 10, 2025
27eed96
try yarn.lock perf fix
jake-perkins Jul 11, 2025
c9e4d1e
cocoapods caching
jake-perkins Jul 11, 2025
f5c4f53
android tuning
jake-perkins Jul 11, 2025
860c7d4
tuning
jake-perkins Jul 11, 2025
4898cab
license-accepts
jake-perkins Jul 11, 2025
8b76ea8
foundry agnostic
jake-perkins Jul 11, 2025
f1008f7
setup
jake-perkins Jul 11, 2025
9884d8a
foundry ubuntu-mac-agnostic
jake-perkins Jul 11, 2025
682cafb
act
jake-perkins Jul 11, 2025
6a1ff90
foundry
jake-perkins Jul 11, 2025
38bd065
foundry android
jake-perkins Jul 11, 2025
2f5e2a6
remover chmod
jake-perkins Jul 11, 2025
a3ea5d4
act
jake-perkins Jul 11, 2025
8f3fdcb
act
jake-perkins Jul 11, 2025
c7d9987
act
jake-perkins Jul 11, 2025
90d1bd2
foundry
jake-perkins Jul 11, 2025
bfd20d8
act
jake-perkins Jul 11, 2025
6d49bac
cfgs
jake-perkins Jul 11, 2025
b2e0ef3
ndk setup
jake-perkins Jul 11, 2025
c35dbc6
ndk
jake-perkins Jul 11, 2025
9e75e06
ndk
jake-perkins Jul 11, 2025
dda3178
act
jake-perkins Jul 11, 2025
03cd24b
licenses
jake-perkins Jul 11, 2025
4b4e46f
android tools
jake-perkins Jul 11, 2025
02ff9a9
e2e
jake-perkins Jul 11, 2025
5695370
act
jake-perkins Jul 11, 2025
f399c35
act
jake-perkins Jul 11, 2025
4d87552
upgrade default xcode-version
jake-perkins Jul 11, 2025
929ddaa
e2e
jake-perkins Jul 11, 2025
d9de05d
lint
jake-perkins Jul 11, 2025
18421e8
android-simulator
jake-perkins Jul 11, 2025
93cf96a
android-act
jake-perkins Jul 11, 2025
db78229
fix emu bug
jake-perkins Jul 11, 2025
37051d0
act
jake-perkins Jul 11, 2025
dade476
act
jake-perkins Jul 11, 2025
8529256
emulator bugs
jake-perkins Jul 11, 2025
3b49d84
android-sim
jake-perkins Jul 11, 2025
a4ca242
act
jake-perkins Jul 11, 2025
b1867a9
act
jake-perkins Jul 11, 2025
860e85f
env
jake-perkins Jul 11, 2025
032380e
update android default abi
jake-perkins Jul 11, 2025
eea10a6
act
jake-perkins Jul 11, 2025
1366275
linting
jake-perkins Jul 12, 2025
1a08796
Merge branch 'main' into e2e-env-actions
jake-perkins Jul 12, 2025
367c013
always lay out simulator cfgs
jake-perkins Jul 15, 2025
d7a349b
E2e ubuntu runners (#87)
makemesteaks Jul 16, 2025
4459e30
E2e env actions keystore (#90)
jake-perkins Jul 18, 2025
4ee8ff1
keystore-integrations
jake-perkins Jul 18, 2025
9e04cea
keystores
jake-perkins Jul 18, 2025
aa884d6
keystore
jake-perkins Jul 18, 2025
a4d8ac3
manage node version
jake-perkins Jul 18, 2025
a3cd1cb
Emulator configs (#88)
makemesteaks Jul 18, 2025
b748908
remove cocoapods caching
jake-perkins Jul 18, 2025
8553525
fmt
jake-perkins Jul 18, 2025
cf5b15f
chore: add conditional to start decoupling some steps
alucardzom Aug 4, 2025
5827d99
chore: test more self hosted conditionals
alucardzom Aug 4, 2025
ac3212f
chore: test path xcode self hosted
alucardzom Aug 4, 2025
f850b3e
targets
jake-perkins Aug 4, 2025
a3886bc
fix target ref
jake-perkins Aug 5, 2025
af1ea7a
chore: comment line
alucardzom Aug 5, 2025
9c67713
chore: add code develop path
alucardzom Aug 5, 2025
87877ab
chore: now fail because can't find xcodebuild
alucardzom Aug 5, 2025
48f952e
chore: add shell removed by cursor
alucardzom Aug 5, 2025
7228375
chore: add conditional and point to the correct develop foler
alucardzom Aug 5, 2025
d942920
chore: rollback to previous state without duplicated block
alucardzom Aug 5, 2025
c9620dc
chore: set true to install ruby 3.1 compatible version
alucardzom Aug 7, 2025
6fe7aea
bundler slef-host flag
jake-perkins Aug 8, 2025
f8b417a
chore: some clean up
alucardzom Aug 8, 2025
11952a4
chore: remove unused blocks
alucardzom Aug 8, 2025
cd57fed
create actiuon for yarn v3
tommasini Sep 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
378 changes: 378 additions & 0 deletions .github/actions/setup-e2e-env/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,378 @@
name: 'Setup E2E Test Environment'
description: 'Sets up the environment for running E2E tests'
inputs:
platform:
description: 'Platform (ios or android)'
required: true
node-version:
description: 'Node.js version'
required: false
default: '20.18.0'
yarn-version:
description: Yarn version to use with Corepack
required: false
default: '1.22.22'
setup-simulator:
description: 'Whether to setup simulator/emulator'
required: false
default: 'false'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Unused Simulator Setup Input

The setup-simulator input is defined but unused in the action steps. Despite its description and PR documentation, there is no logic to conditionally boot simulators or emulators based on this input.

Locations (1)
Fix in Cursor Fix in Web

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Simulator Setup Input Missing Implementation

The setup-simulator input is defined in the action, but there is no corresponding implementation logic to boot or launch simulators/emulators for either iOS or Android platforms when this input is enabled.

Locations (1)
Fix in Cursor Fix in Web

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Unused Input and YAML Formatting Issue

The setup-simulator input is defined but unused in the action logic, rendering it non-functional. Additionally, the yarn-version input's description string lacks quotes, which is a YAML best practice.

Locations (1)
Fix in Cursor Fix in Web

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Simulator Setup Incomplete, YAML Parsing Issues

The setup-simulator input is defined but its functionality to boot simulators/emulators is not implemented; the action only prepares the environment (creates Android AVD, lists iOS devices) without starting them. Additionally, several description fields in the inputs section lack YAML quotes, potentially causing parsing errors.

Locations (1)
Fix in Cursor Fix in Web

# See https://github.com/actions/runner-images/blob/main/images/macos/macos-14-Readme.md#installed-simulators
ios-device:
description: Name of iOS device to boot (e.g., "iPhone 15")
required: false
default: 'iPhone 15'
bundler-version:
description: 'Bundler version to use (only for iOS)'
required: false
default: '2.5.8'
cache-prefix:
description: 'Cache key prefix'
required: false
default: 'e2e'
ruby-version:
description: Ruby version to use (only for iOS)
required: false
default: '3.1'
xcode-version:
description: Xcode version to select (e.g., 16.2)
required: false
default: '16.2'
jdk-version:
description: JDK version to use (only for Android)
required: false
default: '17'
jdk-distribution:
description: JDK distribution to use (only for Android)
required: false
default: 'temurin'
ndk-version:
description: NDK version to use (only for Android)
required: false
default: '26.1.10909125'
foundry-version:
description: Foundry version to install
required: false
default: 'v1.2.3'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Unused Inputs Override Version Settings

The foundry-version input is defined but unused, leading to the latest Foundry version being installed instead of the specified one. Similarly, Android-specific inputs jdk-version, jdk-distribution, and ndk-version are defined but not utilized for their respective setup steps.

Locations (1)
Fix in Cursor Fix in Web

android-avd-name:
description: 'Name of AVD to create and boot (for Android)'
required: false
default: 'test_e2e_avd'
android-device:
description: 'AVD device profile (e.g. "pixel")'
required: false
default: 'pixel'
android-api-level:
description: 'Android API level to use (e.g. "34")'
required: false
default: '34'
android-abi:
description: 'System architecture ABI for the Android system image (e.g. x86_64, arm64-v8a, armeabi-v7a)'
required: false
default: 'x86_64'

runs:
using: 'composite'
steps:
## Common Setup ##
- run: echo "Setup E2E Environment started"
shell: bash

## Yarn Setup & Cache Management

- name: Corepack
id: corepack
run: corepack enable && corepack prepare yarn@${{ inputs.yarn-version }} --activate
shell: bash

- name: Restore Yarn cache
uses: actions/cache@v4
with:
path: |
node_modules
key: ${{ inputs.cache-prefix }}-yarn-${{ inputs.platform }}-${{ runner.os }}-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ inputs.cache-prefix }}-yarn-${{ inputs.platform }}-${{ runner.os }}-

- name: Install JavaScript dependencies
id: yarn-install
run: yarn install --frozen-lockfile
shell: bash
env:
NODE_OPTIONS: --max-old-space-size=4096 # Increase memory limit for Node.js due to large dependencies

- name: Install Detox CLI
id: install-detox-cli
run: yarn global add detox-cli
shell: bash

- name: Install Foundry
shell: bash
run: |
echo "Installing Foundry via foundryup..."

export FOUNDRY_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/.foundry"
export FOUNDRY_BIN="$FOUNDRY_DIR/bin"

mkdir -p "$FOUNDRY_BIN"

curl -sL https://raw.githubusercontent.com/foundry-rs/foundry/master/foundryup/foundryup -o "$FOUNDRY_BIN/foundryup"
chmod +x "$FOUNDRY_BIN/foundryup"

echo "$FOUNDRY_BIN" >> "$GITHUB_PATH"

"$FOUNDRY_BIN/foundryup"

## IOS Setup ##

## Ruby Setup & Cache Management
- name: Setup Ruby
if: ${{ inputs.platform == 'ios' }}
uses: ruby/setup-ruby@a4effe49ee8ee5b8b5091268c473a4628afb5651
with:
ruby-version: ${{ inputs.ruby-version }}

# Install Bundler first
- name: Install bundler
if: ${{ inputs.platform == 'ios' }}
run: gem install bundler -v ${{ inputs.bundler-version }}
shell: bash

# Restore cached Ruby gems
- name: Restore Bundler cache
if: ${{ inputs.platform == 'ios' }}
uses: actions/cache@v4
with:
path: ios/vendor/bundle
key: ${{ inputs.cache-prefix }}-bundler-${{ inputs.platform }}-${{ runner.os }}-${{ hashFiles('ios/Gemfile.lock') }}
restore-keys: |
${{ inputs.cache-prefix }}-bundler-${{ inputs.platform }}-${{ runner.os }}-

# Configure bundler to use a specific path for gem installation
- name: Configure bundler install path
if: ${{ inputs.platform == 'ios' }}
run: bundle config set path 'vendor/bundle'
working-directory: ios
shell: bash

# Install Ruby gems into ios/vendor/bundle ( cache management & awareness )
- name: Install Ruby gems via bundler
if: ${{ inputs.platform == 'ios' }}
run: bundle install
working-directory: ios
shell: bash

# Select Xcode version
- name: Select Xcode version
if: ${{ inputs.platform == 'ios' }}
run: sudo xcode-select -s /Applications/Xcode_${{ inputs.xcode-version }}.app
shell: bash
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Redundant Xcode Version Selection in CI

The setup-e2e-env action contains duplicate Xcode version selection steps for iOS. The first step (line 144) uses an incomplete path and lacks the shell: bash directive, while the second step (line 196) uses the correct path and includes the shell directive. The second step overrides the first, rendering the initial selection redundant.

Fix in Cursor Fix in Web

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: iOS Xcode Selection Fails on GitHub Runners

The setup-e2e-env action includes duplicate Xcode version selection steps for iOS. A step conditional for self-hosted runners and another unconditional step for all iOS platforms lead to self-hosted runners executing xcode-select twice. Additionally, the unconditional step attempts to select Xcode using a path that may not exist on GitHub-hosted runners, potentially causing build failures. This indicates an incorrect implementation of intended distinct Xcode paths for self-hosted versus GitHub-hosted environments.

Fix in Cursor Fix in Web


# Restore CocoaPods cache
- name: Restore CocoaPods cache
if: ${{ inputs.platform == 'ios' && inputs.setup-simulator == 'true' }}
uses: actions/cache@v4
with:
path: ios/Pods
key: ${{ inputs.cache-prefix }}-pods-${{ inputs.platform }}-${{ runner.os }}-${{ hashFiles('ios/Podfile.lock') }}
restore-keys: |
${{ inputs.cache-prefix }}-pods-${{ inputs.platform }}-${{ runner.os }}-

# Install CocoaPods w/ cached bundler environment
- name: Install CocoaPods via bundler
if: ${{ inputs.platform == 'ios' && inputs.setup-simulator == 'true' }}
run: bundle exec pod install
working-directory: ios
shell: bash

- name: Install applesimutils
if: ${{ inputs.platform == 'ios' }}
run: brew tap wix/brew && brew install applesimutils
shell: bash

- name: Boot iOS Simulator (if not already booted)
if: ${{ inputs.platform == 'ios' && inputs.setup-simulator == 'true' }}
run: |
echo "Looking for simulator named: ${{ inputs.ios-device }}"

SIMULATOR_LINE=$(xcrun simctl list devices | grep -m1 "${{ inputs.ios-device }}")
if [ -z "$SIMULATOR_LINE" ]; then
echo "No simulator found with name '${{ inputs.ios-device }}'"
exit 1
fi

SIMULATOR_ID=$(echo "$SIMULATOR_LINE" | awk -F '[()]' '{print $2}')
SIMULATOR_STATE=$(echo "$SIMULATOR_LINE" | awk -F '[()]' '{print $(NF-1)}')

echo "Simulator ID: $SIMULATOR_ID"
echo "Simulator State: $SIMULATOR_STATE"

if [ "$SIMULATOR_STATE" = "Booted" ]; then
echo "Simulator is already booted. Skipping boot step."
else
echo "Booting simulator..."
xcrun simctl boot "$SIMULATOR_ID"
fi
shell: bash

## Android Setup ##

## JDK Setup
- name: Setup Java
if: ${{ inputs.platform == 'android' }}
uses: actions/setup-java@c5195efecf7bdfc987ee8bae7a71cb8b11521c00
with:
java-version: ${{ inputs.jdk-version }}
distribution: ${{ inputs.jdk-distribution }}

## Android SDK Setup

# - name: Install required emulator dependencies
# if: ${{ inputs.platform == 'android' }}
# run: |
# sudo apt-get update
# sudo apt-get install -y libpulse0 libglu1-mesa
# shell: bash

- name: Install Android SDK packages
if: ${{ inputs.platform == 'android' }}
run: |
echo "Accepting SDK licenses..."
printf 'y\n%.0s' {1..10} | "${ANDROID_HOME}/cmdline-tools/latest/bin/sdkmanager" --licenses

echo "Installing Android SDK components..."
"${ANDROID_HOME}/cmdline-tools/latest/bin/sdkmanager" --install \
"platform-tools" \
"platforms;android-${{ inputs.android-api-level }}" \
"build-tools;34.0.0" \
"emulator" \
"system-images;android-34;google_apis;${{ inputs.android-abi }}" \

echo "Updating SDK packages..."
"${ANDROID_HOME}/cmdline-tools/latest/bin/sdkmanager" --update
shell: bash

## NDK Setup

- name: Debug Android SDK Paths
if: ${{ inputs.platform == 'android' }}
run: |
echo "ANDROID_HOME: $ANDROID_HOME"
echo "ANDROID_SDK_ROOT: $ANDROID_SDK_ROOT"
shell: bash

- name: Accept Android SDK licenses
if: ${{ inputs.platform == 'android' }}
run: |
echo "Accepting Android SDK licenses..."
bash -c 'yes | "${ANDROID_HOME}/cmdline-tools/latest/bin/sdkmanager" --licenses' || true
shell: bash

- name: Install Android SDK Packages
if: ${{ inputs.platform == 'android' }}
run: |
"$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager" --install \
"platform-tools" \
"platforms;android-${{ inputs.android-api-level }}" \
"build-tools;34.0.0" \
"emulator" \
"system-images;android-${{ inputs.android-api-level }};google_apis;${{ inputs.android-abi }}"
shell: bash

- name: Install Android NDK
if: ${{ inputs.platform == 'android' }}
run: |
"$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager" "ndk;${{ inputs.ndk-version }}"
shell: bash

- name: Add Android tools to PATH
if: ${{ inputs.platform == 'android' }}
run: |
echo "$ANDROID_HOME/platform-tools" >> "$GITHUB_PATH"
echo "$ANDROID_HOME/emulator" >> "$GITHUB_PATH"
echo "$ANDROID_HOME/cmdline-tools/latest/bin" >> "$GITHUB_PATH"
shell: bash

- name: Add NDK related toolchains to PATH
if: ${{ inputs.platform == 'android' }}
run: |
NDK_TOOLCHAIN="$ANDROID_SDK_ROOT/ndk/${{ inputs.ndk-version }}/toolchains/llvm/prebuilt/linux-x86_64/bin"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: NDK Toolchain Path Not Platform-Agnostic

The NDK toolchain path in the Add NDK related toolchains to PATH step is hardcoded to linux-x86_64. This prevents the action from correctly locating the NDK toolchain on non-Linux x86_64 runners, such as macOS (which requires darwin-x86_64) or ARM-based Linux systems.

Locations (1)
Fix in Cursor Fix in Web

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: NDK Toolchain Path Issue Across Platforms

The Android NDK toolchain path is hardcoded to linux-x86_64, making the setup incompatible with non-Linux runners, such as macOS, where the path should be darwin-x86_64.

Fix in Cursor Fix in Web

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: NDK Toolchain Path Not Platform-Agnostic

The NDK toolchain path in the 'Add NDK related toolchains to PATH' step is hardcoded to linux-x86_64. This prevents the action from correctly setting up the NDK on non-Linux runners (e.g., macOS, Windows), as the prebuilt directory varies by host platform (e.g., darwin-x86_64 for macOS, windows-x86_64 for Windows). The path should dynamically adapt to the runner.os.

Fix in Cursor Fix in Web

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: NDK Path Issue on macOS Builds

The NDK toolchain path is hardcoded to linux-x86_64, which causes Android builds to fail on non-Linux platforms like macOS, where the path should dynamically resolve to darwin-x86_64.

Fix in Cursor Fix in Web

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: NDK Toolchain Path Hardcoded for Linux

The NDK toolchain path is hardcoded to linux-x86_64, which causes failures on other operating systems and architectures, such as macOS (where it should be darwin-x86_64) or ARM64 systems.

Fix in Cursor Fix in Web

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: NDK Toolchain Path Not Arch-Independent

The NDK toolchain path is hardcoded to linux-x86_64. This prevents Android E2E setup from finding the NDK toolchain on macOS runners, where the path should dynamically resolve to darwin-x86_64 or darwin-arm64 based on the runner's architecture.

Fix in Cursor Fix in Web

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: NDK Toolchain Path Incorrect on macOS

The NDK toolchain path is hardcoded to linux-x86_64 in the Add NDK related toolchains to PATH step. This causes Android setup to fail on macOS runners, as the correct path for macOS is darwin-x86_64. The path should be determined dynamically based on runner.os.

Fix in Cursor Fix in Web

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: NDK Toolchain Path Incorrect on macOS

The NDK toolchain path is hardcoded to linux-x86_64. This is incorrect for macOS runners, where the path should be darwin-x86_64, causing the NDK toolchain to not be found in PATH.

Fix in Cursor Fix in Web

echo "$NDK_TOOLCHAIN" >> "$GITHUB_PATH"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: NDK Toolchain Path Incorrect on Non-Linux Runners

The NDK toolchain path is hardcoded to linux-x86_64 in the Android setup step. This causes an incorrect path to be added to GITHUB_PATH on non-Linux x86_64 runners (e.g., macOS, where darwin-x86_64 is expected, or ARM64 runners), leading to NDK toolchain setup failures.

Fix in Cursor Fix in Web

echo "$ANDROID_SDK_ROOT/ndk/${{ inputs.ndk-version }}" >> "$GITHUB_PATH"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: NDK Path and SDK Environment Mismatch

The NDK toolchain path hardcodes linux-x86_64, which will cause Android builds to fail on macOS runners where darwin-x86_64 is required. The path should dynamically determine the correct operating system and architecture. Additionally, there is inconsistent use of ANDROID_SDK_ROOT and ANDROID_HOME throughout the Android setup, which can lead to path resolution issues.

Fix in Cursor Fix in Web

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: NDK Path Issues Across Platforms

The Android NDK toolchain path is hardcoded to linux-x86_64, which is incorrect for macOS runners where darwin-x86_64 is required. This path also inconsistently uses $ANDROID_SDK_ROOT instead of $ANDROID_HOME, which is used by other Android setup steps, potentially leading to incorrect NDK paths.

Fix in Cursor Fix in Web

shell: bash
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: NDK Path Hardcoded for Linux Only

The NDK toolchain path is hardcoded to linux-x86_64 (line 321), which is incorrect for non-Linux runners (e.g., macOS requires darwin-x86_64). This step lacks a runner.os == 'Linux' guard, causing NDK tools to not be found on other platforms.

Fix in Cursor Fix in Web


## Launch AVD

## Launch AVD

- name: Install Android system image
if: ${{ inputs.platform == 'android' && inputs.setup-simulator == 'true' }}
run: |
IMAGE="system-images;android-${{ inputs.android-api-level }};google_apis;${{ inputs.android-abi }}"
echo "Installing system image: $IMAGE"
"${ANDROID_HOME}/cmdline-tools/latest/bin/sdkmanager" --install "$IMAGE"
shell: bash

- name: Set ANDROID_AVD_HOME for downstream steps
if: ${{ inputs.platform == 'android' && inputs.setup-simulator == 'true' }}
shell: bash
run: |
echo "ANDROID_AVD_HOME=$HOME/.android/avd" >> "$GITHUB_ENV"
mkdir -p "$HOME/.android/avd"

- name: Create Android Virtual Device (AVD)
if: ${{ inputs.platform == 'android' && inputs.setup-simulator == 'true' }}
run: |
IMAGE="system-images;android-${{ inputs.android-api-level }};google_apis;${{ inputs.android-abi }}"
echo "Creating AVD with image: $IMAGE"
echo "no" | "${ANDROID_HOME}/cmdline-tools/latest/bin/avdmanager" create avd \
--name "${{ inputs.android-avd-name }}" \
--package "$IMAGE" \
--device "${{ inputs.android-device }}"
shell: bash

- name: List available AVDs
if: ${{ inputs.platform == 'android' && inputs.setup-simulator == 'true' }}
shell: bash
run: |
echo "โœ… Available AVDs:"
"${ANDROID_HOME}/cmdline-tools/latest/bin/avdmanager" list avd || true

# Launch Android Emulator
- name: Launch Android Emulator
if: ${{ inputs.platform == 'android' && inputs.setup-simulator == 'true' }}
run: |
nohup "$ANDROID_HOME/emulator/emulator" \
-avd "${{ inputs.android-avd-name }}" \
-no-audio \
-no-boot-anim \
-no-window \
-verbose > /dev/null 2>&1 &
shell: bash

## Wait for Emulator to Boot
- name: Wait for Android Emulator to Boot
if: ${{ inputs.platform == 'android' && inputs.setup-simulator == 'true' }}
run: |
echo "Waiting for emulator to be ready..."
adb wait-for-device

bootanim=""
timeout=300 # 5 minutes in seconds
elapsed=0

while [[ "$elapsed" -lt "$timeout" ]]; do
bootanim=$(adb shell getprop init.svc.bootanim 2>/dev/null || echo "unknown")
echo "Waiting for emulator... ($bootanim) (${elapsed}s elapsed)"

if [[ "$bootanim" == *"stopped"* ]]; then
echo "โœ… Emulator booted successfully"
exit 0
fi

sleep 5
elapsed=$((elapsed + 5))
done

echo "โŒ Timeout waiting for emulator to boot"
exit 1
shell: bash
Loading