prevent a job in github action workflow file to run in case of an event

Viewed 24

I have a github action workflow validate which currently runs on

on:
  pull_request:
    types: [opened, synchronize, reopened, edited]

there are multiple jobs in this workflow - but for the 1st job - I don't want it to run when a PR is edited.

Hence I've written something like:

jobs:
  run_tests:
    name: Run Tests
    continue-on-error: false
    if: github.event.pull_request.edited != true

But this is not working - when I edit the pull request - the 1st job starts running...

I had even tried with

if: github.event.pull_request.action != 'edited'

How can I prevent this sub-job from running only for a specific pull_request event.

Thanks again Prabhas

1 Answers

After making some tests, I observed that you need another syntax to check the pull request event type.

I actually had to use ${{ github.event.action }}

Example:

if: github.event.action == 'edited'

To do so, I checked the GITHUB CONTEXT inside the workflow run (you can see the logs here) and observed that the event actually appears like this:

{
  [...]
  "base_ref": "main",
  "event_name": "pull_request",
  "event": {
    "action": "edited",
    [...]
  }
}

Where this event.action field would change according to the type (for example, you will have a "synchronize" there, if you update the PR files or description).

I made a full workflow example here if you want to check, with this workflow run (when edited), and this other workflow run (when synchronized).

Related