What a CI pipeline does with your push
You push, and a minute later a tick or a cross appears next to your commit. Here is what ran in between, step by step, and why it ran on a machine that has never seen your code.
01 What happens after git push
You push a commit and, a minute later, a green tick or a red cross appears next to it. In between, a CI (continuous integration) service took your commit, built it on a machine of its own, ran your tests, and reported back.
The recipe lives in your repository. On GitHub it is a YAML file in .github/workflows/, called a workflow. It says when to run (on: push), where (runs-on), and the steps, each one a command or a ready-made action.
02 Checkout, install, test, build
Here is one push going through that file. Watch the disk on the right: it starts with nothing of yours, and everything on it comes from the commit or from a step in the file.
- running now
- passed
- waiting
- just arrived
You run git push. GitHub sees a workflow that listens for push, queues its job, and starts a fresh virtual machine from the Ubuntu image. Nothing of yours is on it.
03 Why a clean machine
Your laptop has years of leftovers: tools installed globally, environment variables, files you never committed, a Node version you picked once. Tests can pass there because of those leftovers. The runner has none of them, so a pass there means the repository alone is enough.
.env file or an uncommitted change that nobody else has.| Thing | Your laptop | The runner |
|---|---|---|
| Files | everything in the folder | only what was committed and pushed |
| Node version | whatever you installed | what `setup-node` names |
| Packages | `node_modules` from months ago | fresh from `package-lock.json` |
| File names | macOS ignores case by default | Linux does not: `Cart.js` is not `cart.js` |
| Secrets and env vars | your shell and `.env` | only the secrets you add to the workflow |
| Time zone | yours | UTC |
04 When a step fails
Each step is a command, and CI judges it the way your shell does: exit code 0 is success, anything else is failure. Test runners exit non-zero when a test fails, which is how CI knows.
| Step | Result |
|---|---|
| checkout | passed |
| setup | passed |
| install | passed |
| test | failed, exit code 1 |
| build | skipped |
| commit a1b2c3d | red cross |
By default, the steps after a failure are skipped and the job fails. A pull request with a red cross is easy to spot, and the repository can be set to block merging until it is green.
05 Green on your laptop, red in CI
CI tests the commit you pushed, not your working folder. A new file you forgot to git add exists on your laptop and nowhere else, so the runner fails with Cannot find module.
import './Cart.js'Wrong case in a file nameThe file is cart.js. macOS finds it anyway; the Linux runner does not. Match the case exactly.npm installInstalling without the lockfilenpm install may pick newer versions than you tested with. Commit package-lock.json and use npm ci, which refuses to run without it.process.env.API_KEYA value only your shell hasIt is set in your .env or shell profile, which are not in the repository. Add it as a repository secret and pass it to the step.new Date().getHours()Tests that depend on the clockRunners use UTC, so a test written in your time zone can fail by hours. Fix the time in the test instead of reading the real clock.runs-on: self-hostedSelf-hosted runners are not cleanYour own runner machine keeps files between jobs unless you clean it. The clean-machine guarantee is for GitHub-hosted runners.