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
labeledto the pull_requesttypes. - 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:e2eGotchas
- Labels are only on
pull_requestevents; 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
How to Build a Dynamic Matrix From Changed DirectoriesGenerate a GitHub Actions job matrix at runtime from the directories that changed, using fromJSON so only aff…
How to Add a Force Full Build Option to Incremental CIGive incremental CI an escape hatch to run the full build on demand via workflow_dispatch input or a commit m…
How to Fix Stuck Required Checks With Conditional JobsSolve the pending required check problem in incremental CI, where a skipped job never reports status, by usin…