A job needs to run only when a label such as `deploy-preview` is on the PR.
BeginnerScenarioGitHub Actions
Answer
Situation read → Conditional job on PR metadata.
What I'd do →
on:
pull_request:
types: [opened, synchronize, labeled]
jobs:
preview:
if: contains(github.event.pull_request.labels.*.name, 'deploy-preview')
Why → labeled must be in types or adding the label will not trigger a run.
Interview tip → Default PR types are opened, synchronize and reopened.
More on GitHub Actions
What are workflows, jobs, steps and actions in GitHub Actions?BeginnerWhat events can trigger a workflow?BeginnerWhat is the difference between `pull_request` and `pull_request_target`?AdvancedWhat is a runner, and how do GitHub-hosted and self-hosted runners differ?BeginnerHow do you pass data between steps and between jobs?IntermediateHow does a build matrix work?Intermediate