Skip to content

Commit dd21574

Browse files
committed
Run e2e tests on CI
Add `android-e2e.yml` and `ios-e2e.yml`: reusable workflows that boot an emulator / simulator, install the app built by the build workflow and run the Argent flows against it. `android.yml` and `ios.yml` run them after the build. Installing and starting the Argent tool-server is shared by both platforms, so it lives in a composite action. The server is started in the foreground and polled for readiness — `--detach` SIGKILLs the whole process group after a hard 15s timeout, which a cold CI runner (first run downloads the simulator-server binary) does not meet.
1 parent a9beeb8 commit dd21574

5 files changed

Lines changed: 367 additions & 1 deletion

File tree

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Start Argent tool-server
2+
description: >-
3+
Installs the Argent CLI and starts a tool-server for later steps and
4+
ARGENT_SERVER_LOG for the caller to print on failure.
5+
6+
inputs:
7+
port:
8+
description: Port to serve the tool-server on.
9+
required: false
10+
default: '3001'
11+
simulator-server-log:
12+
description: >-
13+
SIMSERVER_LOG level for the simulator-server backend the tool-server
14+
spawns, e.g. `debug`. Left unset when empty.
15+
required: false
16+
default: ''
17+
18+
runs:
19+
using: composite
20+
steps:
21+
- name: Install Argent
22+
shell: bash
23+
run: npx @swmansion/argent init --yes
24+
25+
# Start the server here and export its URL, so `flow run` reuses it instead
26+
# of starting one in-process, which has to come up within a fixed window a
27+
# cold runner can miss — the first run downloads the simulator-server binary.
28+
#
29+
# Not `--detach`: it gives the server a hard 15s to come up and then kills
30+
# its whole process group, and backgrounding the CLI does not help because
31+
# the timeout lives in the process we backgrounded. In the foreground there
32+
# is no deadline and the server's own output lands in our log.
33+
- name: Start tool-server
34+
shell: bash
35+
env:
36+
TOOL_SERVER_PORT: ${{ inputs.port }}
37+
SIMULATOR_SERVER_LOG: ${{ inputs.simulator-server-log }}
38+
run: |
39+
LOG="$RUNNER_TEMP/argent-server.log"
40+
# Exported before anything can fail, so the caller's log-printing step
41+
# can find it even when startup is what went wrong.
42+
echo "ARGENT_SERVER_LOG=$LOG" >> "$GITHUB_ENV"
43+
44+
if [ -n "$SIMULATOR_SERVER_LOG" ]; then
45+
export SIMSERVER_LOG="$SIMULATOR_SERVER_LOG"
46+
fi
47+
48+
nohup argent server start --no-auth --port "$TOOL_SERVER_PORT" > "$LOG" 2>&1 &
49+
SERVER_PID=$!
50+
51+
echo "Waiting for Argent tool-server on :$TOOL_SERVER_PORT..."
52+
# 3 min budget. Poll liveness too, so a server that dies on startup
53+
# fails right away with its log instead of at the end of the budget.
54+
for _ in $(seq 1 90); do
55+
if ! kill -0 "$SERVER_PID" 2>/dev/null; then
56+
echo "Argent tool-server exited during startup" >&2
57+
cat "$LOG" >&2
58+
exit 1
59+
fi
60+
if curl -fsS "http://127.0.0.1:$TOOL_SERVER_PORT/tools" >/dev/null 2>&1; then
61+
echo "tool-server is ready"
62+
exit 0
63+
fi
64+
sleep 2
65+
done
66+
echo "Argent tool-server failed to become ready in time" >&2
67+
cat "$LOG" >&2
68+
exit 1

‎.github/workflows/android-e2e.yml‎

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
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"

‎.github/workflows/android.yml‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ name: Build Android (expo-example)
33
on:
44
pull_request:
55
paths:
6+
- .argent/flows/*
7+
- .github/actions/argent-server/action.yml
68
- .github/workflows/android.yml
79
- .github/workflows/android-build.yml
10+
- .github/workflows/android-e2e.yml
811
- packages/react-native-gesture-handler/package.json
912
- packages/react-native-gesture-handler/android/**
1013
- packages/react-native-gesture-handler/shared/**
@@ -31,3 +34,12 @@ jobs:
3134
app: expo-example
3235
artifact-name: android-apk-expo-example
3336
abi: x86_64
37+
38+
e2e:
39+
if: github.repository == 'software-mansion/react-native-gesture-handler'
40+
needs: expo-example
41+
42+
uses: ./.github/workflows/android-e2e.yml
43+
with:
44+
artifact-name: android-apk-expo-example
45+
abi: x86_64

‎.github/workflows/ios-e2e.yml‎

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
name: Run iOS e2e tests
2+
3+
# Reusable: runs the Argent flows against a prebuilt app bundle. Called by `ios.yml`.
4+
on:
5+
workflow_call:
6+
inputs:
7+
artifact-name:
8+
description: Artifact holding the packaged .app bundle to test.
9+
required: true
10+
type: string
11+
xcode-version:
12+
description: >-
13+
Xcode to run on. Must match the version the app was built with, so the
14+
simulator runtime matches the SDK.
15+
required: true
16+
type: string
17+
18+
jobs:
19+
e2e:
20+
runs-on: macos-26
21+
timeout-minutes: 60
22+
23+
steps:
24+
- name: checkout
25+
uses: actions/checkout@v4
26+
27+
- name: Select Xcode
28+
env:
29+
XCODE_VERSION: ${{ inputs.xcode-version }}
30+
run: |
31+
XCODE_APP="/Applications/Xcode_${XCODE_VERSION}.app"
32+
if [ ! -d "$XCODE_APP" ]; then
33+
echo "Xcode ${XCODE_VERSION} is not installed on this runner. Available:" >&2
34+
ls -d /Applications/Xcode*.app >&2
35+
XCODE_APP=$(ls -d /Applications/Xcode_*.app 2>/dev/null | sort -V | tail -1)
36+
[ -n "$XCODE_APP" ] || XCODE_APP=/Applications/Xcode.app
37+
echo "Falling back to $XCODE_APP" >&2
38+
fi
39+
echo "Using $XCODE_APP"
40+
echo "DEVELOPER_DIR=$XCODE_APP/Contents/Developer" >> "$GITHUB_ENV"
41+
DEVELOPER_DIR="$XCODE_APP/Contents/Developer" xcodebuild -version
42+
43+
# Only needed to run the Argent CLI — the app is downloaded, not built.
44+
- name: Use Node.js 24
45+
uses: actions/setup-node@v6
46+
with:
47+
node-version: 24
48+
49+
- name: Download app built by the build workflow
50+
uses: actions/download-artifact@v4
51+
with:
52+
name: ${{ inputs.artifact-name }}
53+
path: ${{ runner.temp }}/app
54+
55+
- name: Unpack app bundle
56+
run: |
57+
tar -xzf "$RUNNER_TEMP/app/app.tar.gz" -C "$RUNNER_TEMP/app"
58+
APP_PATH=$(find "$RUNNER_TEMP/app" -maxdepth 1 -name '*.app' -type d | head -1)
59+
if [ -z "$APP_PATH" ]; then
60+
echo "Downloaded artifact does not contain an .app" >&2
61+
ls -la "$RUNNER_TEMP/app" >&2
62+
exit 1
63+
fi
64+
echo "APP_PATH=$APP_PATH" >> "$GITHUB_ENV"
65+
66+
- name: Set up iPhone 17 Pro simulator
67+
run: |
68+
UDID=$(xcrun simctl list devices available | grep -E "iPhone 17 Pro \(" | head -1 | grep -oE "[0-9A-Fa-f-]{36}" || true)
69+
if [ -z "$UDID" ]; then
70+
echo "iPhone 17 Pro not found, creating one"
71+
RUNTIME=$(xcrun simctl list runtimes ios -j | jq -r '.runtimes | map(select(.isAvailable)) | last | .identifier')
72+
UDID=$(xcrun simctl create "iPhone 17 Pro" "com.apple.CoreSimulator.SimDeviceType.iPhone-17-Pro" "$RUNTIME")
73+
fi
74+
echo "Using simulator $UDID"
75+
xcrun simctl boot "$UDID" || true
76+
xcrun simctl bootstatus "$UDID"
77+
echo "SIMULATOR_UDID=$UDID" >> "$GITHUB_ENV"
78+
79+
- name: Install app on simulator
80+
run: |
81+
echo "Installing $APP_PATH on $SIMULATOR_UDID"
82+
xcrun simctl install "$SIMULATOR_UDID" "$APP_PATH"
83+
84+
- name: Install Argent and start the tool-server
85+
uses: ./.github/actions/argent-server
86+
87+
- name: Run E2E tests
88+
run: argent flow run ./.argent/flows --device $SIMULATOR_UDID
89+
90+
# The tool-server log also carries the device backend's stderr
91+
# (`[sim <udid>]` lines), where a failed connection to the simulator is
92+
# explained.
93+
- name: Print Argent tool-server log
94+
if: ${{ !success() }}
95+
run: cat "$ARGENT_SERVER_LOG" 2>/dev/null || echo "no Argent tool-server log"

0 commit comments

Comments
 (0)