Skip to main content

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)

StageTypical workBlock on fail
InstallLocked deps, cacheYes
Static checksLint, format, typesYes
Unit/component testsFast suite, optional coverage floorYes
BuildCompile, bundle, imageYes
Integration/contractsDB containers, Pact, OpenAPI diffYes when bounded
SecurityDependency/secret scanBy severity
Deploystaging → approval → prodPer policy

Rule: fail early; minute-level signal beats nightly batches.

Quality gates

GateNotes
Branch protectionNo direct push to main; PR + required checks
Required checksNames match rules (test, lint, build)
CoverageAvoid vanity 100%; watch critical packages regress
ContractsConsumer jobs verify provider artifacts
Immutable artifactsSame commit → same digest
warning

Deploy without verify: green deploy scripts but no tests = manual CD. At minimum run core tests before merge.

Environments

EnvPurposeData
localDevLocal/seed
previewPer-PRSynthetic or masked
stagingPre-prod validationMasked subset
productionUsersLive

Example promotion:

  • Merge to main → auto staging
  • Tag v* → production with approval
  • DB migrations: expand → deploy → contract for forward compatibility

Deploy strategies

StrategyWhenCaveat
RollingStateless servicesReadiness probes, surge limits
Blue/greenFast cutoverDouble capacity, sticky sessions
CanaryRisk-sensitiveAutomated 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.