-
-
Notifications
You must be signed in to change notification settings - Fork 206
340 lines (293 loc) · 10.5 KB
/
pull_request.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
name: Pull Request
on:
pull_request:
branches: [master]
paths-ignore:
- 'tools/bumblebee/**'
concurrency:
group: pr_${{ github.head_ref }}
cancel-in-progress: true
jobs:
pr_lint:
name: Lint and Format
runs-on: ubuntu-latest
steps:
- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
node-version: '20'
- name: Checkout
uses: actions/checkout@v3
- name: Install dependencies
uses: bahmutov/npm-install@v1
- name: Format & Lint (npm run lint && npm run ci:format)
run: |
npm run ci:format
npm run lint
pr_test:
name: Test
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
node-version: '20'
- name: Checkout
uses: actions/checkout@v3
- name: Install dependencies
uses: bahmutov/npm-install@v1
- name: Test (client)
run: npm run test:ci
working-directory: client
- name: Test (server)
run: npm run test:ci
if: success() || failure()
working-directory: server
- name: Test (nestjs)
run: npm run test:ci
if: success() || failure()
working-directory: nestjs
- name: Upload test report (client)
uses: actions/upload-artifact@v3
if: success() || failure()
with:
name: test-report-client
path: reports/jest-junit-client.xml
- name: Upload test report (server)
uses: actions/upload-artifact@v3
if: success() || failure()
with:
name: test-report-server
path: reports/jest-junit-server.xml
- name: Upload test report (nestjs)
uses: actions/upload-artifact@v3
if: success() || failure()
with:
name: test-report-nestjs
path: reports/jest-junit-nestjs.xml
pr_build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
node-version: '20'
- name: Checkout
uses: actions/checkout@v3
- name: Restore next cache
uses: actions/cache@v3
env:
cache-name: cache-next
with:
path: |
client/.next/cache
key: ${{ runner.os }}-${{ env.cache-name }}-${{ github.ref_name }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-${{ env.cache-name }}-${{ github.ref_name }}
- name: Restore Docker layers
uses: actions/cache@v3
if: ${{ contains(github.event.pull_request.labels.*.name, 'deploy') }}
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-single-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-single-buildx
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
if: ${{ contains(github.event.pull_request.labels.*.name, 'deploy') }}
with:
platforms: linux/amd64
- name: Login to ECR
uses: docker/login-action@v1
if: ${{ contains(github.event.pull_request.labels.*.name, 'deploy') }}
with:
registry: 511361162520.dkr.ecr.eu-central-1.amazonaws.com
username: ${{ secrets.AWS_ACCESS_KEY_ID }}
password: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
- name: Install dependencies
uses: bahmutov/npm-install@v1
env:
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 'true'
- name: Build (npm run build)
env:
AWS_LAMBDA: 'true'
NODE_ENV: production
RSSHCOOL_UI_GCP_MAPS_API_KEY: ${{ secrets.RSSHCOOL_UI_GCP_MAPS_API_KEY }}
run: |
npm run build
- name: Prepare
working-directory: ./setup/cdk
if: ${{ contains(github.event.pull_request.labels.*.name, 'deploy') }}
run: |
mkdir -p /tmp/.buildx-cache
mkdir -p /tmp/.buildx-cache-new
- name: Upload to CDN
if: ${{ contains(github.event.pull_request.labels.*.name, 'deploy') }}
working-directory: ./client
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: eu-central-1
run: |
aws s3 cp .next/static s3://cdn.rs.school/_next/static/ --recursive --cache-control "public,max-age=15552000,immutable"
- name: Build client lambda
if: ${{ contains(github.event.pull_request.labels.*.name, 'deploy') }}
working-directory: ./client
run: npm run build:lambda
- name: Package Client
uses: docker/build-push-action@v3
if: ${{ contains(github.event.pull_request.labels.*.name, 'deploy') }}
with:
platforms: linux/amd64
provenance: false
context: .
file: ./client/Dockerfile.lambda
push: true
tags: 511361162520.dkr.ecr.eu-central-1.amazonaws.com/rsschool-ui:pr${{ github.event.pull_request.number }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
- name: Pull AWS SSM Params
uses: deptno/[email protected]
if: ${{ contains(github.event.pull_request.labels.*.name, 'deploy') }}
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: eu-central-1
with:
ssm-path: /staging/app
format: dotenv
output: server/.env
- name: Package Server
uses: docker/build-push-action@v3
if: ${{ contains(github.event.pull_request.labels.*.name, 'deploy') }}
with:
platforms: linux/amd64
provenance: false
context: .
file: ./server/Dockerfile.lambda
push: true
tags: 511361162520.dkr.ecr.eu-central-1.amazonaws.com/rsschool-server:pr${{ github.event.pull_request.number }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
- name: Pull AWS SSM Params
uses: deptno/[email protected]
if: ${{ contains(github.event.pull_request.labels.*.name, 'deploy') }}
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: eu-central-1
with:
ssm-path: /staging/app
format: dotenv
output: nestjs/.env
- name: Package Nestjs
uses: docker/build-push-action@v3
if: ${{ contains(github.event.pull_request.labels.*.name, 'deploy') }}
with:
platforms: linux/amd64
provenance: false
context: .
file: ./nestjs/Dockerfile.lambda
push: true
tags: 511361162520.dkr.ecr.eu-central-1.amazonaws.com/rsschool-nestjs:pr${{ github.event.pull_request.number }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
- name: Move cache
if: ${{ contains(github.event.pull_request.labels.*.name, 'deploy') }}
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
pr_deploy:
needs: [pr_build]
name: Deploy
timeout-minutes: 60
runs-on: ubuntu-latest
if: ${{ contains(github.event.pull_request.labels.*.name, 'deploy') }}
steps:
- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
node-version: '20'
- name: Checkout
uses: actions/checkout@v3
- name: Restore npm cache
uses: actions/cache@v3
env:
cache-name: cache-npm
with:
path: ~/.npm
key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('**/package.json') }}
restore-keys: |
${{ runner.os }}-${{ env.cache-name }}-
${{ runner.os }}-
- name: Install dependencies
working-directory: ./setup/cdk
run: npm ci
- name: Deploy
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: eu-central-1
working-directory: ./setup/cdk
run: |
npx cdk deploy --require-approval never -c feature=pr${{ github.event.pull_request.number }} -c deployId=${GITHUB_RUN_ID}
- name: Create GitHub deployment
uses: apalchys/[email protected]
id: deployment
with:
ref: ${{ github.event.pull_request.head.ref }}
pr: true
pr_id: ${{ github.event.pull_request.number }}
token: ${{ secrets.GITHUB_TOKEN }}
target_url: https://pr${{ github.event.pull_request.number }}.app.rs.school
environment: pr${{ github.event.pull_request.number }}
initial_status: success
pr_e2e:
needs: [pr_deploy]
name: End-to-End Tests
timeout-minutes: 10
runs-on: ubuntu-latest
if: ${{ contains(github.event.pull_request.labels.*.name, 'deploy') }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
node-version: '20'
- name: Restore npm cache
uses: actions/cache@v3
env:
cache-name: cache-npm
with:
path: ~/.npm
key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('**/package.json') }}
restore-keys: |
${{ runner.os }}-${{ env.cache-name }}-
${{ runner.os }}-
- name: Restore browsers cache
uses: actions/cache@v3
with:
path: '~/.cache/ms-playwright/'
key: ${{ runner.os }}-browsers
- name: Install Dependencies
working-directory: ./client
run: npm ci
- name: Install Playwright
working-directory: ./client
run: npx playwright install --with-deps
- name: Run Playwright tests
working-directory: ./client
env:
CI: 'true'
BASE_URL: https://pr${{ github.event.pull_request.number }}.app.rs.school
run: npx playwright test
- name: Save Report
uses: actions/upload-artifact@v3
if: always()
with:
name: playwright-report
path: client/playwright-report/
retention-days: 15