|
| 1 | +[//]: # (.github/CI-CD.md) |
| 2 | + |
| 3 | +## CI/CD & Automation |
| 4 | + |
| 5 | +This project uses GitHub Actions to build, validate, and deploy a static Next.js site to AWS (S3 + CloudFront). |
| 6 | + |
| 7 | +### Workflow Layout |
| 8 | + |
| 9 | +| Workflow | File | Trigger | Purpose | |
| 10 | +|----------|------|---------|---------| |
| 11 | +| CI | [`ci.yml`](workflows/ci.yml) | Push, pull request, manual dispatch | Orchestrates build, Lighthouse, and gated deploy | |
| 12 | +| Build Static Site | [`build-static-site.yml`](workflows/build-static-site.yml) | `workflow_call` | Builds the site and uploads the deployable artifact | |
| 13 | +| Lighthouse Static Site | [`lighthouse-static-site.yml`](workflows/lighthouse-static-site.yml) | `workflow_call` | Runs Lighthouse against the uploaded build artifact | |
| 14 | +| Deploy Static Site | [`deploy-static-site.yml`](workflows/deploy-static-site.yml) | `workflow_call` | Downloads the artifact, deploys to AWS, invalidates CloudFront, and tags the release | |
| 15 | + |
| 16 | +### CI Flow |
| 17 | + |
| 18 | +The top-level CI workflow builds once, validates that exact artifact with Lighthouse, and only then deploys it on `master`. |
| 19 | + |
| 20 | +| Job | Description | |
| 21 | +|-----|-------------| |
| 22 | +| Build | Installs dependencies, runs `pnpm build`, and uploads `dist/` as an artifact | |
| 23 | +| Lighthouse | Downloads the `dist/` artifact and runs `npx @lhci/cli autorun` | |
| 24 | +| Deploy | Downloads the same `dist/` artifact, syncs it to S3, invalidates CloudFront, and creates a semver deployment tag | |
| 25 | + |
| 26 | +### Reuse Across Repos |
| 27 | + |
| 28 | +The reusable workflows in `.github/workflows/` are designed to be called by another repo with the same stack. The caller should: |
| 29 | + |
| 30 | +1. Standardize on the same GitHub secret and variable names. |
| 31 | +2. Pass repo-specific values such as `app_url` and `cdk_stack_name` as workflow inputs. |
| 32 | +3. Pin external reusable workflow references to a commit SHA when another repo starts calling them. |
| 33 | + |
| 34 | +### Deployment Behavior |
| 35 | + |
| 36 | +Deploy runs only after both Build and Lighthouse succeed. |
| 37 | + |
| 38 | +| Step | Description | |
| 39 | +|------|-------------| |
| 40 | +| Configure AWS | OIDC authentication via `AWS_DEPLOY_ROLE_ARN` | |
| 41 | +| Read CDK stack outputs | Fetches the S3 bucket name and CloudFront distribution ID from CloudFormation | |
| 42 | +| Sync to S3 | `aws s3 sync dist/ s3://<bucket> --delete` | |
| 43 | +| Invalidate CloudFront | Creates a `/*` invalidation | |
| 44 | +| Tag deployment | Auto-increments the semver patch version on successful deploy | |
| 45 | + |
| 46 | +### Versioning |
| 47 | + |
| 48 | +Deployments are tagged with semver versions that auto-increment on each successful deploy. |
| 49 | + |
| 50 | +| Action | Example | |
| 51 | +|--------|---------| |
| 52 | +| Automatic (every deploy) | `v1.0.0` -> `v1.0.1` -> `v1.0.2` | |
| 53 | +| Manual minor bump | `git tag v1.1.0 && git push origin v1.1.0` | |
| 54 | +| Manual major bump | `git tag v2.0.0 && git push origin v2.0.0` | |
| 55 | + |
| 56 | +List all deployment versions: |
| 57 | + |
| 58 | +```bash |
| 59 | +git tag -l 'v*' --sort=-v:refname |
| 60 | +``` |
| 61 | + |
| 62 | +### Required Secrets & Variables |
| 63 | + |
| 64 | +#### Secrets |
| 65 | + |
| 66 | +| Secret | Required | Purpose | |
| 67 | +|--------|----------|---------| |
| 68 | +| `AWS_DEPLOY_ROLE_ARN` | Yes | IAM role ARN for GitHub OIDC authentication | |
| 69 | +| `NEXT_PUBLIC_CLOUDINARY_CLOUD_NAME` | Yes | Cloudinary cloud name embedded in the static build | |
| 70 | + |
| 71 | +#### Variables / Environment |
| 72 | + |
| 73 | +| Variable | Required | Default | Purpose | |
| 74 | +|----------|----------|---------|---------| |
| 75 | +| `AWS_REGION` | No | `us-east-2` | AWS region for deployment and public client config | |
| 76 | +| `NEXT_PUBLIC_APP_URL` | No | `http://localhost:3000` | Site URL embedded in static output | |
| 77 | +| `NEXT_PUBLIC_AWS_REGION` | No | `us-east-2` | AWS region exposed to the client | |
| 78 | +| `NEXT_PUBLIC_CF_ANALYTICS_TOKEN` | No | — | Cloudflare Web Analytics token | |
| 79 | +| `NEXT_PUBLIC_CW_RUM_APP_MONITOR_ID` | No | — | CloudWatch RUM App Monitor ID | |
| 80 | +| `NEXT_PUBLIC_CW_RUM_IDENTITY_POOL_ID` | No | — | CloudWatch RUM Cognito Identity Pool ID | |
| 81 | +| `NEXT_PUBLIC_SENTRY_DSN` | No | — | Sentry DSN | |
| 82 | + |
| 83 | +Environment variable schemas are validated at build time by [`src/buildEnv.ts`](../src/buildEnv.ts) and [`src/clientEnv.ts`](../src/clientEnv.ts). |
0 commit comments