Skip to content
KALANBLON
Show contents

Chapter 1 of 7 · 20 min

Continuous integration

By the end of this chapter, you'll be able to

  • Explain what DevOps and continuous integration bring
  • Describe the steps of a continuous integration pipeline
  • Read a simple GitHub Actions workflow
  • Shorten a pipeline by running independent tasks in parallel

Integrate often

Continuous integration (CI) means merging everyone's work into the main branch several times a day, and checking each change automatically: does the code build? Do the tests pass? Is the style respected? An integration server runs these checks on every push or merge request, and reports the slightest failure within minutes.

Why often? Because merging two weeks of work in one go produces huge conflicts and bugs that are hard to pin down, while merging one small change at a time keeps each problem small and obvious. Continuous delivery (CD) extends the idea: every version that passes the pipeline is ready to go to production in one click.

The pipeline

A pipeline is a sequence of automatic steps. The fastest ones go first so as to fail fast: no point running ten minutes of tests if the code does not even respect the syntax.

steps = [
    ("install", 40, True),
    ("lint", 15, True),
    ("unit tests", 90, False),
    ("build", 120, True),
    ("end-to-end tests", 300, True),
]

elapsed = 0
for name, duration, success in steps:
    elapsed += duration
    print(f"{elapsed:>4} s  {name:<18} {'ok' if success else 'FAILED'}")
    if not success:
        print(f"Pipeline stopped: {sum(d for _, d, _ in steps) - elapsed} s of computing saved")
        break
  40 s  install            ok
  55 s  lint               ok
 145 s  unit tests         FAILED
Pipeline stopped: 420 s of computing saved

The person who pushed the change hears back in two and a half minutes, while the context is still fresh in their mind. And the main branch always stays in a working state: that is the golden rule of continuous integration.

Merging is only allowed if the pipeline is green: main always works.

Step 5 of 5
Text description of the animation
  1. The developer pushes the branch: the integration server immediately starts a pipeline.
  2. The fastest checks pass first.
  3. A test fails: the pipeline stops and notifies the author.
  4. The author fixes it and pushes again; this time everything passes, including the build.
  5. Merging is only allowed if the pipeline is green: main always works.

A GitHub Actions workflow

With GitHub Actions, the pipeline is described in a YAML file in the repository, for example .github/workflows/ci.yml:

name: CI
on:
  push:
    branches: [main]
  pull_request:

jobs:
  tests:
    runs-on: ubuntu-24.04
    steps:
      - uses: actions/checkout@v5
      - uses: actions/setup-python@v6
        with:
          python-version: "3.13"
      - run: pip install -r requirements.txt
      - run: ruff check .
      - run: pytest
  • on: the events that trigger the pipeline (a push to main, a merge request);
  • jobs: the tasks, here a single one, running on a fresh Ubuntu machine;
  • steps: the steps, in order. uses reuses a ready-made action (fetching the code, installing Python), run runs a command. If a command fails, the job stops.

Other tools do the same with their own syntax: GitLab CI, Jenkins, Woodpecker… The ideas stay the same.

Mini-lab: order your pipelinePython 3.13

Output

Click “Run”: Python will load in your browser (about 10 MB the first time).

Your code runs in your browser, isolated from the page. · Ctrl/⌘ + Enter to run · Esc then Tab to leave the editor

Your turn

Worked exercise

Worked exercise: parallelising the pipeline

A pipeline's steps have dependencies: you can only build after installing, and the end-to-end tests need the build. On the other hand, lint, unit tests and build only depend on the install: they can run in parallel, on different machines. Compute the pipeline's total duration in sequence, then in parallel (each step starts as soon as all its dependencies are finished).

steps = {
    "install": (40, []),
    "lint": (15, ["install"]),
    "unit tests": (90, ["install"]),
    "build": (120, ["install"]),
    "end-to-end tests": (300, ["build"]),
}
Hint 1
In parallel, a step's end time is its duration plus the latest end time of its dependencies (0 if there are none).
Hint 2
The dictionary is already in an order where each step follows its dependencies: a single loop is enough.
Show the solution and common mistakes
steps = {
    "install": (40, []),
    "lint": (15, ["install"]),
    "unit tests": (90, ["install"]),
    "build": (120, ["install"]),
    "end-to-end tests": (300, ["build"]),
}

end = {}
for name, (duration, dependencies) in steps.items():
    end[name] = duration + max((end[d] for d in dependencies), default=0)

print("in sequence:", sum(d for d, _ in steps.values()), "s")
print("in parallel:", max(end.values()), "s")
print("longest path ends with:", max(end, key=end.get))
in sequence: 565 s
in parallel: 460 s
longest path ends with: end-to-end tests

The parallel pipeline takes 460 s: the length of the critical path install → build → end-to-end tests. To save more time, you would have to shorten that path (for example by spreading the end-to-end tests over several machines); speeding up linting would change nothing.

Common mistakes:

  • Taking the sum of the dependencies instead of the maximum: parallel steps do not add up.
  • Forgetting default=0: max of an empty list raises an error for the install step, which has no dependency.

Summary

  1. 1DevOps brings development and operations together to ship often and without fear, thanks to automation.
  2. 2Continuous integration checks every change automatically and keeps the main branch always working.
  3. 3A pipeline puts the fast steps first to fail fast.
  4. 4A GitHub Actions workflow describes triggers, jobs and their steps in YAML.
  5. 5Running independent steps in parallel cuts the duration to the critical path; a flaky test gets fixed, not ignored.

Your progress is saved on this device. Create a free account to keep your progress on all your devices.