ADR-012: CI/CD Pipeline Performance & Security Optimization
Context
Our optimized multi-job workflow must deliver rapid feedback. The old sequential pipeline had bottlenecks: it ran Node installation, linter, tests, and Terraform sequentially, even on PRs that only altered Terraform config. Additionally, global permissions exposed deployment tokens to third-party NPM packages.
Decision
Refactor the linear pipeline into four specialized jobs:
1. `ci-node`: Focuses entirely on testing, linting, and compiling, caching `node_modules` directly based on `package-lock.json`.
2. `terraform-plan` (PR-only): Runs after `ci-node` passes, only when backend files changed, using a fallback image tag.
3. `deploy-infra` (main push): Authenticates, builds/pushes Docker, and applies Terraform.
4. `deploy-hosting` (main push): Runs in parallel with `deploy-infra` using fast dynamic CLI tools.
Only jobs that talk to GCP get `id-token: write` (plus `contents: read`); no job has `deployments: write`. `ci-node` gets `contents: read` and `pull-requests: read`.
Amended 2026-10-16: tag pushes run a separate promotion chain instead (ADR-021), and the tag comes from publishing the draft prepared by release.yml. Staging deploys are path-filtered (hosting only on frontend changes). PRs always run CI, because Node.js CI is a required check.
Consequences
Benefits:
* Keeps PR feedback fast: caching shortens `ci-node`, and the Terraform plan is skipped when no backend files change.
* Direct caching completely bypasses `npm ci` (saving ~35s) on cache hits.
* Enforces strict job-level permissions, isolating Node.js runners from GCP deployer keys.
* Parallelizes environment deployments, saving another 40s in release stages.
The job topology established here was later extended with digest-based production promotion — the release path no longer rebuilds at all (ADR-021).
Alternatives considered
1. Sequential releases: Rejected because both Cloud Run and Firebase Hosting support native, zero-downtime rolling deployments, making parallel releases completely safe.
2. Full sequential pipelines: Rejected due to runner inefficiencies.