Skip to content

Module 07 · Lesson 7.4

Continuous Integration Pipelines

40 minUpdated 19 Nov 2026Part of Testing, CI/CD and Release · New Project Creation
On this page
  1. What you will learn
  2. What continuous integration is, and why it matters
  3. The workflow file for a TypeScript project
  4. Make checks required with branch protection
  5. Secrets in a pipeline
  6. Step-by-step workflow
  7. Working with an assistant on pipelines
  8. Conclusion and your next step
  9. Reusable prompt
  10. Expected output
  11. Common errors and fixes
  12. Validation checklist
  13. Hands-on exercise
  14. Knowledge check
  15. Frequently asked questions
  16. References

At an airport, every bag goes through the same scanner. The scanner does not get tired, forget a step or skip a bag because the queue is long. A continuous integration pipeline is that scanner for your code. Every change goes through the same checks, on a clean machine, every time.

In this lesson you build the pipeline for the Tidewell project. It runs the same commands you run by hand: install, lint, format check, type check and tests. You then make those checks required, so a failing change cannot be merged. Finally you decide where secrets live, because the pipeline must never be the place a key leaks.

What you will learn

  • Explain what continuous integration is, and which checks belong in it.
  • Write a GitHub Actions workflow that runs install, lint, format, type and test checks on every pull request and every push to main.
  • Make the checks required, so that a failing check blocks the merge.
  • Keep secrets in protected settings and keep the pipeline fast and trustworthy.

Before you start

What continuous integration is, and why it matters

Continuous integration, or CI, means that every change to the code is checked automatically, soon after it is made. The checks run on a fresh computer in the cloud, not on yours. If something only works on your laptop, because of a file you forgot to commit or a package you installed by hand, CI finds out on the first run.

Pipeline
A fixed list of automatic steps that every change goes through, like an assembly line with an inspector at each stop.
Workflow
GitHub's name for a pipeline. It is a file in your repository that says when to run and which steps to take.
Check
One named pass-or-fail result from a pipeline, such as 'tests' or 'type check'.
Pull request
A request to merge a change into the main branch. It is where people review the change and where the checks report.
Branch protection
A rule on the main branch, such as 'checks must pass before merging'. Without it, a pipeline is only advice.

This lesson uses GitHub Actions as the worked example, because many teams host code on GitHub. It is one tool among several. GitLab CI/CD, Azure Pipelines and others work on the same ideas: a file in the repository, a trigger, and a list of steps. The names and settings differ, so check your tool's documentation. The same ideas carry over.

You may also see CI/CD. The CD part means continuous delivery or deployment: sending checked changes towards users. The next lesson covers releasing. Here you build the first half, the checks.

The workflow file for a TypeScript project

Start with the scripts the pipeline will call

A good pipeline runs the same commands that a developer runs. You already have lint, format:check and typecheck from Module 3. The test script is new. Keep these names in package.json, and the pipeline file becomes short and easy to read.

JSONpackage.json
{
  "name": "tidewell-booking",
  "private": true,
  "type": "module",
  "scripts": {
    "lint": "eslint .",
    "format:check": "prettier --check .",
    "typecheck": "tsc --noEmit",
    "migrate": "tsx scripts/migrate.ts",
    "smoke": "tsx smoke-cli.ts",
    "docs:check": "tsx scripts/docs-check.ts",
    "test": "tsx --test --test-reporter=spec \"**/*.test.ts\""
  }
}

The kit is one flat folder, so its test pattern is **/*.test.ts. That pattern also finds tests in src/ in a real project.

  • lint runs ESLint, which finds likely mistakes. format:check runs Prettier in check mode, which fails if a file is not formatted, and does not change anything.
  • typecheck runs the TypeScript compiler without producing files, to find type errors.
  • test runs every .test.ts file with Node's test runner through tsx. The spec reporter prints a readable list, because with no terminal, as in a pipeline, Node may print a harder-to-read format by default.
  • migrate applies database migrations, and smoke runs the smoke test from the next lesson. The pipeline does not use them. A release does.
  • docs:check runs the documentation check from Module 8. You can add it as one more step after the tests, once it exists.

The workflow

The file lives at .github/workflows/ci.yml. YAML is a plain-text format that uses indentation to show structure, so spaces matter. Read it from the top.

YAML.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:
  checks:
    runs-on: ubuntu-latest
    timeout-minutes: 10
    steps:
      - name: Get the code
        uses: actions/checkout@v7
      - name: Set up Node.js
        uses: actions/setup-node@v7
        with:
          node-version: 22
          cache: npm
      - name: Install dependencies
        run: npm ci
      - name: Lint
        run: npm run lint
      - name: Check formatting
        run: npm run format:check
      - name: Check types
        run: npm run typecheck
      - name: Run tests
        run: npm test

What each part does

  • on says when to run: on every pull request, and on every push to main. Together they cover the change under review and the merged result.
  • permissions: contents: read gives the job the least power it needs. The checks only read the code, so they may not write to it.
  • concurrency cancels an older run of the same branch when a newer commit arrives, so you do not wait for stale results.
  • jobs: checks is one job on a fresh Linux machine. timeout-minutes stops a stuck run from burning time.
  • actions/checkout copies the code onto the machine. actions/setup-node installs Node and, with cache: npm, reuses downloaded packages to save time. Both are ready-made steps published by GitHub. Their version numbers change, so check each action's page for the current one.
  • npm ci installs exactly what package-lock.json lists, and fails if the lock file and package.json disagree. Plain npm install may quietly change versions, so it is not the right command for a pipeline.
  • The last four steps are the checks, in order from cheapest to slowest. If one fails, the steps after it are skipped, and the run is marked as failed.
  • The integration tests use PGlite, so the pipeline needs no database service. A real PostgreSQL server in CI is another option for later, if you want to test against the exact production version.

Check the workflow file itself

A mistake in the workflow shows up only after you push. You can catch most of them first. This script parses the YAML with the yaml package and checks the rules we promised: the triggers, the commands and their order, read-only permissions, a time limit and no secrets in the test workflow. First it reads the files.

TypeScriptcheck-workflow.ts (reading the files)
// Parses the workflow files and checks the rules we promised ourselves.
import { readFile } from "node:fs/promises";
import { join } from "node:path";
import { parse } from "yaml";

interface Step {
  name?: string;
  uses?: string;
  run?: string;
}
interface Workflow {
  name: string;
  on: Record<string, { branches?: string[] } | null>;
  permissions?: Record<string, string>;
  jobs: Record<string, { "timeout-minutes"?: number; steps: Step[] }>;
}

const REQUIRED_COMMANDS = ["npm ci", "npm run lint", "npm run format:check", "npm run typecheck", "npm test"];
const results: { ok: boolean; message: string }[] = [];
const check = (ok: boolean, message: string) => results.push({ ok, message });

const read = (path: string) => readFile(join(import.meta.dirname, path), "utf8");
const ciText = await read(".github/workflows/ci.yml");
const deployText = await read(".github/workflows/deploy.yml");
const ci = parse(ciText) as Workflow;
const scripts = (JSON.parse(await read("package.json")) as { scripts: Record<string, string> }).scripts;

const job = Object.values(ci.jobs)[0];
const commands = job.steps.flatMap((step) => (step.run ? [step.run] : []));
TypeScriptcheck-workflow.ts (the rules)
check("pull_request" in ci.on, "runs on every pull request");
check(ci.on.push?.branches?.includes("main") === true, "runs on every push to main");
check(JSON.stringify(commands) === JSON.stringify(REQUIRED_COMMANDS), `runs ${REQUIRED_COMMANDS.join(", ")} in that order`);
const missingScripts = commands
  .filter((command) => command.startsWith("npm run "))
  .map((command) => command.slice("npm run ".length))
  .filter((name) => !(name in scripts));
check(missingScripts.length === 0, "every `npm run` command exists in package.json");
check(ci.permissions?.contents === "read", "token is read-only");
check(typeof job["timeout-minutes"] === "number", "has a time limit");
check(!ciText.includes("secrets."), "the test workflow uses no secrets");

const secretNames = [...deployText.matchAll(/\$\{\{\s*secrets\.([A-Z_]+)\s*\}\}/g)].map((m) => m[1]);
check(secretNames.length > 0 && !/(DATABASE_URL|API_KEY|AUTH_SECRET):\s*[^\s$]/.test(deployText), "deploy reads secrets only from protected settings");

for (const { ok, message } of results) console.log(`${ok ? "ok  " : "FAIL"} ${message}`);
console.log(`secret names the deploy workflow expects: ${secretNames.join(", ")}`);
process.exitCode = results.every((r) => r.ok) ? 0 : 1;
Running npx tsx check-workflow.tsCaptured from a real run
ok   runs on every pull request
ok   runs on every push to main
ok   runs npm ci, npm run lint, npm run format:check, npm run typecheck, npm test in that order
ok   every `npm run` command exists in package.json
ok   token is read-only
ok   has a time limit
ok   the test workflow uses no secrets
ok   deploy reads secrets only from protected settings
secret names the deploy workflow expects: DATABASE_URL

The YAML parsed, and every rule held. If someone removes the type-check step, or adds a secret to the test workflow, this check fails and says which rule broke. Dedicated tools exist for checking workflows, so treat this script as a teaching example. What matters is that your pipeline rules are written down and checked.

What a run looks like

When someone opens a pull request, GitHub runs the workflow and shows the result on the page. This is an illustration of a run where a type error was introduced. The real screen looks different and its wording changes over time.

A failing run (illustrative)Illustrative — your output will differ
CI / checks (pull_request)    failed after 1m 10s
  Get the code            passed
  Set up Node.js          passed
  Install dependencies    passed
  Lint                    passed
  Check formatting        passed
  Check types             failed
    src/features/bookings/service.ts(42,7): error TS2322:
    Type 'string' is not assignable to type 'number'.
  Run tests               skipped

Merging is blocked: 1 required check has not passed.

Make checks required with branch protection

A pipeline that can be ignored will be ignored. Under a deadline, 'just merge it, the type check is flaky' is very tempting. Branch protection takes the choice away. You set rules on the main branch, and GitHub enforces them for everyone.

  • Require a pull request before merging. Nobody pushes straight to main.
  • Require the checks job to pass. The name you pick is the name of the job in the workflow file.
  • Require the branch to contain the latest main before it merges, so the checks ran on the result that will land.
  • Apply the rules to administrators too, if the tool allows it. A rule that the owner can skip is a habit, not a rule.
  • Require a review from a second person, or from the owner of the code, for sensitive areas. Module 8 covers review rules.

The menu names change from time to time, and settings can be called branch protection rules or rulesets. Follow the current page, About protected branches (opens in a new tab), when you set it up.

Keep the pipeline fast and trustworthy

  • Cheap checks first. Lint and types answer in seconds. Put them before the slower tests.
  • Cache downloads. cache: npm saved the packages from the last run.
  • Set time limits. A hung test should not hold the team for an hour.
  • Never 'just re-run it until it is green'. A test that sometimes fails is a flaky test. It teaches everyone to ignore red. Fix it, or remove it with a written reason and a ticket to bring it back.
  • Never hide failures. Do not add continue-on-error: true, or || true at the end of a command, to make a pipeline green. That removes the very protection you built.
  • Keep the pipeline under about ten minutes for a project this size. If it gets slow, find out why before you start skipping checks.

Secrets in a pipeline

The test workflow above uses no secrets. The tests use PGlite and fake services, so they never need a database password or an email key. That is deliberate. A workflow that runs on every pull request, including code from many people, is the worst place to hold a real key.

A deploy workflow does need a few secrets, such as the production database address. Those live in the CI system's protected settings, not in the repository. In GitHub they are called secrets, and you can attach them to an environment such as production. An environment can also require a named person to approve before the job runs. In the workflow, a secret is read by name and is never written out.

YAML.github/workflows/deploy.yml
name: Deploy

on:
  workflow_dispatch:

jobs:
  deploy:
    runs-on: ubuntu-latest
    environment: production
    steps:
      - name: Get the code
        uses: actions/checkout@v7
      - name: Apply database migrations
        run: npm run migrate
        env:
          DATABASE_URL: ${{ secrets.DATABASE_URL }}

A sketch of a deploy workflow. How you deploy depends on your host, so only the handling of the secret is the point here.

  • workflow_dispatch means a person starts it by hand. A release is a decision, not a side effect of every merge.
  • environment: production ties the job to the production environment and its protections, such as a required approver.
  • ${{ secrets.DATABASE_URL }} reads the secret by name. The value is never in the file, and GitHub hides it in the logs. Still, never print it yourself, and never put a secret in a command line where it could end up in a log.
  • The check-workflow.ts script confirms that the deploy file mentions secrets only through this form.

Step-by-step workflow

  1. Step 1: Make the commands work on your own computer

    Run npm ci, npm run lint, npm run format:check, npm run typecheck and npm test. Fix them until all five pass.

    What you should see: Five commands that pass locally, from a clean install.

  2. Step 2: Write the workflow file

    Create .github/workflows/ci.yml with the triggers, read-only permissions, a time limit and the five steps. Ask an assistant for a draft, then read every line.

    What you should see: A workflow file that you can explain line by line.

  3. Step 3: Check the file before you push

    Parse the YAML and check your rules with a script like the one above.

    What you should see: All rules print ok.

  4. Step 4: Open a pull request and watch the run

    Push a branch, open a pull request and read the checks page. Fix any step that fails for a reason that is not in your code, such as a missing script.

    What you should see: A green run on a clean change.

  5. Step 5: Require the checks

    Add branch protection for main: pull request first, the checks job required, and the latest main included.

    What you should see: The merge button is disabled while a check fails.

  6. Step 6: Prove it blocks

    Open a throwaway pull request with a deliberate type error, confirm that the merge is blocked, and then close it.

    What you should see: You have seen a failing check stop a merge.

From a change to a merge
  1. Branch and commit

    A change on your computer

  2. Pull request

    Opens the review

  3. Pipeline

    Lint, format, types, tests

  4. Required checks

    Red blocks the merge

  5. Merge to main

    Runs the pipeline again

Every change travels the same route, and a failure at any check stops it.

Working with an assistant on pipelines

TaskAssistant's partYour part
Draft the workflowWrites the YAML and explains each line.Read every line. Check each action name against the publisher's page, and each command against package.json.
Choose permissionsProposes them.Reduce to read-only unless a job really needs to write.
Handle secretsSuggests where to store them.Keep them out of test jobs and out of the repository. Check nothing prints them.
Fix a failing runReads the log and suggests a cause.Fix the cause. Refuse suggestions that hide the failure, such as continue-on-error.
Set required checksLists the settings.Apply them yourself, then prove they block a bad change.

Conclusion and your next step

A continuous integration pipeline runs the same checks on every change, on a clean machine. Install, lint, format, types and tests run in order from cheapest to slowest. Branch protection makes the checks required, and the test workflow needs no secrets at all. A failing run is information, and the right response is to fix the cause and not to loosen the pipeline.

Your next step: add a CI workflow to your capstone, require its checks on your main branch, and prove it by opening a pull request that should fail. Then continue to Releasing and Rolling Back, where you plan a release, add a smoke test and prepare a way back.

For more on safe habits, read AI Code Review: Catching Bugs Before They Ship or the AI-Generated Code Review Checklist.

Reusable prompt

CI workflow drafter

Asks the assistant to draft a pipeline file with least-privilege settings, the exact commands to run and an explanation of each line, and to list its assumptions.

You are helping me write a continuous integration workflow. Do not add features I did not ask for.

Project: Tidewell booking system (fictional clinic). TypeScript, Next.js, PostgreSQL. Tests use PGlite (a real PostgreSQL engine inside Node), so no database service is needed. Hosting for the code: GitHub, so use GitHub Actions.
package.json scripts that exist: lint, format:check, typecheck, test, migrate.

Requirements:
1. Run on every pull request and on every push to main.
2. One job on ubuntu-latest, with a timeout. Steps in this order: check out, set up Node with npm caching, npm ci, npm run lint, npm run format:check, npm run typecheck, npm test.
3. Permissions: contents read only.
4. No secrets in this workflow. Tests need none.
5. Do not use continue-on-error, "|| true" or anything else that hides a failure.
6. Cancel an older run of the same branch when a newer one starts.

Tasks:
1. Write the workflow file.
2. Explain each key in one line, in plain words.
3. Say which parts are specific to GitHub Actions, and what the same idea is called in another tool.
4. List every action you used, with its publisher, and tell me to check the current version on its page. Do not invent version numbers.
5. List your assumptions.
Show the reusable template

Replace each {{placeholder}} with your own details.

You are helping me write a continuous integration workflow. Do not add features I did not ask for.

Project: {{project_and_stack}}. Code hosting: {{hosting}}.
package.json scripts that exist: {{scripts}}

Requirements:
1. Run on every pull request and on every push to {{main_branch}}.
2. One job on {{runner}}, with a timeout. Steps in this order: {{steps_in_order}}.
3. Permissions: contents read only.
4. No secrets in this workflow. Tests need none.
5. Do not use continue-on-error, "|| true" or anything else that hides a failure.
6. Cancel an older run of the same branch when a newer one starts.

Tasks:
1. Write the workflow file.
2. Explain each key in one line, in plain words.
3. Say which parts are specific to {{ci_tool}}, and what the same idea is called in another tool.
4. List every action you used, with its publisher, and tell me to check the current version on its page. Do not invent version numbers.
5. List your assumptions.

Expected output and limitations

A workflow file that matches your requirements, a line-by-line explanation, a note on what is tool-specific, a list of the actions used with their publishers, and a list of assumptions.

Sample responseIllustrative — your output will differ
name: CI
on:
  pull_request:
  push:
    branches: [main]
permissions:
  contents: read
...

Notes
- "on" says when to run. In GitLab CI the same idea is "rules" or "workflow".
- Actions used: actions/checkout and actions/setup-node, both published by GitHub. Check their pages for the current major version.
Assumptions
- The default branch is called main.
- package-lock.json is committed (npm ci needs it).

Limitations to keep in mind

  • The assistant may name actions or versions that do not exist, or use old syntax. Check every action on its publisher's page.
  • It may widen permissions or add a secret 'just in case'. Remove anything you did not ask for.
  • It cannot know your repository settings. You must turn on branch protection yourself and prove that it blocks a bad change.

Common errors and how to fix them

The pipeline passes, but a failing change still reached the main branch.

Why it happens: The checks are not required. The pipeline gives advice and the merge button still works.

Fix: Turn on branch protection, require the job by name, and test it with a deliberate failure.

The pipeline fails on the first step with a message about the lock file.

Why it happens: package-lock.json is missing or does not match package.json, so npm ci refuses to run.

Fix: Run npm install on your computer, commit the updated lock file, and push again.

A test fails in the pipeline but passes on your computer.

Why it happens: The test depends on your machine: the time, the time zone, a file left behind or the order of tests.

Fix: Fix the clock and the data, as in the earlier lessons. Do not re-run the pipeline until it goes green.

Validation checklist

Tick each item once you have confirmed it.

Hands-on exercise

A pipeline plan for Ferngate

Ferngate's parts app has the scripts lint, typecheck and test, and no format script yet. Write the list of steps for its pipeline, decide which checks are required, and say where the deploy token for the workshop's hosting should live.

You will need

  • Scripts that exist: lint, typecheck, test. Tests use an in-memory database and no outside service.
  • The code is on GitHub. The owner will deploy by hand, from a button, at the end of the week.
  • The hosting service gives a deploy token that must not be public.

Acceptance criteria

Your work is done when every one of these is true.

Hints (2)
  • Where would you put the formatting check? Is it a script you must write first, or a step you can leave out for now, and why?
  • The owner presses the deploy button. Which GitHub feature lets one named person approve a deploy?
Show a model answer

A strong answer lists: check out, set up Node with caching, npm ci, lint, type check and tests, with permissions read-only and a time limit. It adds a format script to the project first, and then a step for it, instead of leaving the format check out silently. It requires the single job to pass before merging into main, and proves the block with a throwaway pull request that has a deliberate type error. The deploy token goes into a protected secret attached to a production environment, used only by a separate deploy workflow that the owner starts by hand. It may also require the owner's approval on the environment. The test workflow never sees the token.

Knowledge check

Choose an answer, then check it. Nothing is recorded — this is for you.

  1. 1.What should a pipeline do when the type check fails?
    Show the answer and explanation

    Answer: B. Checks that do not block become noise that people learn to ignore. A warning feels gentler, but it lets a known error reach the main branch. Skipping on busy days is the moment the check matters most.

  2. 2.Where should a deploy key for production be stored?
    Show the answer and explanation

    Answer: C. Protected secrets are kept out of the repository and out of ordinary logs, and they can be limited to one environment. The other two put the key where every contributor, and any later leak of the repository, can see it.

  3. 3.Why does a pipeline run npm ci and not npm install?
    Show the answer and explanation

    Answer: A. A pipeline should build the same thing every time. npm install may update versions quietly, which makes runs differ. Both commands work on Linux, so the platform is not the reason, and neither command has anything to do with the type check.

Frequently asked questions

What is CI/CD?

CI stands for continuous integration: checking every change automatically. CD stands for continuous delivery or deployment: sending checked changes towards users in a controlled way. Together they are called a pipeline.

What is a GitHub Actions workflow?

It is a text file in your repository, in the folder .github/workflows. It says when to run, such as on a pull request, and lists the steps to take. GitHub runs it on a fresh machine and shows the result on the pull request.

Do I need CI for a small project that only I work on?

It is still worth it. The pipeline checks your work on a clean machine, finds missing files, and gives future helpers or contractors a safety net. It takes about an hour to set up and saves much more than that.

How do I stop a broken change from being merged?

Turn on branch protection for your main branch and require the pipeline job to pass. Then a failing check disables the merge button for everyone. Test it once with a deliberate failure so you know it works.

Written by
PromptFable Editorial
Last updated 19 Nov 2026
Review
Reviewed by Waseem Nadir, Technical Reviewer
Last reviewed 27 Nov 2026

References

Primary sources for the technical details in this lesson. Vendor platforms change — check the official page if anything here looks different from what you see.

PromptFable is independent and is not affiliated with, endorsed by or sponsored by Anthropic, Google, OpenAI or any other vendor. Claude, Gemini, Google AI Studio and other product names are trademarks of their respective owners.