Sub topic 5
Choosing triggers: pull requests, pushes, and manual runs
This chapter assumes you can read a GitHub Actions workflow file and know the basics of branches and pull requests. A trigger is the event that starts a workflow. The on: key lists the triggers. For a Salesforce pipeline you usually need three of them.
The three triggers
| Trigger | Fires when | Typical Salesforce use |
|---|---|---|
| `pull_request` | A pull request is opened or updated | Check-only deployment with tests |
| `push` | Commits land on a branch | Real deployment after merge |
| `workflow_dispatch` | Someone clicks Run workflow or calls the API | Redeploys, hotfixes, ad hoc test runs |
A workflow with all three
name: Trigger demo
on:
pull_request:
branches: [main]
types: [opened, synchronize, reopened]
paths:
- 'force-app/**'
push:
branches: [main]
workflow_dispatch:
inputs:
test-level:
description: Apex test level
type: choice
options: [NoTestRun, RunLocalTests, RunAllTestsInOrg]
default: RunLocalTests
jobs:
show:
runs-on: ubuntu-latest
steps:
- name: Show what started this run
run: |
echo "Event: ${{ github.event_name }}"
echo "Test level: ${{ inputs.test-level || 'RunLocalTests' }}"Each filter narrows when the workflow starts:
brancheslimits the target branch. Forpull_requestit is the branch the PR merges into, not the source branch.typeslimits which PR actions count. The three listed here are the defaults.synchronizemeans new commits were pushed to the PR branch.pathsskips the run unless a changed file matches. Here, a PR that only edits documentation does not start a deployment check.inputsadds fields to the manual run form. On other eventsinputs.test-levelis empty, so the||supplies a default.
Mapping triggers to your branch strategy
With one long-lived branch, use pull_request to main for validation and push to main for deployment. With several environments, add one branch per environment, such as develop for a sandbox and main for production. Then give each its own push workflow or branch filter. Chapter 12 covers promotion in detail.
Common errors
- Secrets are empty on forked pull requests. GitHub does not pass secrets to workflows triggered from forks, so authentication fails. Validate internal branches, or review fork code before running anything against an org.
- Required check never reports. If a branch protection rule requires the validation check, a
pathsfilter that skips the run leaves the check pending, and the PR cannot merge. Remove the filter, or add a small always-passing job. - Deploying on
pull_request. That event runs on unmerged code. Keep it check-only with--dry-run, and deploy only onpush. - Manual runs on the wrong branch.
workflow_dispatchuses the branch you pick in the UI. Confirm it before running against production.
Exercise
A team requires the "validate" check before merging, but the workflow uses paths: ['force-app/**']. A developer opens a PR that changes only README.md. What happens, and how can the team fix it?
Show answer
The workflow does not run, so the required check stays pending and the PR cannot merge. The team can remove the paths filter, or keep it and add a lightweight job that always reports success, so the required check always completes.