Run in case of failure



examples/workflows/in-case-of-failure.yml
name: Failure?

on:
    push:
        branches: '*'
    pull_request:
        branches: '*'

jobs:
  build:
    runs-on: ubuntu-latest
    name: Job

    steps:
    - uses: actions/checkout@v3

    - name: Step one
      run: |
        echo Always runs
        #ls blabla

    - name: Step two (run on failure)
      if: ${{ failure() }}
      run: echo There was a failure

    - name: Step three
      run: |
          echo Runs if there was no failure
          #ls blabla

You can create a step that will run only if any of the previous steps failed. In this example if you enable the "ls" statement in "Step one" it will fail that will make Step two execute, but Step three won't because there was a failure.

On the other hand if Step One passes then Step Two won't run. Step three will then run.

A failure in step three (e.g. by enabling the ls statement) will not make step Two run.