Now Pair With an AI
Step 1: You already built this solo
You just worked through the Lint + Test + Ship project yourself, unaided — you fixed a real lint violation, read through a real multi-job workflow line by line, and ran the exact commands that workflow would run, for real, against a real package. That project is unchanged; this page is additive. Now imagine a more realistic shortcut: instead of hand-writing ci.yml and reading every line, you just ask an AI assistant to generate the whole thing — the way developers actually do this on real teams, constantly.
Step 2: Now pair with an AI
Here's a real prompt a learner could give an AI assistant to build a workflow like the one in this chapter's project:
Write me a GitHub Actions workflow that lints and tests my Python
project across multiple versions. It's a package called
expense_tracker with a tests/ folder using pytest, and dev
dependencies listed in requirements-dev.txt. I want it to run
ruff for linting and pytest for tests, and test against a couple
different Python versions since I want to support more than one.
And here's a plausible response — the kind of workflow an AI assistant might hand back on the first try, confident and syntactically clean. Read it the way you'd read a pull request from a teammate, before scrolling to the critique below.
name: CI
on:
push:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.11", "3.12"]
steps:
- name: Check out code
uses: actions/checkout@main
- name: Set up Python
uses: actions/setup-python@main
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: pip install -r requirements-dev.txt
- name: Lint and test
run: |
ruff check . || echo "Lint check complete"
pytest -v
It's clean, uses real syntax correctly, tests two Python versions like you asked, and would genuinely run without erroring out. It also has three separate problems that would only become obvious once someone actually relied on it.
Step 3: Where did the AI's workflow lie to you?
Click to see the critique
What it looks like it does: a normal, minimal on: block — "run when code changes," which sounds like it covers the obvious case.
What it actually risks: on: push alone only runs the workflow when commits land directly on a branch that's pushed — it does not run when someone opens or updates a pull request from a fork, or in many team setups, even a same-repo branch PR, depending on how status checks are wired to branch protection. The prompt asked for a workflow to "lint and test my project," and the whole practical value of that in a team setting is catching a broken change before it merges into main — which requires the check to run on the pull request itself, visibly attached to it, not just after the fact once it's already been pushed to main.
Why it matters: without pull_request as a trigger, a reviewer looking at a PR sees no CI status at all — no green check, no red X, nothing to require via branch protection. Broken code can be reviewed, approved, and merged with zero automated verification, and the workflow only "catches" the problem after it's already on main, which is exactly the late, expensive kind of discovery CI is supposed to prevent (see this chapter's "shift left" concept).
The fix: add a pull_request: trigger alongside push:, both targeting main — exactly what this project's own ci.yml does. Now every PR gets a real status check before anyone can merge it.
@main) are a real supply-chain risk, not just a style nitpick
What it looks like it does: uses: actions/checkout@main and actions/setup-python@main look like they're just pointing at "the latest version" — convenient, always up to date, nothing to maintain.
What it actually risks: @main points at whatever the actual latest commit on that action repository's default branch is at the moment the workflow runs — not a fixed, reviewed release. If the action's maintainers ship a breaking change, an accidental bug, or (in a worst case) if the action's repository itself is ever compromised and malicious code is pushed to its default branch, every workflow using @main picks it up automatically and silently, with no warning and no diff to review. This isn't a hypothetical: it's the exact mechanism behind real supply-chain attacks that have hit widely-used GitHub Actions in the past.
Why it matters: a workflow that behaves one way today can behave differently tomorrow with zero changes to your own repository — and because it's an upstream action's code actually executing on your runner with access to your repo's checkout (and potentially your secrets), an unpinned reference is a real, not theoretical, attack surface.
The fix: pin to a specific released major-version tag — actions/checkout@v4, actions/setup-python@v5 — as this project's own ci.yml does. Major-version tags still get patch/security updates from the maintainer, but only within that reviewed major version, not an arbitrary unreviewed commit. (Security-conscious teams go further and pin to a full commit SHA, but a major-version tag is the realistic minimum.)
|| echo, so a real lint error never fails the build
What it looks like it does: ruff check . || echo "Lint check complete" reads like a harmless status message — printing a friendly confirmation after the lint step runs.
What it actually risks: in a shell, A || B runs B only if A fails, and critically, the overall exit code of that combined command becomes B's exit code — and echo always succeeds (exit code 0). So if ruff check . finds a real violation and exits non-zero, this line catches that failure and replaces it with a successful echo, meaning the step (and therefore the whole job) reports success regardless of what ruff actually found. The lint job would show a green check on every single run, forever, even with genuine lint errors present — there's no scenario in which this step fails.
Why it matters: this is worse than having no lint step at all, because it actively displays a false signal of health — a reviewer sees a green "Lint and test" check and reasonably trusts it, with no way to tell from the PR itself that the check can never fail. This exact `|| echo` / `|| true` pattern is a real, easy-to-miss mistake precisely because the workflow doesn't error out; it just quietly stops meaning anything.
The fix: let ruff check . run as its own step with no fallback (run: ruff check .), exactly as this project's own ci.yml does — a failing command's non-zero exit code should propagate and fail the step/job, which is the entire mechanism a status check relies on to mean anything.
Step 4: Your entry for this chapter's playbook
Fill this in for yourself — it's not saved or sent anywhere, just yours to keep (copy it into your own notes before you close this tab).