Skip to content

Commit

Permalink
Merged in master
Browse files Browse the repository at this point in the history
  • Loading branch information
justino599 committed Jan 24, 2024
2 parents 8fe7d3e + 15c03c0 commit f299abc
Show file tree
Hide file tree
Showing 70 changed files with 1,159 additions and 414 deletions.
8 changes: 1 addition & 7 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
.husky
.next
node_modules
public

# Exclude tests
cypress
cypress.config.ts

# Exclude configuration files
.dockerignore
Expand All @@ -16,15 +16,9 @@ cypress
.prettier*
*docker-compose*
*Dockerfile*
*.config.js
tsconfig.json

# Exlude documentation
docs
*.md

npm-debug.log

# Environment variables
.env
.env*.local
160 changes: 94 additions & 66 deletions .github/workflows/e2e_tests_preview.yml
Original file line number Diff line number Diff line change
@@ -1,97 +1,127 @@
name: Cypress E2E Tests (Preview Deployment)

on:
workflow_dispatch:
inputs:
run_deploy:
description: 'Run deploy-preview job'
required: false
type: boolean
default: false
pull-request:
types:
- ready_for_review

env:
AWS_REGION: ca-central-1 # set this to your preferred AWS region, e.g. us-west-1
ECR_REPOSITORY: harp-video # set this to your Amazon ECR repository name
ECS_SERVICE: harp-video-website-staging-deployment # set this to your Amazon ECS service name
ECS_CLUSTER: HarpVideoDeployment # set this to your Amazon ECS cluster name
ECS_TASK_DEFINITION: amazon-ecs-task-definition.json # set this to the path to your Amazon ECS task definition
# file, e.g. .aws/task-definition.json
CONTAINER_NAME: harp-video # set this to the name of the container in the
# containerDefinitions section of your task definition

permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout

jobs:
deploy-preview:
name: Deploy Preview
name: Deploy
runs-on: ubuntu-latest
if: ${{ inputs.run_deploy }}
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
environment: preview

steps:
- uses: actions/checkout@v4
- name: Install Vercel CLI
run: npm install --global vercel@latest
- name: Pull Vercel Environment Information
run: vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }}
- name: Write .env
run: |
echo "${{ secrets.ENV_PREVIEW }}" > .env
- name: Build Project Artifacts
run: vercel build --token=${{ secrets.VERCEL_TOKEN }}
- name: Deploy Project Artifacts to Vercel
run: |
url="$(vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }})"
vercel alias --token=${{ secrets.VERCEL_TOKEN }} set "$url" ubco-capstone-team-3.vercel.app
- name: Checkout
uses: actions/checkout@v4

- name: Create env File
run: |
echo "${{ secrets.STAGING_ENV_FILE }}" > .env
- name: configure aws credentials
uses: aws-actions/configure-aws-credentials@v3
with:
role-to-assume: arn:aws:iam::932748244514:role/GithubActionRole
role-session-name: GithubActionRole
aws-region: ${{ env.AWS_REGION }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@62f4f872db3836360b72999f4b87f1ff13310f3a
- name: Build, tag, and push image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ github.sha }}
run: |
# Build a docker container and
# push it to ECR so that it can
# be deployed to ECS.
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f Dockerfile.prod .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT
- name: Fill in the new image ID in the Amazon ECS task definition
id: task-def
uses: aws-actions/amazon-ecs-render-task-definition@c804dfbdd57f713b6c079302a4c01db7017a36fc
with:
task-definition: ${{ env.ECS_TASK_DEFINITION }}
container-name: ${{ env.CONTAINER_NAME }}
image: ${{ steps.build-image.outputs.image }}
- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@df9643053eda01f169e64a0e60233aacca83799a
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: ${{ env.ECS_SERVICE }}
cluster: ${{ env.ECS_CLUSTER }}
wait-for-service-stability: true

setup-db:
name: Set up database
name: Migrate Database
runs-on: ubuntu-latest
if: ${{ inputs.run_deploy }}
needs: [ 'deploy-preview' ]
continue-on-error: true
needs: ['deploy-preview']
steps:
- uses: actions/checkout@v4
- name: Write environment variables
run: |
echo "${{ secrets.ENV_PREVIEW }}" > .env
- name: Migrate Database
run: npx prisma migrate deploy &> prisma_migrate.log


- uses: actions/checkout@v4
- name: Write environment variables
run: |
echo "${{ secrets.STAGING_ENV_FILE }}" > .env
- name: Install Packages
run: |
npm ci
- name: Generate Prisma
run: |
npx prisma generate
- name: Migrate Database
run: npx prisma migrate deploy

cypress-e2e:
name: Run cypress E2E tests on preview deployment
name: Run Cypress E2E Tests on Preview Deployment
runs-on: ubuntu-latest
if: always()
needs: [ deploy-preview, setup-db ]
outputs:
PR_ID: ${{ steps.save-cypress-outputs.outputs.PR_ID }}
needs: [ deploy-preview, setup-db]
steps:
- uses: actions/checkout@v4
- name: Write environment variables
run: |
echo "${{ secrets.ENV_PREVIEW }}" > .env
- name: Cypress Run E2E Tests
uses: cypress-io/github-action@v6
env:
GITHUB_TOKEN: ${{ secrets.PERSONAL_GITHUB_ACCESS_TOKEN }}
with:
wait-on: ${{ secrets.CYPRESS_BASE_URL }}
browser: chrome
headed: true
config: baseUrl=${{ secrets.CYPRESS_BASE_URL }}
echo "${{ secrets.STAGING_ENV_FILE }}" > .env
- name: Install Packages
run: |
npm ci
- name: Generate Prisma
run: |
npx prisma generate
- name: Run Cypress Tests
run: |
npx cypress run
- name: Upload screenshots
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
if: failure()
with:
name: cypress-screenshots
path: cypress/screenshots
if-no-files-found: ignore
- name: Upload videos
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
if: failure()
with:
name: cypress-videos
path: cypress/videos
if-no-files-found: ignore
- name: Save cypress outputs
if: always()
id: save-cypress-outputs
run: |
echo "PR_ID=$CYPRESS_PULL_REQUEST_ID" >> $GITHUB_OUTPUT
- name: Upload test results
- name: Upload Test Results
if: always()
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: e2e-test-results
path: cypress/reports/e2e/e2e*.json
Expand All @@ -104,7 +134,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Download test results
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: e2e-test-results
path: cypress/reports
Expand All @@ -116,9 +146,7 @@ jobs:
npx mochawesome-json-to-md@0.7.2 -p cypress/reports/test_results.json -o cypress/reports/test_results.md --reportTitle="E2E Test Results"
- name: Create report and post on PR
uses: peter-evans/create-or-update-comment@v3
env:
PR_ID: ${{ needs.cypress-e2e.outputs.PR_ID }}
with:
issue-number: ${{ env.PR_ID }}
issue-number: ${{ github.event.number }}
body-path: cypress/reports/test_results.md
token: ${{ secrets.PERSONAL_GITHUB_ACCESS_TOKEN }}
99 changes: 2 additions & 97 deletions .github/workflows/local_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
run: npm ci
- name: Write environment variables
run: |
echo "${{ secrets.ENV_TEST_LOCAL }}" > .env
echo "${{ secrets.STAGING_ENV_FILE }}" > .env
echo "" > cypress.config.json
- name: ESLint
run: npm run lint
Expand All @@ -40,7 +40,7 @@ jobs:
node-version: '18.18.0'
- name: Write environment variables
run: |
echo "${{ secrets.ENV_TEST_LOCAL }}" > .env
echo "${{ secrets.STAGING_ENV_FILE }}" > .env
echo "" > cypress.config.json
- name: Run Component Tests
uses: cypress-io/github-action@v6
Expand Down Expand Up @@ -88,98 +88,3 @@ jobs:
issue-number: ${{ env.PR_ID }}
body-path: cypress/reports/test_results.md
token: ${{ secrets.PERSONAL_GITHUB_ACCESS_TOKEN }}

migrate-db-e2e:
name: Set up database
runs-on: ubuntu-latest
needs: [ run-lint ]
continue-on-error: true
steps:
- uses: actions/checkout@v4
- name: Write environment variables
run: |
echo "${{ secrets.ENV_TEST_LOCAL }}" > .env
- name: Migrate Database
run: npx prisma migrate deploy &> prisma_migrate.log

cypress-e2e:
name: Cypress Run E2E Tests on GitHub machine
runs-on: ubuntu-latest
needs: [ migrate-db-e2e ]
outputs:
PR_ID: ${{ steps.save-cypress-outputs.outputs.PR_ID }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: '18.18.0'
- name: Write environment variables
run: |
echo "${{ secrets.ENV_TEST_LOCAL }}" > .env
echo "" > cypress.config.json
- name: Run E2E Tests
uses: cypress-io/github-action@v6
env:
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
GITHUB_TOKEN: ${{ secrets.PERSONAL_GITHUB_ACCESS_TOKEN }}
CYPRESS_BASE_URL: ${{ secrets.CYPRESS_BASE_URL }}
with:
build: npm run build
start: npm run start
install: true
browser: chrome
headed: true
wait-on: ${{ env.CYPRESS_BASE_URL }}
config: baseUrl=${{ env.CYPRESS_BASE_URL }}
- name: Save cypress video
if: failure()
uses: actions/upload-artifact@v3
with:
name: cypress-videos
path: cypress/videos
if-no-files-found: ignore
- name: Save cypress screenshots
if: failure()
uses: actions/upload-artifact@v3
with:
name: cypress-screenshots
path: cypress/screenshots
if-no-files-found: ignore
- name: Save cypress results
id: save-cypress-outputs
run: |
echo "PR_ID=$CYPRESS_PULL_REQUEST_ID" >> $GITHUB_OUTPUT
- name: Upload test results
if: always()
uses: actions/upload-artifact@v3
with:
name: e2e-test-results
path: cypress/reports/e2e/e2e*.json

e2e-results-report:
name: Report E2E test results
runs-on: ubuntu-latest
if: always()
needs: [ cypress-e2e ]
steps:
- uses: actions/checkout@v4
- name: Download test results
uses: actions/download-artifact@v3
with:
name: e2e-test-results
path: cypress/reports
- name: Merge reports to 1 report file
run: |
npx mochawesome-merge cypress/reports/*.json > cypress/reports/test_results.json
- name: Convert report file to markdown
run: |
npx mochawesome-json-to-md@0.7.2 -p cypress/reports/test_results.json -o cypress/reports/test_results.md --reportTitle="E2E Test Results (Local)"
- name: Create report and post on PR
uses: peter-evans/create-or-update-comment@v3
continue-on-error: true
env:
PR_ID: ${{ needs.cypress-e2e.outputs.PR_ID || github.event.number }}
with:
issue-number: ${{ env.PR_ID }}
body-path: cypress/reports/test_results.md
token: ${{ secrets.PERSONAL_GITHUB_ACCESS_TOKEN }}
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ yarn-debug.log*
yarn-error.log*

# local env files
.env*.local
.env
.env*
cypress.env.json

# vercel
Expand Down
Loading

0 comments on commit f299abc

Please sign in to comment.