-
Notifications
You must be signed in to change notification settings - Fork 2
169 lines (158 loc) · 6.66 KB
/
e2e_tests_preview.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
name: Cypress E2E Tests (Preview Deployment)
on:
pull_request:
types: [ready_for_review, synchronize, opened]
paths-ignore:
- docs/**
- '**.md'
- '**.png'
- '**.jpg'
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: aws/amazon-ecs-preview-deployment-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
concurrency: preview
jobs:
deploy-preview:
name: Deploy
runs-on: ubuntu-latest
if: github.event.pull_request.draft == false
environment: preview
steps:
- 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: Migrate Database
runs-on: ubuntu-latest
needs: ['deploy-preview']
steps:
- 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 reset --force &>-
cypress-e2e:
name: Run Cypress E2E Tests on Preview Deployment
runs-on: ubuntu-latest
needs: [deploy-preview, setup-db]
continue-on-error: true
steps:
- 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: Run Cypress Tests
run: |
npx cypress run
- name: Upload screenshots
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@v4
if: failure()
with:
name: cypress-videos
path: cypress/videos
if-no-files-found: ignore
- name: Upload Test Results
if: always()
uses: actions/upload-artifact@v4
with:
name: e2e-test-results
path: cypress/reports/e2e/e2e*.json
results-report:
name: Report results
runs-on: ubuntu-latest
needs: [cypress-e2e]
permissions:
pull-requests: write
issues: write
contents: read
steps:
- uses: actions/checkout@v4
- name: Download test results
uses: actions/download-artifact@v4
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"
- name: Try to find existing report comment
uses: peter-evans/find-comment@v3
id: find-comment
with:
issue-number: ${{ github.event.number }}
body-includes: E2E Test Results
- name: Create report and post on PR
uses: peter-evans/create-or-update-comment@v3
with:
comment-id: ${{ steps.find-comment.outputs.comment-id }}
issue-number: ${{ github.event.number }}
body-path: cypress/reports/test_results.md
edit-mode: replace