Sub topic 1
How CI triggers and status checks work
This chapter gives you the working model for the rest of the tutorial. Every decision about where a check belongs comes down to two mechanisms. A trigger decides when a workflow starts. A status check reports the result back to the commit and decides whether a merge is allowed.
Prerequisites
This chapter assumes you already have the following:
- You can open a pull request (PR), push commits to a branch, and read a diff.
- You have used a CI system. The examples use GitHub Actions, but GitLab CI and Jenkins have close equivalents.
- You know what linting, unit tests, and integration tests are.
You don't need to have configured branch protection or a merge queue.
The pieces of a CI setup
A CI pipeline is an automated sequence of steps that runs against a specific commit. In GitHub Actions the vocabulary is:
- A workflow is a YAML file in
.github/workflows/. It declares when it runs and what it does. - A trigger (an
on:entry) is an event that starts a workflow. - A job is a group of steps that runs on one runner (a machine provided by the CI system).
- A step is a single command or reusable action.
- A status check is the result a job reports to a commit: queued, in progress, success, failure, skipped, and a few others.
Each trigger produces a workflow run. Each job in that run reports one status check. The trigger answers "should anything run now?" and the status check answers "did it pass?"
Triggers: what starts a run
The same workflow file can listen for several events. The ones that matter for placing checks are these:
| Event | Fires when | Code the run sees |
|---|---|---|
| `pull_request` | A PR is opened, updated with new commits, or reopened | A temporary merge of the PR branch into its base branch |
| `merge_group` | A merge queue builds a candidate commit | The queue's candidate: your change on top of the base and any PRs ahead of it |
| `push` | Commits land on a branch | The pushed commit |
| `schedule` | A cron time arrives | The latest commit on the default branch |
| `workflow_dispatch` | Someone starts the workflow manually | The branch or tag chosen at dispatch |
Three details in this table cause real confusion.
pull_request does not test your branch tip alone. For a PR, actions/checkout gets a merge commit that combines your branch with the current base branch. This is the refs/pull/<number>/merge ref. A check can therefore pass on your laptop and fail on the PR because the base moved. It also means the result goes stale when the base changes, which is one reason merge-time checks exist.
schedule always runs on the default branch. You cannot schedule a run against a feature branch. Scheduled runs can start a few minutes late when the platform is busy. On public repositories, GitHub disables scheduled workflows after 60 days without repository activity.
merge_group only fires if the workflow listens for it. If a merge queue is enabled and a required check lives in a workflow without a merge_group: trigger, that check never reports for the queue's candidate commit. The queue then waits for a result that never arrives. The next chapters return to this.
A PR trigger looks like this:
name: pr
on:
pull_request:
branches: [main]
jobs:
fast-checks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- run: npm ci
- run: npm run lint
- run: npm testThe branches: [main] filter limits the workflow to PRs that target main. By default pull_request fires on three activity types: opened, synchronize (new commits pushed), and reopened. Editing a PR description does not rerun it.
Seeing the trigger in action
To see how triggers differ, add a throwaway workflow that prints what it received. It listens for every event in the table above:
name: show-trigger
on:
pull_request:
merge_group:
push:
branches: [main]
schedule:
- cron: '0 2 * * *'
workflow_dispatch:
jobs:
show:
runs-on: ubuntu-latest
steps:
- run: |
echo "event: ${{ github.event_name }}"
echo "ref: ${{ github.ref }}"
echo "sha: ${{ github.sha }}"Open a PR and read the log. The event is pull_request and the ref looks like refs/pull/42/merge. Run it manually from the Actions tab and the event is workflow_dispatch on a branch ref. Compare the sha values with git log to see which commit each run tested. Delete the file when you are done, because it spends runner minutes on every trigger.
Status checks: how results reach the PR
A runner executes a job and reports the outcome to GitHub, attached to the commit SHA that was tested. The PR page displays the results for the PR's head commit.
GitHub has two kinds of status reports. Check runs come from Actions and other GitHub Apps and carry rich output such as annotations and logs. Commit statuses are the older, simpler form, a state plus a context string, which external CI systems often still use. Branch protection treats both the same way. You select a check by its name.
For Actions, a check's name is the job name. If a job has no name: key, the name is the job ID, such as fast-checks. The UI shows it as workflow name / job name, but branch protection matches on the job name. Renaming a job therefore changes the check's identity, and a required check with the old name will wait forever. Matrix jobs create one check per combination, for example test (20) and test (22).
A check can end in one of these states:
| State | Meaning | Effect on a required check |
|---|---|---|
| Pending or queued | Waiting for a runner, or never started | Blocks the merge |
| In progress | Running | Blocks the merge |
| Success | All steps passed | Satisfies it |
| Failure | A step failed, or the job timed out | Blocks the merge |
| Cancelled | Stopped, often by a newer push | Blocks the merge |
| Skipped | Job-level `if:` evaluated false | Counts as passing |
The last row catches many people out. A job skipped by an if: condition reports "Skipped" and satisfies a required check. A workflow that never starts, because its paths: filter excluded every changed file, reports nothing. The required check then sits at "Expected, waiting for status" and blocks the PR. The same trigger-versus-status distinction explains most surprises in this tutorial.
Required checks and the merge decision
Reporting a status doesn't stop a merge by itself. A failing check only blocks a merge if the target branch has a branch protection rule or ruleset that lists it as required. Without that, a red check is advice. With it, the merge button stays disabled until every required check reports success on the head commit.
The flow looks like this:
A new push to the PR branch starts a fresh run. Results attach to commit SHAs, so old results don't carry over to the new head.
Why triggers decide where a check belongs
Each trigger sits at a different point in a change's life and gives different feedback:
pull_requestruns while the author is still in context and can fix things quickly. It gives early feedback on the PR's own changes.merge_groupandpushtomaintest the code as it will actually be integrated. They catch problems that appear only when changes combine.scheduleruns on its own clock, with no author waiting. A run can take hours without blocking anyone, but a failure is no longer tied to one change.
Placing a check means choosing the trigger whose timing and failure signal fit that check. The next chapters build the vocabulary to make that choice: speed against confidence, then the cost of each kind of check, then a decision process.
Common errors
- Wrong event for the job. A slow suite on
pull_requestmakes every PR wait. A fast suite only onschedulelets bugs sit until the next morning. - Missing
merge_grouptrigger. The merge queue hangs waiting for a required check that never reports. - Renamed job, stale required check. The old name stays required and never reports.
- Path filter on a required workflow. The workflow doesn't start, so the check stays pending. A job-level
if:skips cleanly instead. - Expecting
scheduleon a branch. Scheduled runs use the default branch only. - Assuming the PR check tested the final result. It tested a merge with the base as it was at run time.
Exercise
A team requires a check named integration on main. They enable a merge queue, but every queued PR hangs with "Expected, waiting for status". The workflow containing integration has on: pull_request and on: push: branches: [main]. What is missing, and why does the queue hang?
Show answer
The workflow has no merge_group: trigger. The merge queue builds a candidate commit and expects the required integration check to report on it. Because the workflow doesn't listen for merge_group, it never starts for that commit, no status is reported, and the queue waits. Adding merge_group: under on: fixes it.
Exercise
A workflow has on: pull_request: paths: ['src/**'], and its job unit-tests is a required check. A contributor opens a PR that changes only README.md. What happens, and what are two ways to avoid it?
Show answer
The paths filter excludes every changed file, so the workflow never starts and unit-tests never reports. The required check stays pending and blocks the merge. Two fixes: remove the paths: filter and skip work inside the workflow with a job-level if: (a skipped job counts as passing), or use a separate always-running job that detects the changed paths and report success when nothing relevant changed.