CI/CD
CI (continuous integration) verifies every merge automatically; CD (continuous delivery/deployment) promotes artifacts across environments after verification. Goals: fast feedback, actionable failures, repeatable releases.
Pipeline stages (template)
| Stage | Typical work | Block on fail |
|---|---|---|
| Install | Locked deps, cache | Yes |
| Static checks | Lint, format, types | Yes |
| Unit/component tests | Fast suite, optional coverage floor | Yes |
| Build | Compile, bundle, image | Yes |
| Integration/contracts | DB containers, Pact, OpenAPI diff | Yes when bounded |
| Security | Dependency/secret scan | By severity |
| Deploy | staging → approval → prod | Per policy |
Rule: fail early; minute-level signal beats nightly batches.
Quality gates
| Gate | Notes |
|---|---|
| Branch protection | No direct push to main; PR + required checks |
| Required checks | Names match rules (test, lint, build) |
| Coverage | Avoid vanity 100%; watch critical packages regress |
| Contracts | Consumer jobs verify provider artifacts |
| Immutable artifacts | Same commit → same digest |
warning
Deploy without verify: green deploy scripts but no tests = manual CD. At minimum run core tests before merge.
Environments
| Env | Purpose | Data |
|---|---|---|
| local | Dev | Local/seed |
| preview | Per-PR | Synthetic or masked |
| staging | Pre-prod validation | Masked subset |
| production | Users | Live |
Example promotion:
- Merge to
main→ auto staging - Tag
v*→ production with approval - DB migrations: expand → deploy → contract for forward compatibility
Deploy strategies
| Strategy | When | Caveat |
|---|---|---|
| Rolling | Stateless services | Readiness probes, surge limits |
| Blue/green | Fast cutover | Double capacity, sticky sessions |
| Canary | Risk-sensitive | Automated rollback on metrics |
Store/static flows: mobile, frontend.
Observability and rollback
- Tie releases to commit SHA, build id, change ticket
- Golden signals: latency, traffic, errors, saturation
- Rollback: redeploy previous image/build; DB rollback needs upfront design
Minimal CI for personal repos
# Sketch: on pull_request + push to main
# jobs: lint → test → build
Prefer one workflow file, dependency caching, matrices only when multiple runtimes matter.