CI/CD Setup
Intro
A good CI pipeline runs the same checks a developer would run locally, in
the same order, fast enough that contributors get feedback before they
context-switch. Lint first, then test, then build, then deploy — and never
let secrets or unpinned actions sneak in.
Overview
Pipeline stages
Order stages from cheapest to most expensive so failures surface early:
- Lint — format checking and static analysis (fastest feedback)
- Test — unit tests first, then integration tests
- Build — compile, package, create release artifacts
- Deploy — push to staging, then promote to production
GitHub Actions basics
Trigger on push to main and on pull_request. Pin action versions
explicitly (actions/checkout@v4, never @latest). Cache dependencies
(pip, npm, cargo) so reruns are fast. Set timeout-minutes on every job
so a hung step cannot eat your minutes budget.
Testing in CI
Run the same commands as local development — if make test works
locally, that is what CI should call. Use matrix builds for OS or
language-version combinations only when you actually need to support
them. Use fail-fast: true in matrix strategies so one failure cancels
the rest.
Security
Never put secrets in workflow files. Store them in GitHub Secrets and
inject through ${{ secrets.NAME }}. Use the permissions key on each
job to limit the GITHUB_TOKEN scope to the minimum needed. Pin
third-party actions to a commit SHA, not just a version tag, so an
attacker who compromises a tag cannot inject code into your build.
Best practices
- Keep PR pipelines under five minutes wherever possible.
- Make CI failures actionable — clear error messages, surfaced summaries.
- Require CI to pass before merge via branch protection rules.
- Run expensive checks (E2E suites, deploys) only on main, not on PRs.
Gotchas
Agent-specific failure modes — provider-neutral pause-and-self-check items:
- Pinning an action to a tag instead of a commit SHA. Tags are mutable — an attacker who compromises an action's tag can inject code into your build. Pin third-party actions to their full commit SHA, not just
@v4.
- Secrets leaking into build logs. Printing or echoing an environment variable that contains a secret exposes it in the CI log. Never
echo ${{ secrets.FOO }} — pass secrets only through inputs or masked env vars.
- Running expensive checks on every PR. E2E tests and deploy jobs on every pull request slow the pipeline and teach contributors to bypass CI. Gate slow jobs behind
if: github.ref == 'refs/heads/main' or a label.
- No
timeout-minutes on jobs. A hung step runs indefinitely and eats your minutes budget. Every job and every slow step needs a timeout — not just the slow ones you expect.
- CI passes but local fails (or vice versa). Environment divergence — OS, timezone, locale, file path casing, implicit tool versions — causes mismatch. Make CI reproduce local conditions explicitly; never assume the runner matches the developer's machine.
- One mega-job that lints, tests, builds, and deploys. Failures are hard to locate, reruns are expensive, and the job cannot parallelize. Split into separate jobs; each job should do one thing.
- Branch protection not enforcing required status checks. If CI is advisory rather than required for merge, it stops being trusted. Configure branch protection to require every status check that matters before merge.
Full reference
Sample workflow shape
name: ci
on:
push:
branches: [main]
pull_request:
jobs:
lint:
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: pip
- run: pip install -e .[dev]
- run: ruff check .
test:
needs: lint
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: pip
- run: pip install -e .[dev]
- run: pytest
Caching tips by ecosystem
| Ecosystem |
Cache key target |
| Python (pip) |
setup-python with cache: pip and cache-dependency-path |
| Node (npm/yarn/pnpm) |
setup-node with cache: npm (or yarn/pnpm) |
| Rust (cargo) |
Swatinem/rust-cache action keyed on Cargo.lock |
| Go |
actions/setup-go with cache: true |
| Docker layers |
docker/build-push-action with cache-from/cache-to |
Anti-patterns
actions/checkout@latest — pin to a major version or SHA
- Putting tokens in
env: blocks at the top of a workflow — use job
or step scope so secrets are not over-shared
- Running E2E tests on every PR — gate them behind a label or run
only on main
- Skipping CI with
[skip ci] to "save time" — fix the slow step
instead; once CI is optional, it stops being trusted
- One mega-job that lints, tests, builds, deploys — split into
jobs so failures are localized and reruns are cheap
Branch protection checklist
- Require pull request reviews before merge
- Require status checks to pass:
lint, test, and any required builds
- Require branches to be up to date before merging
- Restrict who can push directly to
main
- Require signed commits if your team has the workflow for it
1---2name: ci-cd-setup3description: |4 CI/CD pipeline setup — GitHub Actions, testing, linting, deployment. Use when setting up CI from scratch, adding GitHub Actions, automating tests, wiring up deployment, or improving an existing build pipeline.5metadata:6 source: https://skillmd.com/skills/projectious-work/ci-cd-setup7 processkit:8 apiVersion: processkit.projectious.work/v19 id: SKILL-ci-cd-setup10 version: "1.1.0"11 created: 2026-04-06T00:00:00Z12 category: devops13---1415# CI/CD Setup1617## Intro1819A good CI pipeline runs the same checks a developer would run locally, in20the same order, fast enough that contributors get feedback before they21context-switch. Lint first, then test, then build, then deploy — and never22let secrets or unpinned actions sneak in.2324## Overview2526### Pipeline stages2728Order stages from cheapest to most expensive so failures surface early:29301. **Lint** — format checking and static analysis (fastest feedback)312. **Test** — unit tests first, then integration tests323. **Build** — compile, package, create release artifacts334. **Deploy** — push to staging, then promote to production3435### GitHub Actions basics3637Trigger on `push` to main and on `pull_request`. Pin action versions38explicitly (`actions/checkout@v4`, never `@latest`). Cache dependencies39(pip, npm, cargo) so reruns are fast. Set `timeout-minutes` on every job40so a hung step cannot eat your minutes budget.4142### Testing in CI4344Run the same commands as local development — if `make test` works45locally, that is what CI should call. Use matrix builds for OS or46language-version combinations only when you actually need to support47them. Use `fail-fast: true` in matrix strategies so one failure cancels48the rest.4950### Security5152Never put secrets in workflow files. Store them in GitHub Secrets and53inject through `${{ secrets.NAME }}`. Use the `permissions` key on each54job to limit the `GITHUB_TOKEN` scope to the minimum needed. Pin55third-party actions to a commit SHA, not just a version tag, so an56attacker who compromises a tag cannot inject code into your build.5758### Best practices5960- Keep PR pipelines under five minutes wherever possible.61- Make CI failures actionable — clear error messages, surfaced summaries.62- Require CI to pass before merge via branch protection rules.63- Run expensive checks (E2E suites, deploys) only on main, not on PRs.6465## Gotchas6667Agent-specific failure modes — provider-neutral pause-and-self-check items:6869- **Pinning an action to a tag instead of a commit SHA.** Tags are mutable — an attacker who compromises an action's tag can inject code into your build. Pin third-party actions to their full commit SHA, not just `@v4`.70- **Secrets leaking into build logs.** Printing or echoing an environment variable that contains a secret exposes it in the CI log. Never `echo ${{ secrets.FOO }}` — pass secrets only through inputs or masked env vars.71- **Running expensive checks on every PR.** E2E tests and deploy jobs on every pull request slow the pipeline and teach contributors to bypass CI. Gate slow jobs behind `if: github.ref == 'refs/heads/main'` or a label.72- **No `timeout-minutes` on jobs.** A hung step runs indefinitely and eats your minutes budget. Every job and every slow step needs a timeout — not just the slow ones you expect.73- **CI passes but local fails (or vice versa).** Environment divergence — OS, timezone, locale, file path casing, implicit tool versions — causes mismatch. Make CI reproduce local conditions explicitly; never assume the runner matches the developer's machine.74- **One mega-job that lints, tests, builds, and deploys.** Failures are hard to locate, reruns are expensive, and the job cannot parallelize. Split into separate jobs; each job should do one thing.75- **Branch protection not enforcing required status checks.** If CI is advisory rather than required for merge, it stops being trusted. Configure branch protection to require every status check that matters before merge.7677## Full reference7879### Sample workflow shape8081```yaml82name: ci83on:84 push:85 branches: [main]86 pull_request:87jobs:88 lint:89 runs-on: ubuntu-latest90 timeout-minutes: 591 permissions:92 contents: read93 steps:94 - uses: actions/checkout@v495 - uses: actions/setup-python@v596 with:97 python-version: "3.12"98 cache: pip99 - run: pip install -e .[dev]100 - run: ruff check .101 test:102 needs: lint103 runs-on: ubuntu-latest104 timeout-minutes: 10105 steps:106 - uses: actions/checkout@v4107 - uses: actions/setup-python@v5108 with:109 python-version: "3.12"110 cache: pip111 - run: pip install -e .[dev]112 - run: pytest113```114115### Caching tips by ecosystem116117| Ecosystem | Cache key target |118|---|---|119| Python (pip) | `setup-python` with `cache: pip` and `cache-dependency-path` |120| Node (npm/yarn/pnpm) | `setup-node` with `cache: npm` (or yarn/pnpm) |121| Rust (cargo) | `Swatinem/rust-cache` action keyed on `Cargo.lock` |122| Go | `actions/setup-go` with `cache: true` |123| Docker layers | `docker/build-push-action` with `cache-from`/`cache-to` |124125### Anti-patterns126127- **`actions/checkout@latest`** — pin to a major version or SHA128- **Putting tokens in `env:` blocks at the top of a workflow** — use job129 or step scope so secrets are not over-shared130- **Running E2E tests on every PR** — gate them behind a label or run131 only on main132- **Skipping CI with `[skip ci]` to "save time"** — fix the slow step133 instead; once CI is optional, it stops being trusted134- **One mega-job that lints, tests, builds, deploys** — split into135 jobs so failures are localized and reruns are cheap136137### Branch protection checklist138139- Require pull request reviews before merge140- Require status checks to pass: `lint`, `test`, and any required builds141- Require branches to be up to date before merging142- Restrict who can push directly to `main`143- Require signed commits if your team has the workflow for it