How to Trigger a Workflow on a Pull Request in GitHub Actions
The pull_request event runs your workflow against the merge result of a PR, which is exactly what you want for status checks.
Add on.pull_request and optionally narrow it with types: (opened, synchronize, reopened). The workflow checks out the merged code so tests reflect what will land.
Steps
- Add
pull_request:underon. - Optionally list
types:to control which PR activity fires the run. - Read the base and head refs from
github.base_refandgithub.head_ref.
Workflow
.github/workflows/ci.yml
on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm ci && npm testGotchas
- On PRs from forks,
GITHUB_TOKENis read-only and secrets are not passed, by design. - The default types are opened, synchronize, and reopened; declaring
types:replaces that set entirely.
Related guides
How to Safely Trigger on pull_request_target in GitHub ActionsUse the pull_request_target event to run trusted automation on fork PRs in GitHub Actions with write access,…
How to Trigger a Workflow When a Review Is Requested in GitHub ActionsRun a GitHub Actions workflow when a reviewer is requested on a pull request using the review_requested activ…