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
ifongithub.event.actionfor 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
actionfield differs per event; check the event schema before filtering on it.
Related guides
How to Read Webhook Payloads and Event TypesRead a webhook payload correctly by routing on the event header first, then accessing the action and object f…
How to Choose Between workflow_dispatch, repository_dispatch, and WebhooksChoose the right trigger by comparing workflow_dispatch for manual runs, repository_dispatch for external POS…