Home > Blockchain >  GitHub actions not blocking PR with required step in skipped state
GitHub actions not blocking PR with required step in skipped state

Time:02-25

I have the GitHub action that should only be ran when the commit message contains 'test_api'. However, I do want it to be a required check for the PR to be able to get merged. For some reason this is not picked up, and it does not make any sense to me.

jobs:
  api-tests:
    if: contains(github.event.commits[0].message, '[test_api]')
    runs-on: ubuntu-latest
    ...

PR ready to merge

Branch protection

CodePudding user response:

It says that tests were skipped - that means this is not true:

if: contains(github.event.commits[0].message, '[test_api]')

Unless you have more actions in the workflow.

CodePudding user response:

I would force a failure if the condition isn't true.

jobs:
  api-tests:
    if: contains(github.event.commits[0].message, '[test_api]')
    runs-on: ubuntu-latest
    steps:
      ...
    
  not-api-tests:
    if: "!contains(github.event.commits[0].message, '[test_api]')"
    runs-on: ubuntu-latest
    steps:
    - uses: actions/[email protected]
    - name: Fail the job
      run: exit 1

Note: This should work on all 3 platforms (ubuntu, macos, windows).

I tested it here (committing with [test_api]) and here (forcing the error with another commit message). The workflow implementation can be found here.

  • Related