Continuous integration
Last updated
Four people change Pila every day. If each works alone for weeks and then merges, the merges are painful and the bugs pile up where nobody can see them. Continuous integration is the habit, and the machinery, that stops that: merge small changes often, and let a server build and test every one. In this lesson you'll watch Pila's pipeline run on four pushes, read a red build's log to find what broke, and learn the team rules that make CI work.
By the end of this lesson you can
- Explain continuous integration: merging often, with every change built and tested
- Read a pipeline’s result and its log to find why a build failed
- Follow the team rules that keep the main branch green
Integration hell
Picture Pila's four developers each working on a separate branch for a month, then merging on the same day. Each branch worked alone. Together, they conflict in a hundred places, and the tests fail for reasons nobody can trace, because a month of four people's changes arrived at once. Teams in the 1990s called this integration hell, and some spent longer integrating than building.
The fix sounds backwards: if merging hurts, do it more often, so each merge is small.
Merge often, check every change
Continuous integration (CI) is two habits together:
- Merge small changes into the main branch often, at least daily. Branches live hours or a day or two, not weeks. Paul Hammant's name for this is trunk-based development.
- Every change is built and tested automatically by a server, on a clean computer, before and after it's merged. The steps it runs are called the pipeline.
If every step passes, the build is green; if any fails, it's red. Martin Fowler adds the rule that makes it work: a red main branch is everyone's first job. Nobody piles more changes on top of a broken build; the person whose change broke it fixes it, or reverts it, within minutes.
DORA's research finds CI among the practices that go with teams delivering faster and more reliably. Their caution: running a CI tool isn't the same as doing CI. Long-lived branches with a build server attached are still integration hell, just with a dashboard.
Pila’s pipeline on four pushes
Pila's pipeline has three steps, cheapest first. Play it, push by push:
- Lint (ruff) passed
- Test (pytest)
- Build image
- ▶ running
Add tests for the priority laneMarco
The order is deliberate: linting takes seconds, tests take a minute, building the image takes several. Failing fast saves everyone's time.
Read the red build
Pipelines as code
The pipeline isn't set up by clicking in a settings page. It's a file in the repository, so it's versioned, reviewed and changed like any code. With GitHub Actions, Pila's is .github/workflows/ci.yml:
name: CI
on: [push, pull_request]
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.14"
- run: python -m pip install -r requirements.lock
- run: ruff check .
- run: python -m pytest -qRead it top to bottom: on every push and pull request, take a fresh Linux computer, check out the code, install Python and the locked dependencies, lint, and test. You'll write this file yourself in capstone lesson C.7. Simple Git's Hooks and checks shows how the hosting site uses the result to block merging a red pull request.
Spot the trap: switch off the failing test
It’s 4:50 p.m. A test on main has been red since lunch. Jun can’t see why, and wants to go home. “I’ll mark it skip for now,” he says, “so the build goes green.”
What happens if…
Check what you learned
Sources
Every claim on this page comes from these sources: the standard, the founding text of a method, a study, or the official record of a project, from the body that publishes it. Industry reports are labelled as such.
- Martin Fowler: Continuous Integration: the practice, and its rules, in detail
- DORA: Continuous integration: what the research links CI to, and common pitfalls
- Paul Hammant: Trunk Based Development: short-lived branches merged into one main branch
- GitHub Docs: Understanding GitHub Actions: workflows, jobs and steps, written as a file in the repository