Skip to main content

Build a Pipeline

Why This Matters

Everything so far happened in your terminal, with you watching. A pipeline makes the good parts repeatable: the same steps, the same gates, every time, for every change, whether a person or an agent wrote it.

From loose steps to a flow

Write the steps you have been doing by hand as one chain:

brief → plan → tests (red) → code (green) → review → gates → pull request → human approval

Two kinds of steps live in that chain:

  • Deterministic steps that a script decides: lint, typecheck, tests, mutation score, policy checks.
  • Agent steps that need judgement: planning, implementing, reviewing.

The rule of thumb: let agents do the agent steps, let scripts guard them, and let a human approve the result.

Run the agent non-interactively

Claude Code can run headless with -p (print mode), which makes it usable in scripts and CI:

claude -p "Review the diff of this branch against main for the failure modes
in docs/review-checklist.md. Output a Markdown list of findings." \
  --allowedTools "Read,Grep,Glob,Bash(git diff:*)" > review.md

Limit the tools in headless runs to what the step needs. A review step needs to read, not to edit or push. For GitHub there is an official Claude Code GitHub Action that runs the agent on pull requests and issues; check its documentation for current setup.

The gates in CI

# .github/workflows/checks.yml (simplified)
name: checks
on: pull_request
jobs:
  check:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with: { node-version: 22 }
      - run: npm ci
      - run: npm run lint
      - run: npm run typecheck
      - run: npm test
      - run: npm run mutation:changed       # Stryker on files changed vs origin/main
      - run: npx playwright install --with-deps && npm run e2e
      - run: ./scripts/agent-policy.sh       # no edits in src/generated, no new deps without label

A real GitHub Actions run of TestRun Board on a push to main: lint, typecheck, unit and component tests and end-to-end succeeded; mutation score and agent policy are skipped because they only run on pull requests

A real run on a push to main: the mutation and agent policy jobs only run on pull requests, where they compare against the target branch.

The agent policy step is a small script for team rules that are easy to check mechanically: protected folders unchanged, no new dependency without a label, no .only or .skip added.

The complete, working version is in the example repository: .github/workflows/checks.yml runs four jobs (checks, mutation on changed files, e2e, agent policy) and scripts/agent-policy.sh checks generated code, new dependencies and focused or skipped tests. The ALLOW_NEW_DEPS switch is driven by a new-dependency label on the pull request.

Here is the agent policy check on a branch that adds a dependency and an it.only, and on a clean solution branch (real output):

Real output of scripts/agent-policy.sh: on a branch that adds dayjs and an it.only it reports two failures and exits with 1; on solution/lesson-22-flaky-history all three checks pass

A pipeline that still runs next sprint

  • Keep every gate runnable locally with one command (npm run check).
  • Pin tool versions; an upgrade should be a reviewed change.
  • Make failures readable: one clear error message beats 400 lines of log, for humans and agents.
  • Review the pipeline itself every few sprints: remove gates nobody looks at, add one for the last escaped bug.

Hands-on

  1. Write your chain from brief to approval and mark each step agent, script or human.
  2. Add the missing gates to CI, starting with the cheapest.
  3. Write agent-policy.sh with two checks from your CLAUDE.md “never” list.
  4. Add one headless agent step (for example a review summary as a PR comment) with read-only tools.

Walkthrough in TestRun Board

  1. Read .github/workflows/checks.yml: four jobs. Checks and end-to-end run on every push to main and on pull requests; mutation and agent policy run only on pull requests because they compare against the target branch.
  2. Push a branch with a small change and open a pull request: you should see all four jobs.
  3. Make the policy fail on purpose: add any package to package.json and push. “Agent policy” fails with new dependencies without the new-dependency label. Add the label new-dependency to the pull request: the workflow also triggers on label changes, so the policy runs again and passes.
  4. Add a headless review step locally, read-only:
    claude -p "Review the diff of this branch against main using docs/review-checklist.md. \
    Output a Markdown list of findings." --allowedTools "Read,Grep,Glob,Bash(git diff:*)"
    
  5. Everything runs locally with the same commands as in CI: npm run check, npm run e2e, npm run mutation:changed, bash scripts/agent-policy.sh.

Key Takeaways

  • Agents do judgement steps; scripts guard them; humans approve.
  • Headless runs (claude -p) make agent steps scriptable; restrict their tools.
  • CI gates hold no matter who or what wrote the code.
  • Keep the pipeline simple, local-runnable and maintained.