-
Notifications
You must be signed in to change notification settings - Fork 2
477 lines (444 loc) · 17.4 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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
name: Pull Request
on:
pull_request:
types:
- opened
- synchronize
branches-ignore:
- production
env:
DOMAIN: planx.pizza
FULL_DOMAIN: ${{ github.event.number }}.planx.pizza
PULLREQUEST_ID: ${{ github.event.number }}
EDITOR_DIRECTORY: editor.planx.uk
permissions:
pull-requests: write
packages: read
jobs:
changes:
name: Check file changes
runs-on: ubuntu-22.04
permissions:
pull-requests: read
outputs:
api: ${{ steps.filter.outputs.api }}
e2e: ${{ steps.filter.outputs.e2e }}
editor: ${{ steps.filter.outputs.editor }}
hasura: ${{ steps.filter.outputs.hasura }}
infrastructure: ${{ steps.filter.outputs.infrastructure }}
sharedb: ${{ steps.filter.outputs.sharedb }}
commit: ${{ steps.commit.outputs.commit }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Get commit message
id: commit
run: |
echo "commit=$(git show -s --format=%s)" >> $GITHUB_OUTPUT
- uses: dorny/paths-filter@v2
id: filter
with:
filters: |
api:
- 'api.planx.uk/**'
e2e:
- 'e2e/**'
hasura:
- 'hasura.planx.uk/**'
infrastructure:
- 'infrastructure/**'
editor:
- 'editor.planx.uk/**'
sharedb:
- 'sharedb.planx.uk/**'
integration_tests:
name: Run Integration tests
runs-on: ubuntu-22.04
needs: [changes]
if: ${{ needs.changes.outputs.api == 'true' || needs.changes.outputs.e2e == 'true' || needs.changes.outputs.editor == 'true' || needs.changes.outputs.sharedb == 'true' || needs.changes.outputs.hasura == 'true' }}
steps:
- uses: actions/checkout@v4
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v3
with:
aws-access-key-id: ${{ secrets.PIZZA_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.PIZZA_AWS_SECRET_ACCESS_KEY }}
aws-region: eu-west-2
- name: Copy .env files from Staging S3 to the current working directory with AWS CLI
run: ./scripts/pull-secrets.sh
- name: Check if .env files exist
id: check_files
uses: andstor/file-existence-action@v2
with:
files: ".env, .env.staging, api.planx.uk/.env.test, hasura.planx.uk/.env.test"
fail: true
- name: Setup .gitconfig
run: mv .gitconfig ~/.gitconfig
- uses: pnpm/[email protected]
with:
version: ${{ vars.PNPM_VERSION }}
- uses: actions/setup-node@v3
with:
node-version: ${{ vars.NODE_VERSION }}
cache: "pnpm"
cache-dependency-path: "**/pnpm-lock.yaml"
- run: pnpm install --frozen-lockfile
working-directory: ${{ env.EDITOR_DIRECTORY }}
- name: Start test containers
run: ./scripts/start-containers-for-tests.sh
- name: Postgres Tests
run: ./hasura.planx.uk/run-postgres-tests.sh
- run: pnpm i -g hasura-cli
- name: Hasura Tests
run: pnpm install --frozen-lockfile && pnpm test
working-directory: hasura.planx.uk/tests
api_tests:
name: Run API Tests
runs-on: ubuntu-22.04
timeout-minutes: 10
needs: [changes]
if: ${{ needs.changes.outputs.api == 'true' }}
steps:
- uses: actions/checkout@v4
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v3
with:
aws-access-key-id: ${{ secrets.PIZZA_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.PIZZA_AWS_SECRET_ACCESS_KEY }}
aws-region: eu-west-2
- name: Copy .env files from Staging S3 to the current working directory with AWS CLI
run: ./scripts/pull-secrets.sh
- name: Check if .env files exist
id: check_files
uses: andstor/file-existence-action@v2
with:
files: ".env, .env.staging, api.planx.uk/.env.test, hasura.planx.uk/.env.test"
fail: true
- name: Setup .gitconfig
run: mv .gitconfig ~/.gitconfig
- uses: pnpm/[email protected]
with:
version: ${{ vars.PNPM_VERSION }}
- uses: actions/setup-node@v3
with:
node-version: ${{ vars.NODE_VERSION }}
cache: "pnpm"
cache-dependency-path: "**/pnpm-lock.yaml"
- name: Install dependencies
run: pnpm install --frozen-lockfile
working-directory: api.planx.uk
- name: Run API Tests
run: pnpm install --frozen-lockfile && pnpm check && pnpm test
working-directory: api.planx.uk
test_react:
name: Run React Tests
runs-on: ubuntu-22.04
needs: [changes]
if: ${{ needs.changes.outputs.editor == 'true' }}
steps:
- uses: actions/checkout@v4
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v3
with:
aws-access-key-id: ${{ secrets.PIZZA_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.PIZZA_AWS_SECRET_ACCESS_KEY }}
aws-region: eu-west-2
- name: Copy .env files from Staging S3 to the current working directory with AWS CLI
run: ./scripts/pull-secrets.sh
- name: Check if .env files exist
id: check_files
uses: andstor/file-existence-action@v2
with:
files: ".env, .env.staging, api.planx.uk/.env.test, hasura.planx.uk/.env.test"
fail: true
- uses: pnpm/[email protected]
with:
version: ${{ vars.PNPM_VERSION }}
- uses: actions/setup-node@v3
with:
node-version: ${{ vars.NODE_VERSION }}
cache: "pnpm"
cache-dependency-path: "**/pnpm-lock.yaml"
- name: Setup .gitconfig
run: mv .gitconfig ~/.gitconfig
- run: pnpm install --frozen-lockfile
working-directory: ${{ env.EDITOR_DIRECTORY }}
- run: pnpm build
working-directory: ${{ env.EDITOR_DIRECTORY }}
- run: pnpm test
working-directory: ${{ env.EDITOR_DIRECTORY }}
build_react_app:
name: Build React App
runs-on: ubuntu-22.04
needs: [changes]
if: "${{ !contains(needs.changes.outputs.commit, '[skip pizza]') }}"
steps:
- uses: actions/checkout@v4
- name: Cache build assets
id: cache-react-build-assets
uses: actions/cache@v3
with:
path: ./${{ env.EDITOR_DIRECTORY }}/build
key: ${{ runner.os }}-${{ hashFiles('editor.planx.uk/**') }}
- uses: pnpm/[email protected]
if: steps.cache-react-build-assets.outputs.cache-hit != 'true'
with:
version: ${{ vars.PNPM_VERSION }}
- uses: actions/setup-node@v3
if: steps.cache-react-build-assets.outputs.cache-hit != 'true'
with:
node-version: ${{ vars.NODE_VERSION }}
cache: "pnpm"
cache-dependency-path: "**/pnpm-lock.yaml"
- name: Setup .gitconfig
run: mv .gitconfig ~/.gitconfig
- run: pnpm install --frozen-lockfile
if: steps.cache-react-build-assets.outputs.cache-hit != 'true'
working-directory: ${{ env.EDITOR_DIRECTORY }}
- run: pnpm build
if: steps.cache-react-build-assets.outputs.cache-hit != 'true'
env:
REACT_APP_AIRBRAKE_PROJECT_ID: ${{ secrets.AIRBRAKE_PROJECT_ID }}
REACT_APP_AIRBRAKE_PROJECT_KEY: ${{ secrets.AIRBRAKE_PROJECT_KEY }}
REACT_APP_API_URL: https://api.${{ env.FULL_DOMAIN }}
REACT_APP_FEEDBACK_FISH_ID: 65f02de00b90d1
REACT_APP_HASURA_URL: https://hasura.${{ env.FULL_DOMAIN }}/v1/graphql
REACT_APP_SHAREDB_URL: wss://sharedb.${{ env.FULL_DOMAIN }}
# needed because there's no API to change google's allowed OAuth URLs
REACT_APP_GOOGLE_OAUTH_OVERRIDE: https://api.editor.planx.dev
REACT_APP_ENV: pizza
working-directory: ${{ env.EDITOR_DIRECTORY }}
- run: pnpm build-storybook
if: steps.cache-react-build-assets.outputs.cache-hit != 'true'
working-directory: ${{ env.EDITOR_DIRECTORY }}
env:
# same env as above, if it's job.env it can't access existing env.[variable]
REACT_APP_AIRBRAKE_PROJECT_ID: ${{ secrets.AIRBRAKE_PROJECT_ID }}
REACT_APP_AIRBRAKE_PROJECT_KEY: ${{ secrets.AIRBRAKE_PROJECT_KEY }}
REACT_APP_API_URL: https://api.${{ env.FULL_DOMAIN }}
REACT_APP_FEEDBACK_FISH_ID: 65f02de00b90d1
REACT_APP_HASURA_URL: https://hasura.${{ env.FULL_DOMAIN }}/v1/graphql
REACT_APP_SHAREDB_URL: wss://sharedb.${{ env.FULL_DOMAIN }}
REACT_APP_GOOGLE_OAUTH_OVERRIDE: https://api.editor.planx.dev
REACT_APP_ENV: pizza
pulumi_preview:
name: Run Pulumi Preview
runs-on: ubuntu-22.04
needs: [changes, build_react_app]
if: ${{ needs.changes.outputs.infrastructure == 'true' }}
steps:
- uses: actions/checkout@v4
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v3
with:
aws-access-key-id: ${{ secrets.STAGING_AWS_ACCESS_KEY_ID }}
aws-region: eu-west-2
aws-secret-access-key: ${{ secrets.STAGING_AWS_SECRET_ACCESS_KEY }}
- uses: pnpm/[email protected]
with:
version: ${{ vars.PNPM_VERSION }}
- uses: actions/setup-node@v3
with:
node-version: ${{ vars.NODE_VERSION }}
cache: "pnpm"
cache-dependency-path: "**/pnpm-lock.yaml"
- run: pnpm install --frozen-lockfile
working-directory: infrastructure/application
- name: Download React build assets
id: cache-react-build-assets
uses: actions/cache@v3
with:
path: ./${{ env.EDITOR_DIRECTORY }}/build
key: ${{ runner.os }}-${{ hashFiles('editor.planx.uk/**', '!editor.planx/build/**') }}
- uses: pulumi/actions@v4
with:
command: preview
stack-name: staging
work-dir: infrastructure/application
edit-pr-comment: true
env:
PULUMI_ACCESS_TOKEN: ${{ secrets.PULUMI_ACCESS_TOKEN }}
hasura-change-summary:
name: Generate Hasura Change Summary
runs-on: ubuntu-22.04
needs: [changes]
if: ${{ needs.changes.outputs.hasura == 'true' }}
steps:
- uses: actions/checkout@v4
- uses: Fieldguide/action-hasura-change-summary@v2
id: hasura-change
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
hasura_endpoint: https://hasura.${{ env.FULL_DOMAIN }}
project_dir: ./hasura.planx.uk
- uses: marocchino/sticky-pull-request-comment@v2
if: ${{steps.hasura-change.outputs.change_html != ''}}
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
header: hasura-change-summary
message: ${{ steps.hasura-change.outputs.change_html }}
- uses: marocchino/sticky-pull-request-comment@v2
if: ${{ steps.hasura-change.outputs.change_html == '' }}
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
header: hasura-change-summary
delete: true
create_or_update_vultr_instance:
name: Upsert Vultr Instance
needs: [changes, build_react_app]
runs-on: ubuntu-22.04
if: "${{ success() && !contains(needs.changes.outputs.commit, '[skip pizza]') }}"
steps:
- name: Create Pizza (if it doesn't exist)
id: create
uses: theopensystemslab/[email protected]
with:
action: create
api_key: ${{ secrets.VULTR_API_KEY }}
domain: ${{ env.DOMAIN }}
os_id: 1743
plan: vc2-1c-1gb
pullrequest_id: ${{ env.PULLREQUEST_ID }}
region: lhr
tag: pullrequest
# CREATE STEPS
- if: steps.create.outputs.ip_address != null
name: Create commands
uses: appleboy/ssh-action@master
with:
host: ${{ env.FULL_DOMAIN }}
username: root
password: ${{ steps.create.outputs.default_password }}
command_timeout: 20m
script: |
apt-get update -y
git clone "${{ secrets.AUTHENTICATED_REPO_URL }}"
cd planx-new
git fetch origin "pull/${{ env.PULLREQUEST_ID }}/head" && git checkout FETCH_HEAD
apt-get install awscli -y
export AWS_ACCESS_KEY_ID=${{ secrets.PIZZA_AWS_ACCESS_KEY_ID }}
export AWS_SECRET_ACCESS_KEY=${{ secrets.PIZZA_AWS_SECRET_ACCESS_KEY }}
export AWS_REGION=eu-west-2
CI=true ./scripts/pull-secrets.sh
echo -e "\nROOT_DOMAIN=${{ env.FULL_DOMAIN }}\n" > .env.temp
cat .env .env.temp .env.staging > .env.pizza
SSH_PASSWORD=${{ secrets.SSH_PASSWORD }} ./scripts/pullrequest/create.sh
# UPDATE STEPS
- if: steps.create.outputs.ip_address == null
name: Update commands
uses: appleboy/ssh-action@master
with:
host: ${{ env.FULL_DOMAIN }}
username: root
password: ${{ secrets.SSH_PASSWORD }}
command_timeout: 10m
script: |
apt-get update -y
git clone "${{ secrets.AUTHENTICATED_REPO_URL }}"
cd planx-new
git add . && git stash
git fetch origin "pull/${{ env.PULLREQUEST_ID }}/head" && git checkout FETCH_HEAD
apt-get install awscli -y
export AWS_ACCESS_KEY_ID=${{ secrets.PIZZA_AWS_ACCESS_KEY_ID }}
export AWS_SECRET_ACCESS_KEY=${{ secrets.PIZZA_AWS_SECRET_ACCESS_KEY }}
export AWS_REGION=eu-west-2
CI=true ./scripts/pull-secrets.sh
echo -e "\nROOT_DOMAIN=${{ env.FULL_DOMAIN }}\n" > .env.temp
cat .env .env.temp .env.staging > .env.pizza
./scripts/pullrequest/update.sh
# CREATE & UPDATE STEPS
- uses: actions/checkout@v4
- name: Download React build assets
id: cache-react-build-assets
uses: actions/cache@v3
with:
path: ./${{ env.EDITOR_DIRECTORY }}/build
key: ${{ runner.os }}-${{ hashFiles('editor.planx.uk/**', '!editor.planx/build/**') }}
- name: upload built editor
uses: appleboy/scp-action@master
with:
host: ${{ env.FULL_DOMAIN }}
username: root
password: ${{ secrets.SSH_PASSWORD }}
source: "./${{ env.EDITOR_DIRECTORY }}/build"
target: "planx-new/"
overwrite: true
- uses: marocchino/sticky-pull-request-comment@v2
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
header: vultr
message: |
## Pizza
Deployed ${{ github.sha }} to https://${{ env.FULL_DOMAIN }}.
Useful links:
- [Editor](https://${{ env.FULL_DOMAIN }})
- [Storybook](https://storybook.${{ env.FULL_DOMAIN }})
- [Hasura](https://hasura.${{ env.FULL_DOMAIN }})
- [API](https://api.${{ env.FULL_DOMAIN }})
- [ShareDB](https://sharedb.${{ env.FULL_DOMAIN }})
healthcheck:
name: Run Healthcheck on Pizza Services
needs: [create_or_update_vultr_instance]
runs-on: ubuntu-22.04
steps:
- name: Wait for Vultr to warm up
run: bash -c "sleep 30s"
- name: API healthcheck
run: |
timeout 150s bash -c "until curl --fail https://api.${{ env.FULL_DOMAIN }}; do sleep 1; done"
- name: Hasura healthcheck
run: |
timeout 150s bash -c "until curl --fail https://hasura.${{ env.FULL_DOMAIN }}/healthz; do sleep 1; done"
- name: Editor healthcheck
run: |
timeout 150s bash -c "until curl --fail https://${{ env.FULL_DOMAIN }}; do sleep 1; done"
end_to_end_tests:
name: E2E tests
runs-on: ubuntu-22.04
needs: [changes]
if: ${{ needs.changes.outputs.api == 'true' || needs.changes.outputs.e2e == 'true' || needs.changes.outputs.editor == 'true' || needs.changes.outputs.sharedb == 'true' || needs.changes.outputs.hasura == 'true' }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v3
with:
aws-access-key-id: ${{ secrets.PIZZA_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.PIZZA_AWS_SECRET_ACCESS_KEY }}
aws-region: eu-west-2
- name: Copy .env files from Staging S3 to the current working directory with AWS CLI
run: ./scripts/pull-secrets.sh
- name: Setup PNPM
uses: pnpm/[email protected]
with:
version: ${{ vars.PNPM_VERSION }}
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: ${{ vars.NODE_VERSION }}
cache: "pnpm"
cache-dependency-path: "**/pnpm-lock.yaml"
- name: Setup .gitconfig
run: mv .gitconfig ~/.gitconfig
- name: PNPM Install
run: pnpm install --frozen-lockfile
working-directory: e2e
- name: Code checks
run: pnpm check
working-directory: e2e
- name: Install Playwright Dependencies
run: pnpm playwright install --with-deps
working-directory: e2e/tests/ui-driven
- name: Start test containers
run: ./scripts/start-containers-for-tests.sh
- name: End-to-end Tests
run: pnpm test
working-directory: e2e
- name: Archive Playwright Test Results
if: ${{ failure() }}
uses: actions/upload-artifact@v3
with:
name: playwright-report
path: e2e/tests/ui-driven/test-results/
retention-days: 3