Skip to content
Latchkey

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: under on.
  • Optionally list types: to control which PR activity fires the run.
  • Read the base and head refs from github.base_ref and github.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 test

Gotchas

  • On PRs from forks, GITHUB_TOKEN is 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

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