-
Notifications
You must be signed in to change notification settings - Fork 25
574 lines (507 loc) · 24.2 KB
/
Copy pathcontinuous-integration.yaml
File metadata and controls
574 lines (507 loc) · 24.2 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
# @author Ivan Senic
name: Continuous Integration
# runs on
# * pushes and pull requests on the "main" (pull request only for specific paths)
# * manual trigger
on:
push:
branches: [ "main", "feature/*" ]
pull_request:
branches: [ "main", "feature/*" ]
workflow_dispatch:
# cancel same workflows in progress for pull request branches
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
# needed when a workflow wants to use OIDC (OpenID Connect) to authenticate to cloud
permissions:
id-token: write
contents: write
packages: write
pull-requests: write
# global env vars, available in all jobs and steps
env:
MAVEN_OPTS: '-Xmx4g'
DS_ARTIFACTORY_USERNAME: ${{ secrets.DS_ARTIFACTORY_USERNAME }}
DS_ARTIFACTORY_PASSWORD: ${{ secrets.DS_ARTIFACTORY_PASSWORD }}
# Jobs structure:
#
# 1. Runs unit tests
# 2. Then 2 jobs in parallel
# a) Integration tests with DSE 6.9
# b) Integration tests with HCD
jobs:
# runs unit tests
build:
name: Unit tests
runs-on: ubuntu-latest
# max run time 12 minutes
timeout-minutes: 12
steps:
- uses: actions/checkout@v7
- name: Set up JDK 21
uses: actions/setup-java@v5
with:
distribution: 'temurin'
java-version: '21'
cache: maven
- name: Setup Maven
run: |
mkdir -p ~/.m2
cat <<EOF > ~/.m2/settings.xml
<settings>
<servers>
<server>
<id>stargate-central</id>
<username>${DS_ARTIFACTORY_USERNAME}</username>
<password>${DS_ARTIFACTORY_PASSWORD}</password>
</server>
<server>
<id>stargate-snapshots</id>
<username>${DS_ARTIFACTORY_USERNAME}</username>
<password>${DS_ARTIFACTORY_PASSWORD}</password>
</server>
<server>
<id>artifactory</id>
<username>${DS_ARTIFACTORY_USERNAME}</username>
<password>${DS_ARTIFACTORY_PASSWORD}</password>
</server>
<server>
<id>artifactory-snapshots</id>
<username>${DS_ARTIFACTORY_USERNAME}</username>
<password>${DS_ARTIFACTORY_PASSWORD}</password>
</server>
<server>
<id>artifactory-releases</id>
<username>${DS_ARTIFACTORY_USERNAME}</username>
<password>${DS_ARTIFACTORY_PASSWORD}</password>
</server>
</servers>
</settings>
EOF
- name: Build & Test
run: |
./mvnw -B -ntp -Dstyle.color=always clean test
# Publish baseline coverage for main branch (for future PR comparisons)
- name: Publish baseline coverage
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
uses: actions/upload-artifact@v7
with:
name: baseline-coverage
path: target/site/jacoco/jacoco.xml
retention-days: 30
# Download baseline coverage from main branch for PR comparison
- name: Download baseline coverage
if: github.event_name == 'pull_request'
continue-on-error: true
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Get the latest successful run on main that has the baseline-coverage artifact
run_id=$(gh run list --workflow=continuous-integration.yaml --branch=main --status=success --limit=1 --json databaseId --jq='.[0].databaseId')
if [ -n "$run_id" ]; then
echo "Downloading baseline coverage from run $run_id"
gh run download $run_id --name baseline-coverage --dir baseline-coverage
else
echo "No successful workflow run found on main branch with coverage artifact"
fi
- name: Calculate and report coverage delta
if: github.event_name == 'pull_request'
id: coverage-delta
continue-on-error: true
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
REPO: ${{ github.repository }}
run: |
python3 << 'EOF'
import os
import json
import urllib.request
def get_coverage(jacoco_dir):
"""Calculate coverage from JaCoCo XML file"""
import xml.etree.ElementTree as ET
xml_file = os.path.join(jacoco_dir, 'jacoco.xml')
if os.path.exists(xml_file):
try:
tree = ET.parse(xml_file)
root = tree.getroot()
# Find report-level counter (direct child of root with largest total)
# Strip namespace if present
max_total = 0
best_covered = 0
best_missed = 0
for child in root:
tag = child.tag.split('}')[-1] if '}' in child.tag else child.tag
if tag == 'counter' and child.get('type') == 'INSTRUCTION':
covered = int(child.get('covered', 0))
missed = int(child.get('missed', 0))
total = covered + missed
if total > max_total:
max_total = total
best_covered = covered
best_missed = missed
total = best_covered + best_missed
pct = (best_covered / total * 100) if total > 0 else 0
print(f'XML parse ({xml_file}): covered={best_covered}, missed={best_missed}, total={total}, pct={pct:.2f}%')
return pct
except Exception as e:
print(f'XML parse error: {e}')
pass
return 0
def github_api(method, endpoint, data=None):
url = f"https://api.github.com/repos/{os.environ['REPO']}/{endpoint}"
headers = {
'Authorization': f"token {os.environ['GH_TOKEN']}",
'Accept': 'application/vnd.github.v3+json'
}
req = urllib.request.Request(url, headers=headers, method=method)
if data:
req.data = json.dumps(data).encode()
return json.loads(urllib.request.urlopen(req).read())
# Debug: Check if CSV exists
import os as os_check
csv_exists = os_check.path.exists('target/site/jacoco/jacoco.csv')
xml_exists = os_check.path.exists('target/site/jacoco/jacoco.xml')
print(f'Unit test files: CSV={csv_exists}, XML={xml_exists}')
current = get_coverage('target/site/jacoco')
baseline = get_coverage('baseline-coverage')
print(f'Unit test coverage: current={current:.2f}%, baseline={baseline:.2f}%')
has_baseline = os.path.exists('baseline-coverage/jacoco.xml')
# Write outputs for job summary
with open(os.environ['GITHUB_OUTPUT'], 'a') as f:
f.write(f'current_coverage={current:.2f}\n')
if has_baseline:
delta = current - baseline
f.write(f'baseline_coverage={baseline:.2f}\n')
f.write(f'delta={delta:.2f}\n')
f.write(f'has_baseline=true\n')
print(f'Coverage: {baseline:.2f}% (main) → {current:.2f}% (PR) = {delta:+.2f}%')
# Post PR comment with delta
emoji = '📈' if delta > 0 else '📉' if delta < 0 else '➡️'
color = '🟢' if delta > 0 else '🔴' if delta < 0 else '⚪'
sign = '+' if delta > 0 else ''
msg = '⚠️ Coverage decreased' if delta < 0 else '✅ Coverage improved!' if delta > 0 else 'ℹ️ Coverage unchanged'
comment_body = (
f"## {emoji} Unit Test Coverage Delta vs Main Branch\n\n"
f"| Metric | Value |\n"
f"|--------|-------|\n"
f"| **Main Branch** | {baseline:.2f}% |\n"
f"| **This PR** | {current:.2f}% |\n"
f"| **Delta** | {color} {sign}{delta:.2f}% |\n"
f"{msg}\n"
)
# Find and update existing comment or create new one
pr_number = os.environ['PR_NUMBER']
comments = github_api('GET', f'issues/{pr_number}/comments')
existing = next((c for c in comments if c.get('user', {}).get('login') == 'github-actions[bot]'
and 'Unit Test Coverage Delta vs Main Branch' in c.get('body', '')), None)
if existing:
github_api('PATCH', f"issues/comments/{existing['id']}", {'body': comment_body})
print(f'Updated comment {existing["id"]}')
else:
github_api('POST', f'issues/{pr_number}/comments', {'body': comment_body})
print('Created new comment')
else:
f.write(f'has_baseline=false\n')
print('⚠️ No baseline coverage (expected on first PR after setup)')
EOF
- name: Add coverage to PR
id: jacoco
uses: madrapps/jacoco-report@v1.8.0
if: github.event_name == 'pull_request'
with:
paths: |
${{ github.workspace }}/target/site/jacoco/jacoco.xml
token: ${{ secrets.GITHUB_TOKEN }}
min-coverage-overall: 40
min-coverage-changed-files: 60
title: 'Unit Test Coverage Report'
update-comment: true
- name: Generate JaCoCo Badge
id: jacoco-badge
uses: cicirello/jacoco-badge-generator@v2
with:
badges-directory: .github/badges
generate-branches-badge: true
generate-summary: true
- name: Add unit test coverage to Job Summary
run: |
COVERAGE=$(printf "%.2f" $(echo "${{ steps.jacoco-badge.outputs.coverage }} * 100" | bc -l))
BRANCHES=$(printf "%.2f" $(echo "${{ steps.jacoco-badge.outputs.branches }} * 100" | bc -l))
cat >> $GITHUB_STEP_SUMMARY << EOF
## 📊 Unit Test Code Coverage Report
| Metric | Coverage |
|--------|----------|
| **Instructions** | ${COVERAGE}% |
| **Branches** | ${BRANCHES}% |
EOF
# Add delta for PRs with baseline
if [ "${{ github.event_name }}" == "pull_request" ] && [ "${{ steps.coverage-delta.outputs.has_baseline }}" == "true" ]; then
delta="${{ steps.coverage-delta.outputs.delta }}"
cat >> $GITHUB_STEP_SUMMARY << EOF
### Coverage vs Main: ${{ steps.coverage-delta.outputs.baseline_coverage }}% → ${{ steps.coverage-delta.outputs.current_coverage }}% (${delta}%)
EOF
elif [ "${{ github.event_name }}" == "pull_request" ]; then
cat >> $GITHUB_STEP_SUMMARY << EOF
_Baseline coverage will be available after first merge to main_
EOF
fi
cat >> $GITHUB_STEP_SUMMARY << EOF
📥 [Download Full HTML Report](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
EOF
- name: Upload JaCoCo coverage report
uses: actions/upload-artifact@v7
with:
name: jacoco-report
path: target/site/jacoco/
# runs int tests
int-tests:
name: Integration tests
runs-on: ubuntu-latest
# max run time 40 minutes
timeout-minutes: 40
strategy:
# let all tests run, can find multiple failures in different setup
fail-fast: false
# matrix props:
matrix:
type: [ docker, dse69-it, hcd-it ]
include:
- type: dse69-it
profile: '-Pdse69-it'
- type: hcd-it
profile: '-Phcd-it'
exclude:
- type: docker
steps:
- uses: actions/checkout@v7
- name: Set up JDK 21
uses: actions/setup-java@v5
with:
distribution: 'temurin'
java-version: '21'
cache: maven
- name: Setup Maven
run: |
mkdir -p ~/.m2
cat <<EOF > ~/.m2/settings.xml
<settings>
<servers>
<server>
<id>stargate-central</id>
<username>${DS_ARTIFACTORY_USERNAME}</username>
<password>${DS_ARTIFACTORY_PASSWORD}</password>
</server>
<server>
<id>stargate-snapshots</id>
<username>${DS_ARTIFACTORY_USERNAME}</username>
<password>${DS_ARTIFACTORY_PASSWORD}</password>
</server>
<server>
<id>artifactory</id>
<username>${DS_ARTIFACTORY_USERNAME}</username>
<password>${DS_ARTIFACTORY_PASSWORD}</password>
</server>
<server>
<id>artifactory-snapshots</id>
<username>${DS_ARTIFACTORY_USERNAME}</username>
<password>${DS_ARTIFACTORY_PASSWORD}</password>
</server>
<server>
<id>artifactory-releases</id>
<username>${DS_ARTIFACTORY_USERNAME}</username>
<password>${DS_ARTIFACTORY_PASSWORD}</password>
</server>
</servers>
</settings>
EOF
- name: Configure AWS credentials via OIDC
uses: aws-actions/configure-aws-credentials@v6
with:
role-to-assume: ${{ secrets.US_WEST_2_559669398656_DATA_API_ECR_HCD }}
aws-region: us-west-2
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
with:
mask-password: 'true'
# run the int tests
- name: Integration Test
# -DRERANKING_CONFIG_RESOURCE=test-reranking-providers-config.yaml is to override the reranking config to customized one
# -DEMBEDDING_CONFIG_RESOURCE=test-embedding-providers-config.yaml is to override the embedding config to customized one
# -Pjacoco-it enables the quarkus-jacoco extension for IT coverage
# -Dquarkus.package.write-transformed-bytecode-to-build-output=true is required for JaCoCo IT coverage
# Note: Container image build is disabled for coverage (JaCoCo only works with JAR artifacts)
run: |
./mvnw -B -ntp clean verify -Dstyle.color=always -DskipUnitTests -DRERANKING_CONFIG_RESOURCE=test-reranking-providers-config.yaml -DEMBEDDING_CONFIG_RESOURCE=test-embedding-providers-config.yaml -Drun-create-index-parallel=true -Pjacoco-it -Dquarkus.package.write-transformed-bytecode-to-build-output=true ${{ matrix.profile }}
# Publish baseline IT coverage for main branch (for future PR comparisons)
- name: Publish baseline IT coverage
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
uses: actions/upload-artifact@v7
with:
name: baseline-it-coverage-${{ matrix.type }}
path: target/site/jacoco-it/jacoco.xml
retention-days: 30
# Download baseline IT coverage from main branch for PR comparison
- name: Download baseline IT coverage
if: github.event_name == 'pull_request'
continue-on-error: true
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Get the latest successful run on main that has the baseline IT coverage artifact
run_id=$(gh run list --workflow=continuous-integration.yaml --branch=main --status=success --limit=1 --json databaseId --jq='.[0].databaseId')
if [ -n "$run_id" ]; then
echo "Downloading baseline IT coverage for ${{ matrix.type }} from run $run_id"
gh run download $run_id --name baseline-it-coverage-${{ matrix.type }} --dir baseline-it-coverage-${{ matrix.type }} || echo "No baseline IT coverage artifact found for ${{ matrix.type }}"
else
echo "No successful workflow run found on main branch with IT coverage artifact"
fi
- name: Calculate and report IT coverage delta
if: github.event_name == 'pull_request'
id: it-coverage-delta
continue-on-error: true
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
REPO: ${{ github.repository }}
MATRIX_TYPE: ${{ matrix.type }}
run: |
python3 << 'EOF'
import os
import json
import urllib.request
def get_coverage(jacoco_dir):
"""Calculate coverage from JaCoCo XML file"""
import xml.etree.ElementTree as ET
xml_file = os.path.join(jacoco_dir, 'jacoco.xml')
if os.path.exists(xml_file):
try:
tree = ET.parse(xml_file)
root = tree.getroot()
# Find report-level counter (direct child of root with largest total)
# Strip namespace if present
max_total = 0
best_covered = 0
best_missed = 0
for child in root:
tag = child.tag.split('}')[-1] if '}' in child.tag else child.tag
if tag == 'counter' and child.get('type') == 'INSTRUCTION':
covered = int(child.get('covered', 0))
missed = int(child.get('missed', 0))
total = covered + missed
if total > max_total:
max_total = total
best_covered = covered
best_missed = missed
total = best_covered + best_missed
pct = (best_covered / total * 100) if total > 0 else 0
print(f'XML parse ({xml_file}): covered={best_covered}, missed={best_missed}, total={total}, pct={pct:.2f}%')
return pct
except Exception as e:
print(f'XML parse error: {e}')
pass
return 0
def github_api(method, endpoint, data=None):
url = f"https://api.github.com/repos/{os.environ['REPO']}/{endpoint}"
headers = {
'Authorization': f"token {os.environ['GH_TOKEN']}",
'Accept': 'application/vnd.github.v3+json'
}
req = urllib.request.Request(url, headers=headers, method=method)
if data:
req.data = json.dumps(data).encode()
return json.loads(urllib.request.urlopen(req).read())
matrix_type = os.environ['MATRIX_TYPE']
current = get_coverage('target/site/jacoco-it')
baseline = get_coverage(f'baseline-it-coverage-{matrix_type}')
has_baseline = os.path.exists(f'baseline-it-coverage-{matrix_type}/jacoco.xml')
# Write outputs for job summary
with open(os.environ['GITHUB_OUTPUT'], 'a') as f:
f.write(f'current_coverage={current:.2f}\n')
if has_baseline:
delta = current - baseline
f.write(f'baseline_coverage={baseline:.2f}\n')
f.write(f'delta={delta:.2f}\n')
f.write(f'has_baseline=true\n')
print(f'IT Coverage ({matrix_type}): {baseline:.2f}% (main) → {current:.2f}% (PR) = {delta:+.2f}%')
# Post PR comment with delta
emoji = '📈' if delta > 0 else '📉' if delta < 0 else '➡️'
color = '🟢' if delta > 0 else '🔴' if delta < 0 else '⚪'
sign = '+' if delta > 0 else ''
msg = '⚠️ Coverage decreased' if delta < 0 else '✅ Coverage improved!' if delta > 0 else 'ℹ️ Coverage unchanged'
comment_body = (
f"## {emoji} Integration Test Coverage Delta vs Main Branch ({matrix_type})\n\n"
f"| Metric | Value |\n"
f"|--------|-------|\n"
f"| **Main Branch** | {baseline:.2f}% |\n"
f"| **This PR** | {current:.2f}% |\n"
f"| **Delta** | {color} {sign}{delta:.2f}% |\n"
f"{msg}\n"
)
# Find and update existing comment or create new one
pr_number = os.environ['PR_NUMBER']
comments = github_api('GET', f'issues/{pr_number}/comments')
existing = next((c for c in comments if c.get('user', {}).get('login') == 'github-actions[bot]'
and f'Integration Test Coverage Delta vs Main Branch ({matrix_type})' in c.get('body', '')), None)
if existing:
github_api('PATCH', f"issues/comments/{existing['id']}", {'body': comment_body})
print(f'Updated comment {existing["id"]}')
else:
github_api('POST', f'issues/{pr_number}/comments', {'body': comment_body})
print('Created new comment')
else:
f.write(f'has_baseline=false\n')
print(f'⚠️ No baseline IT coverage for {matrix_type} (expected on first PR after setup)')
EOF
- name: Add integration test coverage to PR
id: jacoco-it
uses: madrapps/jacoco-report@v1.8.0
if: github.event_name == 'pull_request'
with:
paths: |
${{ github.workspace }}/target/site/jacoco-it/jacoco.xml
token: ${{ secrets.GITHUB_TOKEN }}
min-coverage-overall: 40
min-coverage-changed-files: 60
title: 'Integration Test Coverage Report (${{ matrix.type }})'
update-comment: true
continue-on-error: true
- name: Generate JaCoCo IT Badge
id: jacoco-it-badge
uses: cicirello/jacoco-badge-generator@v2
with:
jacoco-csv-file: target/site/jacoco-it/jacoco.csv
badges-directory: .github/badges/it-${{ matrix.type }}
generate-branches-badge: true
generate-summary: true
continue-on-error: true
- name: Add IT coverage to Job Summary
run: |
COVERAGE=$(printf "%.2f" $(echo "${{ steps.jacoco-it-badge.outputs.coverage }} * 100" | bc -l))
BRANCHES=$(printf "%.2f" $(echo "${{ steps.jacoco-it-badge.outputs.branches }} * 100" | bc -l))
echo "## 📊 Integration Test Code Coverage Report (${{ matrix.type }})" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Metric | Coverage |" >> $GITHUB_STEP_SUMMARY
echo "|--------|----------|" >> $GITHUB_STEP_SUMMARY
echo "| **Instructions** | ${COVERAGE}% |" >> $GITHUB_STEP_SUMMARY
echo "| **Branches** | ${BRANCHES}% |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
# Add delta for PRs with baseline
if [ "${{ github.event_name }}" == "pull_request" ] && [ "${{ steps.it-coverage-delta.outputs.has_baseline }}" == "true" ]; then
delta="${{ steps.it-coverage-delta.outputs.delta }}"
echo "### Coverage vs Main: ${{ steps.it-coverage-delta.outputs.baseline_coverage }}% → ${{ steps.it-coverage-delta.outputs.current_coverage }}% (${delta}%)" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
elif [ "${{ github.event_name }}" == "pull_request" ]; then
echo "_Baseline IT coverage will be available after first merge to main_" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
fi
echo "📥 [Download Full HTML Report](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "The complete JaCoCo HTML report is available as an artifact named \`jacoco-it-report-${{ matrix.type }}\`" >> $GITHUB_STEP_SUMMARY
- name: Upload JaCoCo integration test code coverage report
uses: actions/upload-artifact@v7
with:
name: jacoco-it-report-${{ matrix.type }}
path: target/site/jacoco-it/