Continuous integration
Overview
Continuous integration (CI) means integrating everyone’s work frequently — and verifying every change automatically. On GitHub, that means a workflow that runs your linters and tests on each pull request. The result appears on the PR as a status check: green means it’s safe to merge, red means something broke — and with branch rules, red blocks the merge.
A complete CI workflow
# .github/workflows/ci.yml
name: CI
on:
pull_request:
push:
branches: [main]
permissions:
contents: read
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: 24
cache: npm
- run: npm ci
- run: npm run lint
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node: [22, 24, 26]
name: test (${{ matrix.node }})
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: ${{ matrix.node }}
cache: npm
- run: npm ci
- run: npm testThe same structure works for any language — swap setup-node for actions/setup-python, actions/setup-java, actions/setup-go and so on, and run that ecosystem’s commands.
What each part does
Triggers
Running on pull_request tests the PR merged with its target branch, so you see whether the combination works. Running on push to main re-checks main after every merge — and gives you a badge for the README.
Reproducible installs
npm ci installs exactly what’s in package-lock.json and fails if the lockfile is out of date. That’s why lockfiles are committed (Ignoring files): CI and every developer get identical dependencies.
Caching
cache: npm in setup-node caches npm’s download cache between runs, keyed on the lockfile. Installs go from a minute to seconds. Other setup actions have the same option; actions/cache caches anything else.
The matrix
strategy:
fail-fast: false
matrix:
node: [22, 24, 26]
os: [ubuntu-latest, windows-latest] # add a dimension → 6 jobsA matrix creates one job per combination. Test on the versions you support — for Node.js in December 2026 that’s typically the maintained LTS lines 22 and 24 plus 26. By default, the first failure cancels the other matrix jobs; fail-fast: false lets them finish, so you can see whether a failure is version-specific.
Concurrency
When you push three commits in a row to a PR, you only care about the last. concurrency with cancel-in-progress cancels older runs of the same group (here, the same branch).
Requiring CI to pass
A CI workflow only helps if failures stop merges. In your branch ruleset, enable Require status checks to pass and select the jobs — for example lint and each test (22), test (24), test (26) (Protecting branches). Status checks must have run at least once to appear in the list.
When CI fails
- Open the failing check from the PR (or
gh pr checks, thengh run view --log-failed). - Read the first error, not the last — later errors are often consequences.
- Reproduce locally: run the same command (
npm ci && npm test) on the same version. - Fix and push to the same branch — CI runs again automatically.
Common “works on my machine” causes: a file you forgot to commit, a dependency installed globally on your machine but missing from package.json, an uncommitted lockfile change, or code depending on your time zone or operating system.
Flaky tests
A test that sometimes passes and sometimes fails — usually because of timing, randomness or shared state — erodes trust in CI. Fix or quarantine it quickly; “just re-run it” turns into ignoring red builds.
Beyond tests
Once CI is in place, it’s easy to add more checks:
- Type checking and builds (
npm run build), to catch broken production builds. - Formatting checks (
prettier --check) so style never comes up in review. - Security: Dependabot alerts and update PRs, dependency review on PRs, and CodeQL code scanning.
- Previews: deploy each PR to a temporary URL for reviewers to try.
Status badge
Show the build status in your README:
The CI contract: nothing merges to
mainunless the robots agree it works. It’s the single most valuable automation most teams have.
CI for a Node.js project
Write .github/workflows/ci.yml for a Node.js project. It runs on pull requests and on pushes to main. A lint job runs npm run lint on Node 24. A test job runs npm test on Node 22, 24 and 26 using a matrix, and keeps testing the other versions if one fails. Both jobs use npm ci with npm caching. Outdated runs for the same branch are cancelled when new commits are pushed, and the token is read-only. Then require the test checks in your branch ruleset.
# .github/workflows/ci.yml
name: CI
on:
# pull requests + pushes to main
# read-only token
# cancel outdated runs for the same branch
jobs:
lint:
# Node 24, npm ci (with cache), npm run lint
test:
# matrix: Node 22, 24, 26 — don't stop the others when one fails# .github/workflows/ci.yml
name: CI
on:
pull_request:
push:
branches: [main]
permissions:
contents: read
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: 24
cache: npm
- run: npm ci
- run: npm run lint
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node: [22, 24, 26]
name: test (${{ matrix.node }})
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: ${{ matrix.node }}
cache: npm
- run: npm ci
- run: npm testSummary
- Continuous integration runs your checks automatically on every push and pull request, so problems are found before merging.
- A typical CI workflow installs dependencies with a lockfile (
npm ci), then lints, tests and builds. - A matrix runs the same job across versions or operating systems;
fail-fast: falseshows every result. - Cache dependencies and cancel outdated runs with
concurrencyto keep CI fast and cheap. - Make the CI jobs required status checks so a red build blocks the merge.