Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .ebignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage
/test-results
/playwright-report

# next.js
/out/
.swc

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts

# Elastic Beanstalk Files
.elasticbeanstalk/*
!.elasticbeanstalk/*.cfg.yml
!.elasticbeanstalk/*.global.yml
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @ACompleteNoobSmoke
11 changes: 11 additions & 0 deletions .github/slack/test-failure-slack-payload.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "* <https://github.com/${{github.repository}}/actions/runs/${{github.run_id }}|${{ github.workflow }} workflow run>* failed."
}
}
]
}
15 changes: 15 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: CI

on:
pull_request:
branches: [main]

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
cancel-in-progress: true

jobs:
run-tests:
name: Run Test
uses: ./.github/workflows/test.yaml
secrets: inherit
120 changes: 120 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
name: Deploy

run-name: Deploy

on:
workflow_dispatch:
inputs:
aws-env:
description: "AWS Elastic Beanstalk Environmnet"
required: true
default: "gha-course-staging"
type: string
github-env:
description: "Github Environment"
required: true
default: "staging"
type: string
workflow_call:
inputs:
aws-env:
description: "AWS Elastic Beanstalk Environment"
required: true
default: "gha-course-staging"
type: string
github-env:
description: "Github Environment"
required: true
default: "staging"
type: string


concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ inputs.github-env }}

jobs:
deploy:
name: Deploy Project
runs-on: ubuntu-latest
environment:
name: ${{ inputs.github-env }}
url: "http://${{steps.get-env-cname.outputs.aws_cname}}"
steps:
- name: Avoid deploying to production using a non-production env
if: inputs.aws-env == vars.AWS_EB_PRODUCTION_ENV && inputs.github-env != 'production'
run: |
echo "::error::Cannot deploy to production using a non production environment"
exit 1
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ vars.AWS_REGION }}
- name: Checkout Code
uses: actions/checkout@v3
- name: Setup Node Environment
uses: actions/setup-node@v3
with:
node-version: 18
cache: "npm"
- name: Install Dependencies
run: npm ci
- name: Build App
run: npm run build
- name: Cache
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{runner.os}}-pip
- name: Install EB CLI
id: install-eb-cli
run: pip install awsebcli
- name: Get AWS ENV Name
id: get-env-name
run: echo "aws_env=$(aws elasticbeanstalk describe-environments --application-name ${{vars.AWS_EB_APP_NAME}}
--environment-name ${{inputs.aws_env}} --query "Environments[0].EnvironmentName"
--output text)" >> $GITHUB_OUTPUT
- name: Get AWS ENV Status
id: get-env-status
run: echo "aws_status=$(aws elasticbeanstalk describe-environments --application-name ${{vars.AWS_EB_APP_NAME}}
--environment-name ${{inputs.aws_env}} --query "Environments[0].Status"
--output text)" >> $GITHUB_OUTPUT
- name: Initialize EB
run: eb init ${{vars.AWS_EB_APP_NAME}} --platform ${{vars.AWS_EB_PLATFORM}} --region ${{vars.AWS_REGION}}
- name: Create A New Environment
if: steps.get-env-name.outputs.aws_env == 'None' || steps.get-env-status.outputs.aws_status == 'Terminated'
run: eb create ${{inputs.aws-env}} --instance-types ${{vars.AWS_EB_ENV_INSTANCE_TYPES}} --cname ${{inputs.aws-env}}
--envvars FLAGSMITH_KEY=${{ secrets.FLAGSMITH_KEY }}
- name: Deploy if Environment Exists
if: steps.get-env-name.outputs.aws_env == inputs.aws-env && steps.get-env-status.outputs.aws_status != 'Terminated'
run: eb deploy ${{inputs.aws-env}}
- name: Get AWS ENV CNAME
id: get-env-cname
run: echo "aws_cname=$(aws elasticbeanstalk describe-environments --application-name ${{vars.AWS_EB_APP_NAME}}
--environment-name ${{inputs.aws_env}} --query "Environments[0].CNAME"
--output text)" >> $GITHUB_OUTPUT
- name: Send A Slack Message On Failure
id: slack
continue-on-error: true
uses: slackapi/slack-github-action@v1.24.0
with:
payload: |
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ":muscle-rocket: Deployment to AWS environment *${{inputs.aws_env}}*
using *${{inputs.github-env}}* GitHub environment was successfull. <http://${{steps.get-env-cname.outputs.aws_cname}}|View Deployment>"
}
}
]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
- name: Abort if Cancelled
if: cancelled() && steps.install-eb-cli.conclusion == 'success'
run: eb abort ${{ inputs.aws-env}}
90 changes: 90 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: Test WF

on:
workflow_call:

jobs:
test-and-build:
name: Test & Build
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
- name: Setup Node Environment
uses: actions/setup-node@v3
with:
node-version: 18
cache: "npm"
- name: Install Dependencies
run: npm ci
- name: Check For Formatting Errors
run: npm run format
- name: Check For ESLint Errors
run: npm run lint
- name: Check For Type Errors
run: npm run typecheck
- name: Build Project
run: npm run build
env:
FLAGSMITH_KEY: ${{ secrets.FLAGSMITH_KEY }}
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: build
path: .next/
- name: Run Unit Tests
run: npm run test
- name: Upload Coverage Test
if: always()
uses: actions/upload-artifact@v3
with:
name: coverage
path: coverage/
- name: Upload Coverage Reports To Codecov
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
- name: Store Playwright's Version
run: |
PLAYWRIGHT_VERSION=$(npm ls @playwright/test | grep @playwright | sed 's/.*@//')
echo "Playwright's Version: $PLAYWRIGHT_VERSION"
echo "PLAYWRIGHT_VERSION=$PLAYWRIGHT_VERSION" >> $GITHUB_ENV
- name: Cache Playwright Browsers
uses: actions/cache@v3
id: cache-playwright
with:
path: ~/.cache/ms-playwright
key: playwright-browsers-${{ env.PLAYWRIGHT_VERSION }}
- name: Install Playwright Browsers
if: steps.cache-playwright.outputs.cache-hit != 'true'
run: npx playwright install --with-deps
- name: Run E2E Tests
run: npm run test:e2e
env:
FLAGSMITH_KEY: ${{ secrets.FLAGSMITH_KEY }}
- name: Upload E2E Coverage Test
if: always()
uses: actions/upload-artifact@v3
with:
name: playwright-report
path: playwright-report/
- name: Send A Slack Message On Failure
id: slack
if: failure()
uses: slackapi/slack-github-action@v1.24.0
with:
payload: |
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "* <https://github.com/${{github.repository}}/actions/runs/${{github.run_id }}|${{ github.workflow }} workflow run>* failed."
}
}
]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,8 @@ yarn-error.log*
# typescript
*.tsbuildinfo
next-env.d.ts

# Elastic Beanstalk Files
.elasticbeanstalk/*
!.elasticbeanstalk/*.cfg.yml
!.elasticbeanstalk/*.global.yml
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: npm run start -- -p $PORT
16 changes: 14 additions & 2 deletions __tests__/page.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,21 @@ import { render, screen } from "@testing-library/react";
import Home from "../src/app/page";
import "@testing-library/jest-dom";

jest.mock("../src/app/utils/flagsmith", () => {
return {
getEnvironmentFlags: jest.fn(() =>
Promise.resolve({
isFeatureEnabled: () => {
return true;
},
}),
),
};
});

describe("Home", () => {
it("renders a heading", () => {
render(<Home />);
it("renders a heading", async () => {
render(await Home());

const docH = screen.getByRole("heading", {
name: "Hello World",
Expand Down
Loading