Skip to content
Latchkey

How to Run Selective CI From Pull Request Labels

Gating a job on contains(github.event.pull_request.labels.*.name, run-e2e) lets a reviewer trigger an expensive suite by adding a label, on top of automatic change detection.

Sometimes the human knows best. Gate an expensive job with an if that checks the PR labels, so it runs only when someone applies (say) run-e2e. Trigger on the labeled event so adding the label re-runs the workflow.

Steps

  • Add labeled to the pull_request types.
  • Gate the job on contains(github.event.pull_request.labels.*.name, 'run-e2e').
  • Combine with change detection for a belt-and-suspenders trigger.

Workflow

.github/workflows/ci.yml
on:
  pull_request:
    types: [opened, synchronize, labeled]
jobs:
  e2e:
    if: contains(github.event.pull_request.labels.*.name, 'run-e2e')
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npm ci && npm run test:e2e

Gotchas

  • Labels are only on pull_request events; the same expression is empty on push, so the job simply will not run there.
  • If the labeled job is a required check, a PR without the label leaves it pending; keep label-gated jobs optional.

Related guides

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