2121# Android → --driver devicelab
2222# iOS → default driver
2323#
24- # In CI on Android, driver startup crashes are retried twice (3 runs total).
24+ # Failed test runs are retried in CI only (iOS and Android). Override with
25+ # MAESTRO_MAX_RETRIES (default: 1 locally, 2 in CI). DeviceLab driver startup
26+ # crashes on CI Android get extra cleanup between attempts.
2527
2628set -euo pipefail
2729
@@ -143,8 +145,12 @@ set_font_scale default
143145# maestro-runner exits non-zero when the tag filter matches zero flows. That's
144146# not a real failure for us (e.g. running a single flow that has no
145147# accessibility variant), and letting it propagate aborts later test suites.
148+ is_ci () {
149+ [ -n " ${CI:- } " ] || [ -n " ${GITHUB_ACTIONS:- } " ]
150+ }
151+
146152is_ci_android () {
147- [ " $PLATFORM " = android ] && { [ -n " ${CI :- } " ] || [ -n " ${GITHUB_ACTIONS :- } " ] ; }
153+ [ " $PLATFORM " = android ] && is_ci
148154}
149155
150156is_driver_startup_crash () {
@@ -165,8 +171,8 @@ run_maestro() {
165171 local max_attempts rc tmp attempt=1 delayed_retry=0
166172 if [ -n " ${MAESTRO_MAX_RETRIES:- } " ]; then
167173 max_attempts=" $MAESTRO_MAX_RETRIES "
168- elif is_ci_android ; then
169- max_attempts=3 # 1 initial run + 2 retries
174+ elif is_ci ; then
175+ max_attempts=2 # 1 initial run + 1 retry
170176 else
171177 max_attempts=1
172178 fi
@@ -214,6 +220,15 @@ run_maestro() {
214220 rm -f " $tmp "
215221 continue
216222 fi
223+ elif is_ci && [ " $attempt " -lt " $max_attempts " ]; then
224+ echo " warn: test run failed (attempt $attempt /$max_attempts ), retrying in 5s..." >&2
225+ if [ " $PLATFORM " = android ]; then
226+ cleanup_devicelab_driver
227+ fi
228+ sleep 5
229+ attempt=$(( attempt + 1 ))
230+ rm -f " $tmp "
231+ continue
217232 fi
218233
219234 rm -f " $tmp "
0 commit comments