Engineering Playbook

CI/CD Pipelines

GitHub Actions, Reusable Workflows, and Trunk-Based Development.

CI/CD Pipelines

Continuous Integration (CI) is "Merge often, test automatically." Continuous Deployment (CD) is "Ship to production automatically."

The Pipeline Anatomy

A standard pipeline has three distinct stages:

1. The Build Stage (CI)

Fast feedback. Runs on every Pull Request.

  • Lint: Check code style (Prettier/ESLint).
  • Test: Run Unit Tests.
  • Build: Compile the code / Build the Docker Image.
  • Outcome: A "Green" checkmark on GitHub.

2. The Delivery Stage (CD - Staging)

Runs on merge to main.

  • Push: Upload Docker image to ECR/DockerHub.
  • Deploy: Update the Staging environment (Helm upgrade / Terraform apply).
  • Verify: Run Integration/Smoke tests against the live Staging URL.

3. The Release Stage (CD - Prod)

  • Gate: Manual approval button (optional) or automated Canary check.
  • Deploy: Update Production.

GitHub Actions Pattern

Don't copy-paste YAML across 50 repos. Use Reusable Workflows.

Central Repo (infra-modules): /.github/workflows/build-node.yml -> Defines the standard npm install && npm test logic.

App Repo:

jobs:
  ci:
    uses: my-org/infra-modules/.github/workflows/build-node.yml@v1
    with:
      node-version: 18

Trunk-Based Development

Stop using GitFlow (Develop/Release branches). It's too slow.

  • The Rule: Everyone pushes to main (or short-lived feature branches merging to main daily).
  • The Safety: Use Feature Flags. You can merge unfinished code to main if it is wrapped in if (flags.newCheckout). It sits in Prod, dormant, until you flip the switch.

Caching is King

The slowest part of CI is usually npm install or docker build.

Aggressively use caching:

  1. Cache node_modules based on package-lock.json hash.
  2. Use Docker Layer Caching (or GitHub Actions Cache API).