Restart workflow from workflow

Hello

Any idea how to restart the entire workflow automatically if any step fails (restart)? I know it can be done manually.

Clarification: I mean resetting it to full, not from the point it failed (which I know it is impossible)

EG:

Step 1 - OK
Step 2 - OK
Step 3 - FAIL
RESTART (back to step 1)

Thanks a lot!

Hi @murciaelx ,

Github support rest api to restart the workflow. Please check the link here:

https://developer.github.com/v3/actions/workflow-runs/#re-run-a-workflow

You need another workflow to restart the first workflow, since the first workflow need to be completed.

Tried on my side, it works. 

workflow one: the failed workflow

job2:
    runs-on: [ubuntu-latest]
    steps:
      - name: step1
        run: |
          echo step1
      - name: step2 # the fail step
        run: |
          fail
      - name: send info to restart workflow # send out the info about the workflow
        if: failure()
        uses: peter-evans/repository-dispatch@v1
        with:
          token: ${{ secrets.PAT2 }}
          event-type: restart
          client-payload: '{"runid": "${{ github.run_id }}"}' # the run_id

In master branch, create a new yaml to restart the workflow one.

name: restart workflow
on:
  repository_dispatch:
    types: [restart]
jobs:
  job1:
    runs-on: ubuntu-latest
    steps:
      - name: restart workflow
        run: |
          URL=https://api.github.com/repos/${{github.repository}}/actions/runs/${{ github.event.client_payload.runid }}/rerun
          curl -X POST -u "weide-zhou:${{secrets.PAT2}}" $URL

Thanks.