Skip to content
Latchkey

How to Trigger a Workflow When a Label Is Added in GitHub Actions

The pull_request labeled type fires whenever a label is added, and an if check narrows it to the exact label you want.

Add types: [labeled] to the pull_request event, then gate the job with if: github.event.label.name == 'deploy-preview'.

Steps

  • Add pull_request: with types: [labeled].
  • Gate the job on github.event.label.name.
  • The event fires once per label addition.

Workflow

.github/workflows/preview.yml
on:
  pull_request:
    types: [labeled]
jobs:
  preview:
    if: github.event.label.name == 'deploy-preview'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: ./deploy-preview.sh

Gotchas

  • A PR opened with a label already applied does not fire labeled; only later additions do.
  • github.event.label exists only for the labeled and unlabeled types, not for other pull_request types.

Related guides

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