Deflake Tests #6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deflake Tests | |
| description: Re-triggers test jobs if they failed. | |
| on: | |
| workflow_run: | |
| workflows: [linux] | |
| types: | |
| - completed | |
| jobs: | |
| rerun-failing-jobs: | |
| runs-on: ubuntu-latest | |
| if: github.event.workflow_run.conclusion == 'failure' || github.event.workflow_run.conclusion == 'cancelled' | |
| permissions: | |
| actions: write | |
| checks: read | |
| steps: | |
| - name: Checkout repo | |
| uses: actions/checkout@v4 | |
| - name: Check Retry Count | |
| id: retry_check | |
| env: | |
| DEFLAKE_ATTEMPTS: 3 | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| WORKFLOW: ${{ github.event.workflow_run.id }} | |
| shell: bash | |
| run: | | |
| set +x | |
| # Attempt to access the last attempt of the workflow that triggereed this one. | |
| if gh run view ${WORKFLOW} --attempt ${DEFLAKE_ATTEMPTS}; then | |
| echo "continue=false" >> ${GITHUB_OUTPUT} | |
| else | |
| echo "continue=true" >> ${GITHUB_OUTPUT} | |
| fi | |
| - name: Rerun Failing Checks | |
| if: steps.retry_check.outputs.continue == 'true' | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| REPO: ${{ github.repository }} | |
| WORKFLOW: ${{ github.event.workflow_run.id }} | |
| shell: bash | |
| run: | | |
| set +x | |
| echo "Rerunning failed jobs for workflow run ${WORKFLOW}" | |
| gh run rerun "${WORKFLOW}" --repo "${REPO}" --failed |