How do you trigger a workflow on pushes to `main` and on PRs that target `main`?
BeginnerConceptTriggers & Events
Answer
on:
push:
branches: [main]
pull_request:
branches: [main]
For pull_request, branches filters the base branch, not the head. Without filters, the workflow runs on every push to every branch and every PR, which doubles runs when a PR branch is pushed (one push, one pull_request).
More on Triggers & Events
What activity types does `pull_request` trigger on by default, and how do you add more?IntermediateHow do `branches` and `branches-ignore` filters work with globs?BeginnerHow do path filters work, and what are their limits?AdvancedHow do you trigger only on version tags, and what is the gotcha with pushing many tags?IntermediateWhat is `workflow_dispatch`, and what input types does it support?BeginnerWhy does `github.event.inputs.dry_run == true` never match, while `inputs.dry_run` works?Intermediate