Checkout action depending on pull_request or push

Hi

I would like to be able to checkout the branch that is merging into master, instead of master, when the checkout action is ran.
So I looked it up and found this in the docs.

Now I would like to not need to recreate the whole flow when the triggered event is a push in the master branch instead of a pull request…

So is there a way I can add an “IF” statement based on whether it is running on “push” or “pull_request” ?

My current piece of code as follows:

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master, staging ]

jobs:
  Validate_and_Test:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2
      with:
        ref: ${{ github.event.pull_request.head.sha }}
    - name: Set up Python 3.6
      uses: actions/setup-python@v2
      with:
        python-version: 3.6

Yes, you can do quite fancy magical things, here’s a workflow that I use:

you can see that it decides how to perform a checkout based on the event.

In theory, I could probably use a combined step instead of using multiple conditional steps, but the logic is clear enough this way and it means someone can see at a glance if it is checking out a normal branch, or a merge.