-
Notifications
You must be signed in to change notification settings - Fork 94
804 lines (731 loc) · 29.7 KB
/
code_checks.yml
File metadata and controls
804 lines (731 loc) · 29.7 KB
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
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
name: Code Checks
on:
push:
branches: [master]
pull_request:
types: [opened, reopened, synchronize]
permissions:
id-token: write
contents: read
checks: write
jobs:
compare_sha:
runs-on: ubuntu-latest
name: Compare sha
steps:
- name: Compare commit ids
run: |
echo "github.sha: ${{ github.sha }}"
echo "github.event.push.head_commit.id: ${{ github.event.push.head_commit.id }}"
echo "github.event.pull_request.merge_commit_sha: ${{ github.event.pull_request.merge_commit_sha }}"
echo "github.event.head_commit.id: ${{ github.event.head_commit.id }}"
linting_and_security:
name: Linting and Security
env:
BUNDLE_ENTERPRISE__CONTRIBSYS__COM: ${{ secrets.BUNDLE_ENTERPRISE__CONTRIBSYS__COM }}
permissions: write-all
runs-on: ubuntu-32-cores-latest
steps:
- name: Checkout PR
if: ${{ github.event_name != 'pull_request' }}
uses: actions/checkout@v6
- name: Checkout PR HEAD ref
if: ${{ github.event_name == 'pull_request' }}
uses: actions/checkout@v6
with:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 1
- name: Compute changed files for boundary check
if: ${{ github.event_name == 'pull_request' }}
run: |
git fetch --no-tags --depth=1 origin "${{ github.event.pull_request.base.sha }}"
git diff --name-only --diff-filter=ACMR "${{ github.event.pull_request.base.sha }}" HEAD > /tmp/changed-files.txt
- name: Check runtime does not depend on spec code
run: |
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
CHANGED_FILES_FILE=/tmp/changed-files.txt bash script/ci/check_runtime_spec_dependencies.sh
else
bash script/ci/check_runtime_spec_dependencies.sh
fi
- uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: Check for Gemfile changes
id: gemfile_changes
if: github.event_name == 'pull_request'
uses: tj-actions/changed-files@v47.0.4
with:
files: |
Gemfile
Gemfile.lock
modules/*/Gemfile
- name: Run bundle-audit (checks gems for CVE issues)
id: bundle_audit
if: |
(
github.ref == 'refs/heads/master' ||
(github.event_name == 'pull_request' && steps.gemfile_changes.outputs.any_changed == 'true')
)
continue-on-error: true
run: bundle exec bundle-audit check --update
- name: Configure AWS Credentials
if: steps.bundle_audit.outcome == 'failure'
uses: aws-actions/configure-aws-credentials@v6
with:
role-to-assume: ${{ vars.AWS_ASSUME_ROLE }}
aws-region: us-gov-west-1
- uses: department-of-veterans-affairs/action-inject-ssm-secrets@d8e6de3bde4dd728c9d732baef58b3c854b8c4bb
if: steps.bundle_audit.outcome == 'failure'
with:
ssm_parameter: /devops/VA_VSP_BOT_GITHUB_TOKEN
env_variable_name: VA_VSP_BOT_GITHUB_TOKEN
- name: Checkout VSP actions
if: steps.bundle_audit.outcome == 'failure'
uses: actions/checkout@v6
with:
repository: department-of-veterans-affairs/vsp-github-actions
ref: refs/heads/main
token: ${{ env.VA_VSP_BOT_GITHUB_TOKEN }}
persist-credentials: false
path: ./.github/actions/vsp-github-actions
- uses: department-of-veterans-affairs/action-inject-ssm-secrets@d8e6de3bde4dd728c9d732baef58b3c854b8c4bb
if: steps.bundle_audit.outcome == 'failure'
with:
ssm_parameter: /devops/github_actions_slack_socket_token
env_variable_name: SLACK_APP_TOKEN
- uses: department-of-veterans-affairs/action-inject-ssm-secrets@d8e6de3bde4dd728c9d732baef58b3c854b8c4bb
if: steps.bundle_audit.outcome == 'failure'
with:
ssm_parameter: /devops/github_actions_slack_bot_user_token
env_variable_name: SLACK_BOT_TOKEN
- name: Slack notify - bundle-audit CVE failure
if: |
steps.bundle_audit.outcome == 'failure' &&
(
github.ref == 'refs/heads/master' ||
(github.event_name == 'pull_request' && steps.gemfile_changes.outputs.any_changed == 'true')
)
uses: ./.github/actions/vsp-github-actions/slack-socket
with:
slack_app_token: ${{ env.SLACK_APP_TOKEN }}
slack_bot_token: ${{ env.SLACK_BOT_TOKEN }}
message: "Critical: Vets-API bundle-audit detected CVE vulnerabilities"
blocks: |
[
{ "type": "divider" },
{
"type": "header",
"text": {
"type": "plain_text",
"text": ":rotating_light: CRITICAL: CVE Vulnerability Detected",
"emoji": true
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*bundle-audit found gems with known CVE vulnerabilities in vets-api*"
}
},
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": ":x: *Status*: Build Failed"
},
{
"type": "mrkdwn",
"text": ":git: *Branch*: `${{ github.ref_name }}`"
}
]
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ":bust_in_silhouette: *Author:* ${{ github.actor }}"
}
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": ":mag_right: View Run",
"emoji": true
},
"url": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}",
"style": "danger"
}
]
},
{ "type": "divider" }
]
channel_id: "C0APA867M0V"
- name: Fail job if bundle-audit found CVEs
if: steps.bundle_audit.outcome == 'failure'
run: exit 1
- name: Run Rubocop
run: bundle exec rubocop --parallel --format github
- name: Run Brakeman
run: bundle exec brakeman --ensure-latest --confidence-level=2 --format github
- name: Run Reek
uses: reviewdog/action-reek@v1.20.0
with:
reek_version: gemfile
reporter: github-pr-review
reek_flags: --smell DuplicateMethodCall
# Note: this is the default anyway but explicitly set to remind us we can change to hard-fail on reek warnings with `any`
# For now we just want to run in advisory mode to surface architectural smells as comments during review
# ...but _without_ blocking merges for now
fail_level: none
# Always add the "lint-failure" label on failure and remove it on success
- name: Add Lint Failure label
if: ${{ failure() && github.event_name == 'pull_request' }}
uses: actions/github-script@v8
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const prNumber = context.payload.pull_request.number
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
labels: ['lint-failure'],
})
- name: Remove Lint Failure label
if: ${{ success() && github.event_name == 'pull_request' }}
uses: actions/github-script@v8
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const prNumber = context.payload.pull_request.number
try {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
name: 'lint-failure',
})
} catch (e) {
if (e.status !== 404) throw e
}
build:
name: Build and Cache Docker Image
runs-on: ubuntu-16-cores-latest
env:
BUNDLE_ENTERPRISE__CONTRIBSYS__COM: ${{ secrets.BUNDLE_ENTERPRISE__CONTRIBSYS__COM }}
DOCKER_BUILDKIT: 1
steps:
- name: Checkout PR
if: ${{ github.event_name != 'pull_request' }}
uses: actions/checkout@v6
- name: Checkout PR HEAD ref
if: ${{ github.event_name == 'pull_request' }}
uses: actions/checkout@v6
with:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 1
- name: Login to DockerHub
uses: docker/login-action@v4
with:
username: ${{ secrets.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v6
with:
role-to-assume: ${{ vars.AWS_ASSUME_ROLE }}
aws-region: us-gov-west-1
- name: Login to Amazon ECR
id: ecr-login
uses: aws-actions/amazon-ecr-login@v2.0.1
with:
mask-password: true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Build and Cache Docker Image
uses: docker/build-push-action@v7
env:
DOCKER_BUILD_SUMMARY: false
with:
build-args: |
BUNDLE_ENTERPRISE__CONTRIBSYS__COM=${{ env.BUNDLE_ENTERPRISE__CONTRIBSYS__COM }}
USER_ID=1001
context: .
push: false
load: false
tags: vets-api
outputs: type=docker,dest=/tmp/vets-api.tar
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Compress Docker image
run: zstd -T0 /tmp/vets-api.tar -o /tmp/vets-api.tar.zst
- name: Save Docker image to cache
uses: actions/cache/save@v4
with:
path: /tmp/vets-api.tar.zst
key: docker-image-${{ github.sha }}
tests:
name: Test (Group ${{ matrix.test_group }})
runs-on: ubuntu-16-cores-latest
permissions: write-all
needs: build
strategy:
fail-fast: false
matrix:
test_group: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24]
env:
BUNDLE_ENTERPRISE__CONTRIBSYS__COM: ${{ secrets.BUNDLE_ENTERPRISE__CONTRIBSYS__COM }}
ECR_REGISTRY_WITH_SLASH: "${{ secrets.ECR_REGISTRY }}/"
CI: true
RAILS_ENV: test
TERM: xterm-256color
DOCKER_BUILDKIT: 1
COMPOSE_DOCKER_CLI_BUILD: 1
COMPOSE_BASH_CMD: docker compose -f docker-compose.test.yml run web bash -c
steps:
- name: Checkout PR
if: ${{ github.event_name != 'pull_request' }}
uses: actions/checkout@v6
- name: Checkout PR HEAD ref
if: ${{ github.event_name == 'pull_request' }}
uses: actions/checkout@v6
with:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 1
- name: Login to DockerHub
uses: docker/login-action@v4
with:
username: ${{ secrets.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v6
with:
role-to-assume: ${{ vars.AWS_ASSUME_ROLE }}
aws-region: us-gov-west-1
- name: Login to Amazon ECR
id: ecr-login
uses: aws-actions/amazon-ecr-login@v2.0.1
with:
mask-password: true
- name: Restore Docker image from cache
uses: actions/cache/restore@v4
with:
path: /tmp/vets-api.tar.zst
key: docker-image-${{ github.sha }}
fail-on-cache-miss: true
- name: Load Docker image
run: zstd -d /tmp/vets-api.tar.zst --stdout | docker load
# Shard balancing: if a runtime log exists (cached from a previous run),
# parallel_test uses --group-by runtime to distribute specs by actual
# measured execution time. Otherwise it falls back to --group-by filesize.
# The runtime log is generated in publish_results from JUnit XML timing
# data and cached for subsequent runs.
#
# Cache key priority:
# 1. This branch's most recent run
# 2. master branch (so new PRs get balanced shards immediately)
# 3. Any previous run (catch-all fallback)
# If no cache exists at all (e.g. first-ever run), parallel_test uses
# filesize grouping automatically.
- name: Restore runtime log from cache
uses: actions/cache/restore@v4
with:
path: tmp/parallel_runtime_rspec.log
key: parallel-runtime-log-${{ github.ref }}-${{ github.run_id }}
restore-keys: |
parallel-runtime-log-${{ github.ref }}-
parallel-runtime-log-refs/heads/master-
parallel-runtime-log-
- name: Determine shard grouping strategy
id: grouping
run: |
if [ -s tmp/parallel_runtime_rspec.log ]; then
echo "strategy=runtime" >> $GITHUB_OUTPUT
echo "Runtime log found, using runtime-based shard balancing"
else
echo "strategy=filesize" >> $GITHUB_OUTPUT
echo "No runtime log found, falling back to filesize grouping"
fi
- name: Setup Database
uses: nick-fields/retry@ce71cc2ab81d554ebbe88c79ab5975992d79ba08 # v3.0.2
with:
timeout_minutes: 10
retry_wait_seconds: 3 # Seconds
max_attempts: 3
command: >
${{ env.COMPOSE_BASH_CMD }}
"bundle exec rails db:test:prepare"
- name: Setup system tmp dir
run: >
${{ env.COMPOSE_BASH_CMD }}
"mkdir -p tmp/systmp"
- name: Run Specs
timeout-minutes: 15
env:
TEST_ENV_NUMBER: ${{ matrix.test_group }}
run: >
${{ env.COMPOSE_BASH_CMD }}
"TEST_ENV_NUMBER=${{ matrix.test_group }} TMPDIR=tmp/systmp bundle exec parallel_test spec modules --group-by ${{ steps.grouping.outputs.strategy }} --type rspec --only-group ${{ matrix.test_group }} -n 24 -o '--profile 20'"
- name: Prepare SimpleCov shard payload
if: always()
run: |
mkdir -p simplecov-resultset-${{ matrix.test_group }}
if [ -f coverage/.resultset.json ]; then
mv coverage/.resultset.json simplecov-resultset-${{ matrix.test_group }}/.resultset.json
fi
- name: Upload SimpleCov raw resultset
if: always()
uses: actions/upload-artifact@v7
with:
name: simplecov-resultset-${{ matrix.test_group }}
path: simplecov-resultset-${{ matrix.test_group }}/.resultset.json
include-hidden-files: true
if-no-files-found: warn
- name: Upload Test Results (JUnit XMLs)
if: always()
uses: actions/upload-artifact@v7
with:
name: Test Results Group ${{ matrix.test_group }}
path: log/*.xml
if-no-files-found: ignore
- name: Upload Test Artifacts (log)
uses: actions/upload-artifact@v7
if: always()
with:
name: Test Artifacts (log directory) Group ${{ matrix.test_group }}
path: |
log
!log/*.xml
if-no-files-found: ignore
- name: Upload Test Artifacts (rails tmp)
if: failure()
uses: actions/upload-artifact@v7
with:
name: Test Artifacts (rails tmp directory) Group ${{ matrix.test_group }}
path: tmp
if-no-files-found: ignore
retention-days: 14
publish_results:
name: Publish Test Results and Coverage
if: always()
needs: [build, tests]
permissions: write-all
runs-on: ubuntu-16-cores-latest
steps:
- uses: actions/checkout@v6
- uses: ruby/setup-ruby@v1
env:
BUNDLE_ENTERPRISE__CONTRIBSYS__COM: ${{ secrets.BUNDLE_ENTERPRISE__CONTRIBSYS__COM }}
with:
bundler-cache: ${{ needs.tests.result == 'success' }}
- uses: actions/download-artifact@v8
- name: Publish Test Results to GitHub
if: always()
uses: EnricoMi/publish-unit-test-result-action@v2
with:
check_name: Test Results
comment_mode: off
files: Test Results Group*/*.xml
github_token: ${{ secrets.GITHUB_TOKEN }}
- name: Add Test Failure label
if: ${{ needs.tests.result == 'failure' && github.event_name == 'pull_request' }}
uses: actions/github-script@v8
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const prNumber = context.payload.pull_request.number
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
labels: ['test-failure'],
})
- name: Fail job if tests failed
if: ${{ needs.tests.result == 'failure' }}
run: exit 1
- name: Remove Test Failure label
if: ${{ needs.tests.result == 'success' && github.event_name == 'pull_request' }}
uses: actions/github-script@v8
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const prNumber = context.payload.pull_request.number
try {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
name: 'test-failure',
})
} catch (e) {
if (e.status !== 404) throw e
}
# Convert JUnit XML test results into a parallel_test runtime log so that
# future runs can use --group-by runtime (runtime-based shard balancing).
# Each shard uploads JUnit XMLs as artifacts; the download-artifact step
# above already fetched them into "Test Results Group N/" directories.
# The generated log is cached (below) for the next workflow run.
- name: Generate parallel_test runtime log from JUnit XML
if: always()
run: |
mkdir -p tmp
ruby script/junit_to_runtime_log.rb tmp/parallel_runtime_rspec.log "Test Results Group*/*.xml"
- name: Save runtime log to cache
if: always()
uses: actions/cache/save@v4
with:
path: tmp/parallel_runtime_rspec.log
key: parallel-runtime-log-${{ github.ref }}-${{ github.run_id }}
- name: Download coverage artifacts
if: needs.tests.result == 'success'
uses: actions/download-artifact@v8
with:
pattern: simplecov-resultset-*
path: .
- name: Collate coverage and generate report
if: needs.tests.result == 'success'
env:
BUNDLE_ENTERPRISE__CONTRIBSYS__COM: ${{ secrets.BUNDLE_ENTERPRISE__CONTRIBSYS__COM }}
run: bundle exec ruby script/coverage_collate.rb
- name: Upload Combined Coverage HTML
if: needs.tests.result == 'success'
uses: actions/upload-artifact@v7
with:
name: Coverage Report
path: coverage
if-no-files-found: ignore
- name: Fix up coverage report to work with coverage-check-action
id: coverage
if: needs.tests.result == 'success'
run: |
echo "=== Fixing coverage report format ==="
sed -i 's/"line"/"covered_percent"/g' 'coverage/.last_run.json'
echo "=== Verifying modified format ==="
pct=$(cat coverage/.last_run.json | jq '.result.covered_percent')
echo "percent=$pct" >> $GITHUB_OUTPUT
echo "Extracted coverage: $pct"
- name: Publish Coverage Report
if: needs.tests.result == 'success'
uses: devmasx/coverage-check-action@v1.2.0
with:
type: simplecov
result_path: coverage/.last_run.json
min_coverage: 90
token: ${{ secrets.GITHUB_TOKEN }}
- name: Configure AWS Credentials
if: needs.tests.result == 'success' && github.event_name != 'pull_request'
uses: aws-actions/configure-aws-credentials@v6
with:
role-to-assume: ${{ vars.AWS_ASSUME_ROLE }}
aws-region: us-gov-west-1
- uses: department-of-veterans-affairs/action-inject-ssm-secrets@d8e6de3bde4dd728c9d732baef58b3c854b8c4bb
if: needs.tests.result == 'success' && github.event_name != 'pull_request'
with:
ssm_parameter: /devops/VA_VSP_BOT_GITHUB_TOKEN
env_variable_name: VA_VSP_BOT_GITHUB_TOKEN
- name: Checkout VSP actions
if: needs.tests.result == 'success' && github.event_name != 'pull_request'
uses: actions/checkout@v6
with:
repository: department-of-veterans-affairs/vsp-github-actions
ref: refs/heads/main
token: ${{ env.VA_VSP_BOT_GITHUB_TOKEN }}
persist-credentials: false
path: ./.github/actions/vsp-github-actions
- uses: department-of-veterans-affairs/action-inject-ssm-secrets@d8e6de3bde4dd728c9d732baef58b3c854b8c4bb
if: needs.tests.result == 'success' && github.event_name != 'pull_request'
with:
ssm_parameter: /devops/github_actions_slack_socket_token
env_variable_name: SLACK_APP_TOKEN
- uses: department-of-veterans-affairs/action-inject-ssm-secrets@d8e6de3bde4dd728c9d732baef58b3c854b8c4bb
if: needs.tests.result == 'success' && github.event_name != 'pull_request'
with:
ssm_parameter: /devops/github_actions_slack_bot_user_token
env_variable_name: SLACK_BOT_TOKEN
- name: Slack notify - critical coverage alert
if: needs.tests.result == 'success' && github.event_name != 'pull_request' && fromJSON(steps.coverage.outputs.percent) < 90
uses: ./.github/actions/vsp-github-actions/slack-socket
with:
slack_app_token: ${{ env.SLACK_APP_TOKEN }}
slack_bot_token: ${{ env.SLACK_BOT_TOKEN }}
message: "Critical: Vets-API Testing Coverage Below 90% - Deployment Blocked"
blocks: |
[
{ "type": "divider" },
{
"type": "header",
"text": {
"type": "plain_text",
"text": ":rotating_light: CRITICAL: Test Coverage Too Low",
"emoji": true
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Vets-API deployment is BLOCKED until coverage reaches 90%*"
}
},
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": ":chart_with_downwards_trend: *Current Coverage*: ${{ steps.coverage.outputs.percent }}%"
},
{
"type": "mrkdwn",
"text": ":dart: *Required Minimum*: 90%"
},
{
"type": "mrkdwn",
"text": ":x: *Status*: Deployment Blocked"
}
]
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ":bust_in_silhouette: *Author:* ${{ github.actor }}"
}
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": ":mag_right: View Test Run",
"emoji": true
},
"url": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}",
"style": "danger"
}
]
},
{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": ":bulb: *View detailed coverage:* <https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}|Open test run> → Scroll to *Artifacts* → Download *Coverage Report* → Open *index.html*"
}
]
},
{ "type": "divider" }
]
channel_id: "C0APA867M0V"
- name: Slack notify - warning low coverage alert
if: needs.tests.result == 'success' && github.event_name != 'pull_request' && fromJSON(steps.coverage.outputs.percent) >= 90 && fromJSON(steps.coverage.outputs.percent) < 93
uses: ./.github/actions/vsp-github-actions/slack-socket
with:
slack_app_token: ${{ env.SLACK_APP_TOKEN }}
slack_bot_token: ${{ env.SLACK_BOT_TOKEN }}
message: "Warning: Vets-API Testing Coverage Below 93%"
blocks: |
[
{ "type": "divider" },
{
"type": "header",
"text": {
"type": "plain_text",
"text": ":warning: Warning: Vets-API Coverage Below Target",
"emoji": true
}
},
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": ":chart_with_downwards_trend: *Current Coverage*: ${{ steps.coverage.outputs.percent }}%"
},
{
"type": "mrkdwn",
"text": ":dart: *Required Minimum*: 90%"
},
{
"type": "mrkdwn",
"text": ":large_green_circle: *Status*: Deployment Allowed"
}
]
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ":bust_in_silhouette: *Author:* ${{ github.actor }}"
}
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": ":mag_right: View Test Run",
"emoji": true
},
"url": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}",
"style": "danger"
}
]
},
{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": ":bulb: *View detailed coverage:* <https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}|Open test run> → Scroll to *Artifacts* → Download *Coverage Report* → Open *index.html*"
}
]
},
{ "type": "divider" }
]
channel_id: "C0APA867M0V"
- name: Comment Coverage on PR
if: needs.tests.result == 'success' && github.event_name == 'pull_request' && fromJSON(steps.coverage.outputs.percent) < 90
uses: marocchino/sticky-pull-request-comment@v3
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
header: coverage
message: |
## :x: Critical: Test Coverage Too Low
**Coverage:** ${{ steps.coverage.outputs.percent }}%
Your test coverage is **below the required minimum of 90%**.
Please add additional tests before this PR can be considered for merge.
Once coverage is improved, push another commit or rerun the workflow to update this report.
**View detailed coverage:** [Open test run](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) → Scroll to **Artifacts** → Download **Coverage Report** → Open **index.html**
- name: Comment Coverage on PR
if: needs.tests.result == 'success' && github.event_name == 'pull_request' && fromJSON(steps.coverage.outputs.percent) >= 90 && fromJSON(steps.coverage.outputs.percent) < 93
uses: marocchino/sticky-pull-request-comment@v3
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
header: coverage
message: |
## :warning: Warning: Low Coverage Report
**Coverage:** ${{ steps.coverage.outputs.percent }}%
Please add or expand tests to improve coverage before merging.
**View detailed coverage:** [Open test run](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) → Scroll to **Artifacts** → Download **Coverage Report** → Open **index.html**
- name: Remove coverage comment when coverage is healthy
if: needs.tests.result == 'success' && github.event_name == 'pull_request' && fromJSON(steps.coverage.outputs.percent) >= 93
uses: marocchino/sticky-pull-request-comment@v3
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
header: coverage
delete: true