Rerun Workflow Runs #1271
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: Rerun Workflow Runs | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| TERM: xterm-256color | |
| ########################################################################## | |
| concurrency: | |
| group: "workflow = ${{ github.workflow }}, ref = ${{ github.event.ref }}, pr = ${{ github.event.pull_request.id }}" | |
| cancel-in-progress: true | |
| on: | |
| workflow_run: | |
| workflows: | |
| - Initializr Build | |
| - Initializr Native Image | |
| - Initializr Helm Charts | |
| types: | |
| - completed | |
| branches: | |
| - master | |
| ########################################################################## | |
| jobs: | |
| rerun-failed-jobs: | |
| runs-on: ubuntu-latest | |
| continue-on-error: true | |
| if: ${{ github.event.workflow_run.conclusion == 'failure' && github.event.workflow_run.status == 'completed' }} | |
| steps: | |
| - name: Rerunning ${{ github.event.workflow_run.name }} | |
| run: | | |
| echo "Workflow run ID: ${{ github.event.workflow_run.id }}" | |
| echo "Workflow run Name: ${{ github.event.workflow_run.name }}" | |
| echo "Workflow run attempt #: ${{ github.event.workflow_run.run_attempt }}" | |
| CURRENT_ATTEMPTS=${{ github.event.workflow_run.run_attempt }} | |
| if [ "$CURRENT_ATTEMPTS" -le 2 ]; then | |
| echo "Rerunning failed workflow jobs for workflow ${{ github.event.workflow_run.name }}..." | |
| gh api --method POST -H "Accept: application/vnd.github+json" /repos/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}/rerun-failed-jobs | |
| else | |
| echo "Max run attempts reached. Not rerunning." | |
| fi |