-
Notifications
You must be signed in to change notification settings - Fork 2
CI CD Workflow & Ephemeral Environments
Sebastian Marines edited this page Apr 22, 2025
·
1 revision
We follow a simple “one PR per ticket → merge to main” model with GitHub Actions powering several pipelines:
- Schema Change Workflow
- Full PR Pipeline
- Tear-down on PR Close
This workflow runs only when schema.graphql is modified. It ensures API & client types stay in sync.
-
Trigger Condition
-
on: pushoron: pull_requestwhenschema.graphqlchanges.
-
-
Steps
- Run
npx graphql-codegenlocally (CI installs dependencies then executes). - Generate:
- React hooks (for frontend queries/mutations).
- TypeScript interfaces (for backend resolvers).
- If codegen output isn’t checked in, the job fails and asks contributor to regenerate.
- Run
-
Purpose
-
schema.graphqlis the single source of truth for all data types. - Guarantees type safety between AppSync, Lambda resolvers, and React.
-
Runs on every PR against main, in this order:
- Run all backend & frontend unit tests.
- Fail fast: If any test fails, pipeline stops here.
Each PR branch name must follow our naming convention (e.g. feature/50-graphql-agenda-data)—used to provision isolated stacks.
-
Backend Stack (CDK)
- Inputs: branch name, AWS credentials.
-
Resources:
- DynamoDB tables
- Lambda functions
- AppSync API
- Cognito User Pool
-
Outputs:
- GraphQL endpoint URL
- Cognito User Pool ID & domain
-
Inject Configuration into Frontend
- Script writes a
.envfile infrontend/:REACT_APP_API_URL=<GraphQL URL> REACT_APP_COGNITO_USERPOOL_ID=<UserPool ID> REACT_APP_COGNITO_DOMAIN=<Cognito domain>
- Script writes a
-
Frontend Stack (CDK)
- Runs
npm run buildinfrontend/ - Deploys build to S3 & creates/updates CloudFront distribution
- Invalidates CloudFront cache so the new version is served immediately.
- Runs
-
Data Seeding (Test Only)
- Populates DynamoDB with sample data
- Creates a test user in Cognito User Pool
-
PR Comment
- GitHub Actions posts:
- Ephemeral environment URL
- Cognito login link (if applicable)
- GitHub Actions posts:
- Browsers: Chrome, Firefox, Safari, mobile Chrome & Safari.
-
Flow Tested:
- Log in with test user
- Fetch user data via GraphQL
- Verify UI displays expected information
-
Artifacts:
- Screenshots & HTML report published to an external dashboard
- PR comment with test status & report link (e.g.
https://e2e.app.awscommunity.mx/...)
When a PR is merged or closed:
- Re-run the same CDK script in destroy mode.
- Deletes:
- Backend CloudFormation stack
- Frontend CloudFormation stack
- All associated AWS resources
- Frees up environment to keep costs under control.
-
Branch format:
type/ISSUE_NUMBER-short-description
example:feature/50-graphql-agenda-data -
Stack naming:
Each CDK stack is prefixed by the branch name, e.g.:50-graphql-agenda-data-backend 50-graphql-agenda-data-frontend
- Type Safety on schema changes
- Fast Feedback via unit tests
- Isolated Test Environments per PR
- Automated E2E Validation
- Cost-Controlled Tear-down on branch cleanup