Skip to content

Commit bda9bd7

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 2c04b54 commit bda9bd7

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,3 +632,24 @@ 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() && fromJSON(github.run_attempt) < 3 && ${{ github.ref == 'refs/heads/main' || contains(github.ref, 'stable') || inputs.run-e2e-tests }}
649+
steps:
650+
- name: Checkout
651+
uses: actions/checkout@v4
652+
- name: Rerun failed jobs in the current workflow
653+
env:
654+
GH_TOKEN: ${{ github.token }}
655+
run: gh workflow run retry-workflow.yml -F run_id=${{ github.run_id }}

0 commit comments

Comments
 (0)