Skip to content
Latchkey

How to Filter Webhook Events in a Workflow

Narrow a workflow to the events you want with a types: list on the trigger and an if on the action.

Set a types: list on the event (for example pull_request: types: [opened, reopened]) and add an if on github.event.action for finer control inside the job.

Steps

  • Add a types: list under the event to limit which activities trigger it.
  • Add a job or step if on github.event.action for finer filtering.
  • Combine with branch or path filters to narrow further.

Workflow

.github/workflows/ci.yml
on:
  pull_request:
    types: [opened, reopened, synchronize]
jobs:
  label:
    if: github.event.action == 'opened'
    runs-on: ubuntu-latest
    steps:
      - run: echo "New PR #${{ github.event.number }}"

Gotchas

  • Omitting types: defaults to a broad set; list them explicitly to avoid extra runs.
  • The action field differs per event; check the event schema before filtering on it.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →