Skip to content

Commit 4b43f09

Browse files
cipolleschifacebook-github-bot
authored andcommitted
Add automatic retry of failed workflows to improve E2E stability (#51627)
Summary: This cdhanges are inspired by https://stackoverflow.com/a/78314483 and they should help with the stability of E2E tests on main. Most of the time, those tests fails because of flakyness in the E2E infrastructure on GHA. Usually, rerunning the tests manually makes the workflow pass. These couple of jobs automatically reruns the workflow up to 3 times in case one of the E2E tests fails ## Changelog: [Internal] - improve CI by rerunning the workflow if the E2E tests fails Reviewed By: cortinico Differential Revision: D75449445
1 parent 56c1ab3 commit 4b43f09

File tree

2 files changed

+43
-5
lines changed

2 files changed

+43
-5
lines changed

.github/workflows/retry-workflow.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Retry workflow
2+
# Based on https://stackoverflow.com/a/78314483
3+
4+
on:
5+
workflow_dispatch:
6+
inputs:
7+
run_id:
8+
required: true
9+
jobs:
10+
rerun:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: rerun ${{ inputs.run_id }}
14+
env:
15+
GH_REPO: ${{ github.repository }}
16+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
17+
run: |
18+
gh run watch ${{ inputs.run_id }} > /dev/null 2>&1
19+
gh run rerun ${{ inputs.run_id }} --failed

.github/workflows/test-all.yml

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ jobs:
187187
flavor: ${{ matrix.flavor }}
188188

189189
test_e2e_ios_rntester:
190-
if: ${{ github.ref == 'refs/heads/main' || contains(github.ref, 'stable') || inputs.run-e2e-tests }}
190+
# if: ${{ github.ref == 'refs/heads/main' || contains(github.ref, 'stable') || inputs.run-e2e-tests }}
191191
runs-on: macos-14-large
192192
needs:
193193
[test_ios_rntester]
@@ -221,7 +221,7 @@ jobs:
221221
flavor: ${{ matrix.flavor }}
222222

223223
test_e2e_ios_templateapp:
224-
if: ${{ github.ref == 'refs/heads/main' || contains(github.ref, 'stable') || inputs.run-e2e-tests }}
224+
# if: ${{ github.ref == 'refs/heads/main' || contains(github.ref, 'stable') || inputs.run-e2e-tests }}
225225
runs-on: macos-14-large
226226
needs: [build_npm_package, prebuild_apple_dependencies]
227227
env:
@@ -312,7 +312,7 @@ jobs:
312312
architecture: ${{ matrix.architecture }}
313313

314314
test_e2e_android_templateapp:
315-
if: ${{ github.ref == 'refs/heads/main' || contains(github.ref, 'stable') || inputs.run-e2e-tests }}
315+
# if: ${{ github.ref == 'refs/heads/main' || contains(github.ref, 'stable') || inputs.run-e2e-tests }}
316316
runs-on: 4-core-ubuntu
317317
needs: build_npm_package
318318
continue-on-error: true
@@ -439,11 +439,11 @@ jobs:
439439
uses: ./.github/actions/build-android
440440
with:
441441
release-type: ${{ needs.set_release_type.outputs.RELEASE_TYPE }}
442-
run-e2e-tests: ${{ github.ref == 'refs/heads/main' || contains(github.ref, 'stable') || inputs.run-e2e-tests }}
442+
run-e2e-tests: true # ${{ github.ref == 'refs/heads/main' || contains(github.ref, 'stable') || inputs.run-e2e-tests }}
443443
gradle-cache-encryption-key: ${{ secrets.GRADLE_CACHE_ENCRYPTION_KEY }}
444444

445445
test_e2e_android_rntester:
446-
if: ${{ github.ref == 'refs/heads/main' || contains(github.ref, 'stable') || inputs.run-e2e-tests }}
446+
# if: ${{ github.ref == 'refs/heads/main' || contains(github.ref, 'stable') || inputs.run-e2e-tests }}
447447
runs-on: 4-core-ubuntu
448448
needs: [build_android]
449449
strategy:
@@ -632,3 +632,22 @@ jobs:
632632
uses: ./.github/actions/lint
633633
with:
634634
github-token: ${{ env.GH_TOKEN }}
635+
636+
# This job should help with the E2E flakyness.
637+
# In case E2E tests fails, it launches a new retry-workflow workflow, passing the current run_id as input.
638+
# The retry-workflow reruns only the failed jobs of the current test-all workflow using
639+
# ```
640+
# gh run rerun ${{ inputs.run_id }} --failed
641+
# ```
642+
# From https://stackoverflow.com/a/78314483 it seems like that adding the extra workflow
643+
# rather then calling directly this command should improve stability of this solution.
644+
# This is exactly the same as rerunning failed tests from the GH UI, but automated.
645+
rerun-failed-jobs:
646+
runs-on: ubuntu-latest
647+
needs: [test_e2e_ios_rntester, test_e2e_android_rntester,test_e2e_ios_templateapp, test_e2e_android_templateapp]
648+
if: failure() && ${{ github.ref == 'refs/heads/main' || contains(github.ref, 'stable') || inputs.run-e2e-tests }} && fromJSON(github.run_attempt) < 3
649+
steps:
650+
- name: Rerun failed jobs in the current workflow
651+
env:
652+
GH_TOKEN: ${{ github.token }}
653+
run: gh workflow run ./.github/workflows/retry-workflow.yml -F run_id=${{ github.run_id }}

0 commit comments

Comments
 (0)