Skip to content
Latchkey

How to Run a Step Only for a Specific Label in GitHub Actions

Test contains(github.event.pull_request.labels.*.name, 'deploy') to gate on a label.

The labels.*.name array holds every label on the PR. Use contains against it, and trigger on the labeled action so re-labeling re-evaluates.

Steps

  • Add pull_request types [labeled, opened, synchronize] to on.
  • Gate the step with contains(github.event.pull_request.labels.*.name, '<label>').
  • Match the label name exactly, including case.

Workflow

.github/workflows/ci.yml
on:
  pull_request:
    types: [labeled, opened, synchronize]
jobs:
  preview:
    runs-on: ubuntu-latest
    steps:
      - name: Deploy preview
        if: contains(github.event.pull_request.labels.*.name, 'deploy-preview')
        run: ./deploy-preview.sh

Gotchas

  • The labels.*.name object filter returns an array; contains checks membership.
  • Without the labeled trigger type, adding a label later will not start a new run.

Related guides

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