-
Notifications
You must be signed in to change notification settings - Fork 8
730 lines (592 loc) · 20.8 KB
/
CI.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
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
---
name: CI build
on:
workflow_dispatch:
schedule:
- cron: '0 10 * * *' # every day at 10am
push:
branches:
- master
tags:
- 'v*.*.*'
pull_request:
permissions: read-all
jobs:
compile:
name: Compile Java Code
runs-on: ubuntu-latest
steps:
- name: Checkout codebase
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Set up JDK 17
uses: actions/setup-java@b36c23c0d998641eff861008f374ee103c25ac73 # v4
with:
java-version: '17'
distribution: 'temurin'
cache: maven
- name: Build with Maven
run: mvn -f backend --quiet clean compile -DskipTests=True
install:
runs-on: ubuntu-latest
name: Install JS libraries
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Setup Node.js
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4
with:
node-version: '20.12.2'
cache: 'yarn'
cache-dependency-path: 'frontend/yarn.lock'
- name: Install dependencies
run: yarn --cwd frontend install
build:
runs-on: ubuntu-latest
name: Build Vue app
needs: install
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Setup Node.js
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4
with:
node-version: '20.12.2'
cache: 'yarn'
cache-dependency-path: 'frontend/yarn.lock'
- name: Install dependencies
run: yarn --cwd frontend install
- name: Build app
run: yarn --cwd frontend build
lint:
name: Lint Java Code
runs-on: ubuntu-latest
steps:
- name: Set up JDK 17
uses: actions/setup-java@b36c23c0d998641eff861008f374ee103c25ac73 # v4
with:
java-version: '17'
distribution: 'temurin'
- name: Checkout Code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Lint Code Base
run: mvn -f backend clean com.spotify.fmt:fmt-maven-plugin:check
lint-js:
runs-on: ubuntu-latest
name: Lint JS Code
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Setup Node.js
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4
with:
node-version: '22.11.0'
cache: 'yarn'
cache-dependency-path: 'frontend/yarn.lock'
- name: Install dependencies
run: yarn install --cwd frontend
- name: Lint
run: yarn --cwd frontend eslint src
analyze:
name: CodeQL Analysis
needs: compile
runs-on: ubuntu-latest
timeout-minutes: 120
permissions:
actions: read
contents: write
security-events: write
steps:
- name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Set up JDK 17
uses: actions/setup-java@b36c23c0d998641eff861008f374ee103c25ac73 # v4
with:
java-version: '17'
distribution: 'temurin'
cache: maven
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: java
- name: Compile with maven
run: mvn -f backend --quiet -B clean package -Dmaven.test.skip=true
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: java
- name: Update dependency graph
uses: advanced-security/maven-dependency-submission-action@v4
with:
directory: backend
unit-tests:
name: Unit tests
runs-on: ubuntu-latest
needs:
- compile
steps:
- name: Checkout codebase
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Set up JDK 17
uses: actions/setup-java@b36c23c0d998641eff861008f374ee103c25ac73 # v4
with:
java-version: '17'
distribution: 'temurin'
cache: maven
- name: Run unit tests
working-directory: backend
run: mvn --quiet clean test -B --file pom.xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@b9fd7d16f6d7d1b5d2bec1a2887e65ceed900238 # v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
flags: unit
continue-on-error: true
integration-tests:
name: Integration tests
runs-on: ubuntu-latest
needs:
- unit-tests
steps:
- name: Checkout codebase
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Set up JDK 17
uses: actions/setup-java@b36c23c0d998641eff861008f374ee103c25ac73 # v4
with:
java-version: '17'
distribution: 'temurin'
cache: maven
- name: Run integration tests
working-directory: backend
run: mvn --quiet clean verify -B -Dspring.profiles.active=test
- name: Upload coverage to Codecov
uses: codecov/codecov-action@b9fd7d16f6d7d1b5d2bec1a2887e65ceed900238 # v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
flags: unit
continue-on-error: true
test:
runs-on: ubuntu-latest
needs:
- build-image
- build-frontend-image
name: E2E Tests
strategy:
matrix:
browser: [ "chrome", "electron" ]
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Download artifact
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4
with:
name: negotiator
path: /tmp
- name: Download artifact
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4
with:
name: negotiator-frontend
path: /tmp
- name: Load image
run: docker load --input /tmp/negotiator.tar
- name: Load image
run: docker load --input /tmp/negotiator-frontend.tar
- name: Setup API server
run: docker compose up -d
- name: Wait
run: sleep 30
- name: Cypress run
uses: cypress-io/github-action@57b70560982e6a11d23d4b8bec7f8a487cdbb71b #v6
with:
working-directory: frontend
browser: ${{ matrix.browser }}
- uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4
if: failure()
with:
name: cypress-screenshots
path: frontend/cypress/screenshots
build-image:
name: Build backend image
runs-on: ubuntu-latest
needs:
- unit-tests
steps:
- name: Checkout codebase
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Set up QEMU
uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf # v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@c47758b77c9736f4b2ef4073d4d51994fabfe349 # v3
- name: Build and push
uses: docker/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75 # v6
with:
context: backend
tags: bbmrieric/negotiator:latest
outputs: type=docker,dest=/tmp/negotiator.tar
- name: Upload image
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4
with:
name: negotiator
path: /tmp/negotiator.tar
build-frontend-image:
name: Build frontend image
runs-on: ubuntu-latest
needs:
- build
steps:
- name: Checkout codebase
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Set up QEMU
uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf # v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@c47758b77c9736f4b2ef4073d4d51994fabfe349 # v3
- name: Build and push
uses: docker/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75 # v6
with:
context: frontend
tags: bbmrieric/negotiator-frontend:latest
outputs: type=docker,dest=/tmp/negotiator-frontend.tar
- name: Upload image
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4
with:
name: negotiator-frontend
path: /tmp/negotiator-frontend.tar
image-scan:
needs:
- build-image
- build-frontend-image
runs-on: ubuntu-latest
permissions:
security-events: write
steps:
- name: Download artifact
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4
with:
name: negotiator
path: /tmp
- name: Download artifact
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4
with:
name: negotiator-frontend
path: /tmp
- name: Load image
run: docker load --input /tmp/negotiator.tar
- name: Load image
run: docker load --input /tmp/negotiator-frontend.tar
- name: Run Trivy Vulnerability Scanner
uses: aquasecurity/trivy-action@5681af892cd0f4997658e2bacc62bd0a894cf564
with:
image-ref: bbmrieric/negotiator:latest
format: sarif
output: trivy-results.sarif
severity: 'CRITICAL'
timeout: '15m0s'
- name: Run Trivy Vulnerability Scanner
uses: aquasecurity/trivy-action@5681af892cd0f4997658e2bacc62bd0a894cf564
with:
image-ref: bbmrieric/negotiator-frontend:latest
format: sarif
output: trivy-results.sarif
severity: 'CRITICAL'
timeout: '15m0s'
- name: Upload Trivy Scan Results to GitHub Security Tab
if: ${{ (github.repository_owner == 'bbmri-eric') || (vars.IMAGE_SCAN_UPLOAD == 'true') }}
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: trivy-results.sarif
system-test:
name: System tests
runs-on: ubuntu-latest
needs:
- build-image
steps:
- name: Download artifact
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4
with:
name: negotiator
path: /tmp
- name: Checkout codebase
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Load image
run: docker load --input /tmp/negotiator.tar
- name: Clone deployment repo
run: git clone https://gitlab.bbmri-eric.eu/negotiator-deployment/negotiator-deployment-template.git /opt/negotiator
- name: Run docker compose
working-directory: /opt/negotiator
run: docker compose -f compose.yaml -f $GITHUB_WORKSPACE/.github/compose-overrides/compose.override.system.yaml up -d negotiator
- name: Wait
run: sleep 30
- name: Get docker logs
run: docker logs negotiator
- name: Get running containers
run: docker ps
- name: Check health
run: $GITHUB_WORKSPACE/.github/scripts/check_health.sh negotiator
- name: Send request
run: $GITHUB_WORKSPACE/.github/scripts/new_request.sh
oauth-test:
name: OAuth2 Authorization tests
runs-on: ubuntu-latest
needs:
- build-image
steps:
- name: Download artifact
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4
with:
name: negotiator
path: /tmp
- name: Load image
run: docker load --input /tmp/negotiator.tar
- name: Checkout codebase
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Setup environment with auth server
run: docker compose up -d
- name: Wait
run: sleep 30
- name: Get docker logs
run: docker logs negotiator
- name: Check health
run: .github/scripts/check_health.sh negotiator
- name: Send authenticated request
run: chmod +x .github/scripts/send_authenticated_request.sh && .github/scripts/send_authenticated_request.sh
prometheus-test:
name: Prometheus Scraping Test
runs-on: ubuntu-latest
needs:
- build-image
steps:
- name: Download artifact
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4
with:
name: negotiator
path: /tmp
- name: Load image
run: docker load --input /tmp/negotiator.tar
- name: Checkout codebase
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Setup environment with auth server
run: docker compose up -d
- name: Wait
run: sleep 30
- name: Get docker logs
run: docker logs negotiator
- name: Run prometheus
working-directory: .github/prometheus
run: docker compose up -d
- name: Wait
run: sleep 30
- name: Check scraping
run: curl -s --fail 'http://localhost:9090/api/v1/query?query=up' | jq -e '.data.result[].metric.__name__ == "up"'
backwards-compatibility:
name: DB migration tests
runs-on: ubuntu-latest
needs:
- build-image
steps:
- name: Download artifact
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4
with:
name: negotiator
path: /tmp
- name: Clone deployment repo
run: git clone https://gitlab.bbmri-eric.eu/negotiator-deployment/negotiator-deployment-template.git /opt/negotiator
- name: Run docker compose
working-directory: /opt/negotiator
run: docker compose up -d negotiator
- name: Wait
run: sleep 30
- name: Down docker compose
run: cd /opt/negotiator && docker compose down
- name: Remove image
run: docker image rm bbmrieric/negotiator
- name: Load image
run: docker load --input /tmp/negotiator.tar
- name: Run docker compose
run: cd /opt/negotiator && docker compose up -d negotiator
- name: Wait
run: sleep 30
- name: Get docker logs
run: docker logs negotiator
- name: Checkout codebase
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Check health
run: .github/scripts/check_health.sh negotiator
build-push-image:
name: Publish backend image
runs-on: ubuntu-latest
needs:
- system-test
- oauth-test
- backwards-compatibility
- integration-tests
- prometheus-test
permissions:
packages: write
contents: read
steps:
- name: Checkout codebase
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Set up QEMU
uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf # v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@c47758b77c9736f4b2ef4073d4d51994fabfe349 # v3
- name: Login to DockerHub
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3
with:
username: ${{ secrets.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitHub Container Registry
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker meta
id: meta
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5
with:
images: |
bbmrieric/negotiator
ghcr.io/${{ github.repository_owner }}/negotiator
tags: |
type=ref,event=branch
type=raw,value=${{ github.head_ref }},event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'master') }}
- name: Build and push
uses: docker/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75 # v6
with:
context: backend
platforms: linux/amd64,linux/arm64
push: true
labels: ${{ steps.meta.outputs.labels }}
tags: ${{ steps.meta.outputs.tags }}
build-args: ARTIFACT_VERSION=${{ github.ref_name }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-push-frontend:
name: Publish frontend image
runs-on: ubuntu-latest
needs:
- system-test
- oauth-test
- backwards-compatibility
- integration-tests
- prometheus-test
permissions:
packages: write
contents: read
steps:
- name: Checkout codebase
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Set up QEMU
uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf # v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@c47758b77c9736f4b2ef4073d4d51994fabfe349 # v3
- name: Login to DockerHub
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3
with:
username: ${{ secrets.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitHub Container Registry
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker meta
id: meta
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5
with:
images: |
bbmrieric/negotiator-frontend
ghcr.io/${{ github.repository_owner }}/negotiator-frontend
tags: |
type=ref,event=branch
type=raw,value=${{ github.head_ref }},event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'master') }}
- name: Copy git directory
run: cp -r .git frontend
- name: Build and push
uses: docker/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75 # v6
with:
context: frontend
platforms: linux/amd64,linux/arm64
push: true
labels: ${{ steps.meta.outputs.labels }}
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-pages:
runs-on: ubuntu-24.04
name: Build Docs
steps:
- name: Check out Git repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
with:
fetch-depth: 0
- name: Setup Node
uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # v4
with:
node-version: 21
cache: npm
cache-dependency-path: 'docs/package-lock.json'
- name: Build
working-directory: docs
env:
DOCS_BASE: "/${{ github.event.repository.name }}/"
run: make build
- name: Setup Pages
uses: actions/configure-pages@983d7736d9b0ae728b81ab479565c72886d7745b # v5
- name: Upload artifact
uses: actions/upload-pages-artifact@56afc609e74202658d3ffba0e8f6dda462b719fa # v3
with:
path: docs/.vitepress/dist
deploy-pages:
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-24.04
needs: [ build-pages ]
name: Publish Docs
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e # v4
publish-jar:
if: github.event_name == 'push' && github.ref_type == 'tag'
name: Publish JAR file
runs-on: ubuntu-latest
permissions:
packages: write
needs:
- system-test
- oauth-test
- backwards-compatibility
- integration-tests
- prometheus-test
steps:
- name: Checkout codebase
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Set up JDK 17
uses: actions/setup-java@b36c23c0d998641eff861008f374ee103c25ac73 # v4
with:
java-version: '17'
distribution: 'temurin'
cache: maven
- name: Publish package
run: mvn -f backend --quiet -B versions:set -DnewVersion="${ARTIFACT_VERSION//v}"
env:
ARTIFACT_VERSION: ${{ github.ref_name }}
- name: Publish package
run: mvn -f backend --batch-mode deploy
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}