Sub topic 1
How CI triggers and status checks work
Prerequisites
This chapter assumes you know the basic Git and pull request workflow. It also assumes you have used a CI system such as GitHub Actions, GitLab CI, or Jenkins, and that you know what linting, unit tests, and integration tests are. The examples use GitHub Actions. The ideas carry over to other systems, though the names differ.
The working model
A CI pipeline is a set of automated jobs that runs when something happens in your repository. Three parts matter for placement decisions:
- A trigger is the event that starts a run, such as a pull request being opened or a clock reaching a set time.
- A job is a unit of work that runs on a fresh machine and executes your commands.
- A status check is the pass or fail result a job reports back to the commit. The result appears in the pull request, and branch protection can require it before merging.
Every placement decision in this tutorial comes down to choosing which trigger starts which jobs.
The three trigger families
Most pipelines use three families of triggers. Each runs against a different version of the code.
| Trigger | GitHub Actions event | Code under test | Typical timing |
|---|---|---|---|
| Pull request | `pull_request` | The PR branch merged with its target branch | Minutes after each push |
| Merge or main | `merge_group`, `push` to `main` | The candidate or merged commit | At or after merge |
| Scheduled | `schedule`, `workflow_dispatch` | The default branch | Overnight or on demand |
The sections below show how a push to a branch moves through these triggers.
A workflow that runs on pull requests
This workflow runs lint and unit tests when a pull request targets main.
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 on block is the trigger. The jobs block defines the work. The job name, fast-checks, becomes the name of the status check. When branch protection requires a check, it matches this name. A later chapter covers that setup.
How a status check reports
Each job reports one of a few states to the commit it ran on:
- Queued or in progress, while the job waits or runs.
- Success, when every step exits with code 0.
- Failure, when any step exits with a nonzero code.
- Skipped, when the job did not run, for example because of a filter.
A pull request shows these states next to the head commit. A new push creates a new run for the new commit. Results from the old commit do not carry over.
Where triggers differ
Triggers differ in which commit they test and which branch's workflow file they read.
pull_requesttests a temporary merge of your branch with the target branch. It reads the workflow file from that merge result.pushtomaintests the commit that actually landed.schedulealways runs the workflow file on the default branch. Changing a cron line on a feature branch has no effect until it merges.
Common errors
- Writing a workflow with the wrong event name, so it never runs. For example, a merge queue only starts workflows that listen for
merge_group. - Testing a feature branch cron change and wondering why nothing fires.
- Assuming a green result on an old commit still applies after a new push.
- Giving jobs vague or duplicate names, which makes required checks ambiguous.
Exercise
A teammate edits the cron line in a workflow on a feature branch and opens a pull request. The nightly run does not use the new time. Why, and what makes it take effect?
Show answer
The schedule trigger only reads the workflow file on the default branch. The new cron line takes effect after the pull request merges into that branch. Until then, you can use workflow_dispatch to start a manual run.