Tests and CI · Chapter 2 of 3 · 3 min

The Tests Workflow on GitHub Actions

A complete continuous-integration setup in one short YAML file: what each line does, why the install is strict, and how to read the results.

What CI is for

Continuous integration means: every change is tested automatically, on a clean machine, before it joins the main line. "Clean machine" is the key part. Your laptop has files, settings and installed tools that the server does not. CI proves the change works without them.

The whole workflow

This is the complete file this site uses, .github/workflows/test.yml:

name: tests
on:
  pull_request:
  push:
    branches: [main]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 22
          cache: npm
      - run: npm ci --omit=dev --ignore-scripts
      - run: npm test
      - run: npm run validate:mentorship

That is all it takes. Line by line:

When it runs

on: pull_request runs it for every pull request, so the green tick or red cross appears before merging. push: branches: [main] runs it again after the merge, against the exact code that is now on main. The second run catches the rare case where two pull requests each pass alone but break together.

Where it runs

runs-on: ubuntu-latest gives a fresh Linux virtual machine for every run. Nothing carries over from the last run except what the cache keeps on purpose.

Getting the code and Node

actions/checkout fetches the commit being tested. actions/setup-node installs Node 22, the same major version the server runs. Testing on a different version than production is a quiet source of "but it passed in CI".

cache: npm keeps downloaded packages between runs, keyed on the lock file, so installs are fast without being stale.

The strict install

npm ci --omit=dev --ignore-scripts

The checks

npm test runs the whole suite. npm run validate:mentorship runs an extra content validator. Any step that exits with an error fails the job, and a failed job is a red cross.

Reading the results

On this site a passing run takes 40 to 50 seconds. Over 196 runs, the workflow failed twice. Both failures were on main and both were fixed within minutes. That record is worth watching: a rising failure rate on main means changes are being merged without waiting for the PR check.

To see only failures, filter the Actions page with is:failure. To read one, open the run and expand the failing step: the test name and the assertion message are at the bottom of the log.

Why also test in Cloud Build?

The deploy pipeline (next series) runs the tests a third time before building the image. It looks redundant, but it is the gate closest to production: if something reaches main without a green check, the build still refuses to ship it.

Try it yourself

Copy the workflow above into .github/workflows/test.yml in a project of yours, set the Node version to the one you deploy, and open a pull request. Then break a test on purpose and watch the red cross appear before you can merge with confidence.