-
Notifications
You must be signed in to change notification settings - Fork 6
593 lines (591 loc) · 20.7 KB
/
pr.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
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
name: PR
on:
pull_request:
branches:
- main
types:
- opened
- reopened
- synchronize
jobs:
compile:
name: Install deps and compile
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- id: setup-beam
name: Set up Elixir
uses: erlef/setup-beam@v1
with:
version-file: .tool-versions
version-type: strict
- uses: actions/cache@v3
with:
path: |
_build
deps
key: ${{ runner.os }}-${{ steps.setup-beam.outputs.elixir-version }}-${{ steps.setup-beam.outputs.otp-version }}-mix-${{ github.sha }}
restore-keys: |
${{ runner.os }}-${{ steps.setup-beam.outputs.elixir-version }}-${{ steps.setup-beam.outputs.otp-version }}-mix-
- name: Install Elixir dependencies
env:
MIX_ENV: test
run: mix deps.get
- name: Compile
env:
MIX_ENV: test
run: mix compile
credo:
needs: compile
name: Credo
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- id: setup-beam
name: Set up Elixir
uses: erlef/setup-beam@v1
with:
version-file: .tool-versions
version-type: strict
- uses: actions/cache@v3
with:
path: |
_build
deps
key: ${{ runner.os }}-${{ steps.setup-beam.outputs.elixir-version }}-${{ steps.setup-beam.outputs.otp-version }}-mix-${{ github.sha }}
restore-keys: |
${{ runner.os }}-${{ steps.setup-beam.outputs.elixir-version }}-${{ steps.setup-beam.outputs.otp-version }}-mix-
- name: Check code style
env:
MIX_ENV: test
run: mix credo --strict
deps_audit:
needs: compile
name: Deps audit
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- id: setup-beam
name: Set up Elixir
uses: erlef/setup-beam@v1
with:
version-file: .tool-versions
version-type: strict
- uses: actions/cache@v3
with:
path: |
_build
deps
key: ${{ runner.os }}-${{ steps.setup-beam.outputs.elixir-version }}-${{ steps.setup-beam.outputs.otp-version }}-mix-${{ github.sha }}
restore-keys: |
${{ runner.os }}-${{ steps.setup-beam.outputs.elixir-version }}-${{ steps.setup-beam.outputs.otp-version }}-mix-
- name: Check for vulnerable Mix dependencies
env:
MIX_ENV: test
run: mix deps.audit
dialyzer:
needs: compile
name: Dialyzer
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- id: setup-beam
name: Set up Elixir
uses: erlef/setup-beam@v1
with:
version-file: .tool-versions
version-type: strict
- uses: actions/cache@v3
with:
path: |
_build
deps
key: ${{ runner.os }}-${{ steps.setup-beam.outputs.elixir-version }}-${{ steps.setup-beam.outputs.otp-version }}-mix-${{ github.sha }}
restore-keys: |
${{ runner.os }}-${{ steps.setup-beam.outputs.elixir-version }}-${{ steps.setup-beam.outputs.otp-version }}-mix-
- name: Restore PLT cache
uses: actions/cache@v3
with:
path: priv/plts
key: ${{ runner.os }}-${{ steps.setup-beam.outputs.elixir-version }}-${{ steps.setup-beam.outputs.otp-version }}-plt-${{ github.sha }}
restore-keys: |
${{ runner.os }}-${{ steps.setup-beam.outputs.elixir-version }}-${{ steps.setup-beam.outputs.otp-version }}-plt-
- name: Create PLTs
env:
MIX_ENV: test
run: mix dialyzer --plt
- name: Run dialyzer
env:
MIX_ENV: test
run: mix dialyzer
format:
needs: compile
name: Format
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- id: setup-beam
name: Set up Elixir
uses: erlef/setup-beam@v1
with:
version-file: .tool-versions
version-type: strict
- uses: actions/cache@v3
with:
path: |
_build
deps
key: ${{ runner.os }}-${{ steps.setup-beam.outputs.elixir-version }}-${{ steps.setup-beam.outputs.otp-version }}-mix-${{ github.sha }}
restore-keys: |
${{ runner.os }}-${{ steps.setup-beam.outputs.elixir-version }}-${{ steps.setup-beam.outputs.otp-version }}-mix-
- name: Check Elixir formatting
env:
MIX_ENV: test
run: mix format --check-formatted
hex_audit:
needs: compile
name: Hex audit
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- id: setup-beam
name: Set up Elixir
uses: erlef/setup-beam@v1
with:
version-file: .tool-versions
version-type: strict
- uses: actions/cache@v3
with:
path: |
_build
deps
key: ${{ runner.os }}-${{ steps.setup-beam.outputs.elixir-version }}-${{ steps.setup-beam.outputs.otp-version }}-mix-${{ github.sha }}
restore-keys: |
${{ runner.os }}-${{ steps.setup-beam.outputs.elixir-version }}-${{ steps.setup-beam.outputs.otp-version }}-mix-
- name: Check for retired Hex packages
env:
MIX_ENV: test
run: mix hex.audit
prettier:
name: Check formatting using Prettier
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Restore npm cache
uses: actions/cache@v3
id: npm-cache
with:
path: node_modules
key: ${{ runner.os }}-prettier
- name: Install Prettier
if: steps.npm-cache.outputs.cache-hit != 'true'
run: npm i -D prettier prettier-plugin-toml
- name: Run Prettier
run: npx prettier -c .
sobelow:
needs: compile
name: Security check
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- id: setup-beam
name: Set up Elixir
uses: erlef/setup-beam@v1
with:
version-file: .tool-versions
version-type: strict
- uses: actions/cache@v3
with:
path: |
_build
deps
key: ${{ runner.os }}-${{ steps.setup-beam.outputs.elixir-version }}-${{ steps.setup-beam.outputs.otp-version }}-mix-${{ github.sha }}
restore-keys: |
${{ runner.os }}-${{ steps.setup-beam.outputs.elixir-version }}-${{ steps.setup-beam.outputs.otp-version }}-mix-
- name: Check for security issues using sobelow
env:
MIX_ENV: test
run: mix sobelow --config .sobelow-conf
test:
needs: compile
name: Test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- id: setup-beam
name: Set up Elixir
uses: erlef/setup-beam@v1
with:
version-file: .tool-versions
version-type: strict
- uses: actions/cache@v3
with:
path: |
_build
deps
key: ${{ runner.os }}-${{ steps.setup-beam.outputs.elixir-version }}-${{ steps.setup-beam.outputs.otp-version }}-mix-${{ github.sha }}
restore-keys: |
${{ runner.os }}-${{ steps.setup-beam.outputs.elixir-version }}-${{ steps.setup-beam.outputs.otp-version }}-mix-
- name: Run tests
env:
MIX_ENV: test
run: mix test --cover --warnings-as-errors
unused_deps:
needs: compile
name: Check unused deps
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- id: setup-beam
name: Set up Elixir
uses: erlef/setup-beam@v1
with:
version-file: .tool-versions
version-type: strict
- uses: actions/cache@v3
with:
path: |
_build
deps
key: ${{ runner.os }}-${{ steps.setup-beam.outputs.elixir-version }}-${{ steps.setup-beam.outputs.otp-version }}-mix-${{ github.sha }}
restore-keys: |
${{ runner.os }}-${{ steps.setup-beam.outputs.elixir-version }}-${{ steps.setup-beam.outputs.otp-version }}-mix-
- name: Check for unused Mix dependencies
env:
MIX_ENV: test
run: mix deps.unlock --check-unused
test_linux_bash:
name: Test Linux script with bash shell
runs-on: ubuntu-latest
env:
SHELL: bash
TZ: America/New_York
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Restore script result cache
uses: actions/cache@v3
id: result_cache
with:
key: ${{ runner.os }}-bash-script-${{ hashFiles('test/scripts/script.exp') }}-${{ hashFiles('priv/script.sh') }}
path: priv/script.sh
- name: Install expect tool
if: steps.result_cache.outputs.cache-hit != 'true'
run: sudo apt-get update && sudo apt-get install -y expect
- name: Remove mise config files
run: rm -f .mise.toml .tool-versions
- name: Test the script
if: steps.result_cache.outputs.cache-hit != 'true'
run: cd test/scripts && expect script.exp
shell: bash -l {0}
- name: Generate an app and start the server
if: steps.result_cache.outputs.cache-hit != 'true'
run: make -f test/scripts/Makefile serve
shell: bash -l {0}
- name: Check HTTP status code
if: steps.result_cache.outputs.cache-hit != 'true'
uses: nick-fields/retry@v2
with:
command: INPUT_SITES='["http://localhost:4000"]' INPUT_EXPECTED='[200]' ./test/scripts/check_status_code.sh
max_attempts: 7
retry_wait_seconds: 5
timeout_seconds: 1
test_macos_bash:
name: Test macOS script with bash shell
runs-on: macos-latest
env:
SHELL: bash
TZ: America/New_York
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Restore script result cache
uses: actions/cache@v3
id: result_cache
with:
key: ${{ runner.os }}-bash-script-${{ hashFiles('test/scripts/script.exp') }}-${{ hashFiles('priv/script.sh') }}
path: priv/script.sh
- name: Disable password prompt for macOS
if: steps.result_cache.outputs.cache-hit != 'true'
run: 'sudo sed -i "" "s/%admin ALL = (ALL) ALL/%admin ALL = (ALL) NOPASSWD: ALL/g" /etc/sudoers'
- name: Install expect tool
if: steps.result_cache.outputs.cache-hit != 'true'
run: brew install expect
- name: Remove mise config files
run: rm -f .mise.toml .tool-versions
- name: Test the script
if: steps.result_cache.outputs.cache-hit != 'true'
run: cd test/scripts && expect script.exp
shell: bash -l {0}
- name: Generate an app and start the server
if: steps.result_cache.outputs.cache-hit != 'true'
run: make -f test/scripts/Makefile serve
shell: bash -l {0}
- name: Check HTTP status code
if: steps.result_cache.outputs.cache-hit != 'true'
uses: nick-fields/retry@v2
with:
command: INPUT_SITES='["http://localhost:4000"]' INPUT_EXPECTED='[200]' ./test/scripts/check_status_code.sh
max_attempts: 7
retry_wait_seconds: 5
timeout_seconds: 1
test_linux_fish:
name: Test Linux script with fish shell
runs-on: ubuntu-latest
env:
SHELL: fish
TZ: America/New_York
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Restore script result cache
uses: actions/cache@v3
id: result_cache
with:
key: ${{ runner.os }}-fish-script-${{ hashFiles('test/scripts/script.exp') }}-${{ hashFiles('priv/script.sh') }}
path: priv/script.sh
- name: Install shell
if: steps.result_cache.outputs.cache-hit != 'true'
run: sudo apt-get update && sudo apt-get install -y fish
- name: Install expect tool
if: steps.result_cache.outputs.cache-hit != 'true'
run: sudo apt-get update && sudo apt-get install -y expect
- name: Remove mise config files
run: rm -f .mise.toml .tool-versions
- name: Test the script
if: steps.result_cache.outputs.cache-hit != 'true'
run: cd test/scripts && expect script.exp
shell: fish -l {0}
- name: Generate an app and start the server
if: steps.result_cache.outputs.cache-hit != 'true'
run: make -f test/scripts/Makefile serve
shell: fish -l {0}
- name: Check HTTP status code
if: steps.result_cache.outputs.cache-hit != 'true'
uses: nick-fields/retry@v2
with:
command: INPUT_SITES='["http://localhost:4000"]' INPUT_EXPECTED='[200]' ./test/scripts/check_status_code.sh
max_attempts: 7
retry_wait_seconds: 5
timeout_seconds: 1
test_macos_fish:
name: Test macOS script with fish shell
runs-on: macos-latest
env:
SHELL: fish
TZ: America/New_York
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Restore script result cache
uses: actions/cache@v3
id: result_cache
with:
key: ${{ runner.os }}-fish-script-${{ hashFiles('test/scripts/script.exp') }}-${{ hashFiles('priv/script.sh') }}
path: priv/script.sh
- name: Install shell
if: steps.result_cache.outputs.cache-hit != 'true'
run: brew install fish
- name: Disable password prompt for macOS
if: steps.result_cache.outputs.cache-hit != 'true'
run: 'sudo sed -i "" "s/%admin ALL = (ALL) ALL/%admin ALL = (ALL) NOPASSWD: ALL/g" /etc/sudoers'
- name: Install expect tool
if: steps.result_cache.outputs.cache-hit != 'true'
run: brew install expect
- name: Remove mise config files
run: rm -f .mise.toml .tool-versions
- name: Test the script
if: steps.result_cache.outputs.cache-hit != 'true'
run: cd test/scripts && expect script.exp
shell: fish -l {0}
- name: Generate an app and start the server
if: steps.result_cache.outputs.cache-hit != 'true'
run: make -f test/scripts/Makefile serve
shell: fish -l {0}
- name: Check HTTP status code
if: steps.result_cache.outputs.cache-hit != 'true'
uses: nick-fields/retry@v2
with:
command: INPUT_SITES='["http://localhost:4000"]' INPUT_EXPECTED='[200]' ./test/scripts/check_status_code.sh
max_attempts: 7
retry_wait_seconds: 5
timeout_seconds: 1
test_linux_zsh:
name: Test Linux script with zsh shell
runs-on: ubuntu-latest
env:
SHELL: zsh
TZ: America/New_York
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Restore script result cache
uses: actions/cache@v3
id: result_cache
with:
key: ${{ runner.os }}-zsh-script-${{ hashFiles('test/scripts/script.exp') }}-${{ hashFiles('priv/script.sh') }}
path: priv/script.sh
- name: Install shell
if: steps.result_cache.outputs.cache-hit != 'true'
run: sudo apt-get update && sudo apt-get install -y zsh
- name: Install expect tool
if: steps.result_cache.outputs.cache-hit != 'true'
run: sudo apt-get update && sudo apt-get install -y expect
- name: Remove mise config files
run: rm -f .mise.toml .tool-versions
- name: Test the script
if: steps.result_cache.outputs.cache-hit != 'true'
run: cd test/scripts && expect script.exp
shell: zsh -l {0}
- name: Generate an app and start the server
if: steps.result_cache.outputs.cache-hit != 'true'
run: make -f test/scripts/Makefile serve
shell: zsh -l {0}
- name: Check HTTP status code
if: steps.result_cache.outputs.cache-hit != 'true'
uses: nick-fields/retry@v2
with:
command: INPUT_SITES='["http://localhost:4000"]' INPUT_EXPECTED='[200]' ./test/scripts/check_status_code.sh
max_attempts: 7
retry_wait_seconds: 5
timeout_seconds: 1
test_macos_zsh:
name: Test macOS script with zsh shell
runs-on: macos-latest
env:
SHELL: zsh
TZ: America/New_York
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Restore script result cache
uses: actions/cache@v3
id: result_cache
with:
key: ${{ runner.os }}-zsh-script-${{ hashFiles('test/scripts/script.exp') }}-${{ hashFiles('priv/script.sh') }}
path: priv/script.sh
- name: Install shell
if: steps.result_cache.outputs.cache-hit != 'true'
run: brew install zsh
- name: Disable password prompt for macOS
if: steps.result_cache.outputs.cache-hit != 'true'
run: 'sudo sed -i "" "s/%admin ALL = (ALL) ALL/%admin ALL = (ALL) NOPASSWD: ALL/g" /etc/sudoers'
- name: Install expect tool
if: steps.result_cache.outputs.cache-hit != 'true'
run: brew install expect
- name: Remove mise config files
run: rm -f .mise.toml .tool-versions
- name: Test the script
if: steps.result_cache.outputs.cache-hit != 'true'
run: cd test/scripts && expect script.exp
shell: zsh -l {0}
- name: Generate an app and start the server
if: steps.result_cache.outputs.cache-hit != 'true'
run: make -f test/scripts/Makefile serve
shell: zsh -l {0}
- name: Check HTTP status code
if: steps.result_cache.outputs.cache-hit != 'true'
uses: nick-fields/retry@v2
with:
command: INPUT_SITES='["http://localhost:4000"]' INPUT_EXPECTED='[200]' ./test/scripts/check_status_code.sh
max_attempts: 7
retry_wait_seconds: 5
timeout_seconds: 1
test_wsl:
name: Test WSL script with wsl-bash shell
runs-on: windows-latest
env:
SHELL: wsl-bash
TZ: America/New_York
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup WSL
uses: Vampire/setup-wsl@v3
with:
distribution: Ubuntu-22.04
additional_packages: expect
wsl_shell_user: root
update: true
- name: Restore script result cache
uses: actions/cache@v3
id: result_cache
with:
key: ${{ runner.os }}-wsl-bash-script-${{ hashFiles('test/scripts/script.exp') }}-${{ hashFiles('priv/script.sh') }}
path: priv/script.sh
- name: Remove mise config files
run: wsl rm -f .mise.toml .tool-versions
- name: Test the script
if: steps.result_cache.outputs.cache-hit != 'true'
run: cd test/scripts && expect script.exp
shell: wsl-bash -l {0}
- name: Generate an app and start the server
if: steps.result_cache.outputs.cache-hit != 'true'
run: make -f test/scripts/Makefile serve
shell: wsl-bash -l {0}
- name: Check HTTP status code
if: steps.result_cache.outputs.cache-hit != 'true'
uses: nick-fields/retry@v2
with:
command: INPUT_SITES='["http://localhost:4000"]' INPUT_EXPECTED='[200]' ./test/scripts/check_status_code.sh
max_attempts: 7
retry_wait_seconds: 5
timeout_seconds: 1
deploy_preview_app:
name: Deploy preview app
needs:
- compile
- credo
- deps_audit
- dialyzer
- format
- hex_audit
- prettier
- sobelow
- test
- unused_deps
- test_linux_bash
- test_macos_bash
- test_linux_fish
- test_macos_fish
- test_linux_zsh
- test_macos_zsh
- test_wsl
runs-on: ubuntu-latest
permissions: write-all
concurrency:
group: pr-${{ github.event.number }}
environment:
name: pr-${{ github.event.number }}
url: https://phx-tools-pr-${{ github.event.number }}.fly.dev
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Delete previous deployments
uses: strumwolf/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
environment: pr-${{ github.event.number }}
ref: ${{ github.head_ref }}
onlyRemoveDeployments: true
- name: Deploy preview app
uses: optimumBA/fly-preview-apps@main
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
FLY_ORG: optimum-bh
FLY_REGION: fra
PHX_HOST: phx-tools-pr-${{ github.event.number }}.fly.dev
REPO_NAME: phx_tools
with:
name: phx-tools-pr-${{ github.event.number }}
secrets: APPSIGNAL_APP_ENV=preview APPSIGNAL_PUSH_API_KEY=${{ secrets.APPSIGNAL_PUSH_API_KEY }} PHX_HOST=${{ env.PHX_HOST }} SECRET_KEY_BASE=${{ secrets.SECRET_KEY_BASE }}