github-action: does the IF have an ELSE?

GitHub Actions doesn't have else statement to run a different command/action/code. But you're right, all what you need to do is to create another step with reversed if condition. BTW, you can just use ! instead of false ==, if you surround your statement with ${{ }}.

Here are some links: if statement, operators


You can do the following which would only run the script where the condition passes:

job_name:
  runs-on: windows-latest
  if: "!contains(github.event.head_commit.message, 'SKIP SCRIPTS')"    <--- skips everything in this job if head commit message does not contain 'SKIP SCRIPTS'

  steps:
    - uses: ....
  
    - name: condition 1
      if: "contains(github.event.head_commit.message, 'CONDITION 1 MSG')"
      run: script for condition 1

   - name: condition 2
      if: "contains(github.event.head_commit.message, 'CONDITION 2 MSG')"
      run: script for condition 2

and so on. Of course you would use your own condition here.


You may consider using the haya14busa/action-cond action. It is useful when the if-else operation is needed to set dynamic configuration of other steps (don't need to duplicate the whole step to set different values in a few parameters).

Example:

- name: Determine Checkout Depth
  uses: haya14busa/action-cond@v1
  id: fetchDepth
  with:
    cond: ${{ condition }}
    if_true: '0'  # string value
    if_false: '1' # string value
- name: Checkout
  uses: actions/checkout@v2
  with:
    fetch-depth: ${{ steps.fetchDepth.outputs.value }}