-
Notifications
You must be signed in to change notification settings - Fork 1
521 lines (458 loc) · 17.5 KB
/
Copy pathci.yml
File metadata and controls
521 lines (458 loc) · 17.5 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
name: CI (c++) Build and Test
on:
workflow_dispatch:
inputs:
protocol:
description: 'RPC Protocol to test'
required: true
default: 'rpc_v2'
type: choice
options:
- rpc_v2
- legacy
push:
branches: [ main, develop, next ]
pull_request:
branches: [ main, develop, next ]
defaults:
run:
shell: bash
env:
HUSKY: 0
MOCK_PATH: ${{ github.workspace }}/mock-firebolt
MOCK_BRANCH: topic/changes-for-bidirectional
MOCK_SHA1SUM: 1fec7b75190e75ac8ea8ebf9f3e00c0a070b2566
jobs:
build_docker:
permissions:
contents: read
packages: write
runs-on: ubuntu-latest
outputs:
image_tag: ${{ steps.meta.outputs.tags }}
steps:
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}/firebolt-client-ci
tags: type=sha
- name: Checkout Code
uses: actions/checkout@v4
- name: Get Transport Version for Build-Arg
id: transport_version
run: echo "version=$(cat ${{ github.workspace }}/.transport.version)" >> $GITHUB_OUTPUT
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: .github/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
DEPS_TRANSPORT_V=${{ steps.transport_version.outputs.version }}
DEPS_TRANSPORT_PROTOCOL=${{ github.event.inputs.protocol || 'rpc_v2' }}
cache-from: type=gha,scope=${{ github.workflow }}
cache-to: type=gha,mode=max,scope=${{ github.workflow }}
format_check:
permissions:
contents: read
packages: read
needs: [build_docker]
runs-on: ubuntu-latest
steps:
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout Code
uses: actions/checkout@v4
- name: Run clang-format check
run: |
docker run --rm --user "$(id -u):$(id -g)" -v ${{ github.workspace }}:/workspace ${{ needs.build_docker.outputs.image_tag }} \
bash -c " \
set -e \
&& git ls-files -- '*.cpp' '*.h' | xargs clang-format --dry-run --Werror \
"
build_project:
permissions:
contents: read
packages: read
needs: [build_docker]
runs-on: ubuntu-latest
steps:
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get version
run: |
VERSION=$(git describe --tags --dirty --match "v[0-9]*")
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "version: $VERSION"
- name: Configure Project
run: |
docker run --rm --user "$(id -u):$(id -g)" -v ${{ github.workspace }}:/workspace ${{ needs.build_docker.outputs.image_tag }} \
bash -c " \
set -e \
&& cmake -B build -S . \
-DCMAKE_BUILD_TYPE=Debug \
-DENABLE_TESTS=ON \
&& cp docs/openrpc/the-spec/firebolt-open-rpc.json build/test/ \
"
- name: Build Project
run: |
docker run --rm --user "$(id -u):$(id -g)" -v ${{ github.workspace }}:/workspace ${{ needs.build_docker.outputs.image_tag }} \
bash -c " \
set -e \
&& cmake --build build --parallel \
"
- name: Install Project to build/install
run: |
docker run --rm --user "$(id -u):$(id -g)" -v ${{ github.workspace }}:/workspace ${{ needs.build_docker.outputs.image_tag }} \
bash -c " \
set -e \
&& cmake --install build --prefix build/install \
"
- name: Upload build directory
uses: actions/upload-artifact@v4
with:
name: build-dir
path: ${{ github.workspace }}/build
unit_tests:
permissions:
contents: read
packages: read
needs: [build_docker, build_project]
runs-on: ubuntu-latest
steps:
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout Code
uses: actions/checkout@v4
- name: Download build directory
uses: actions/download-artifact@v4
with:
name: build-dir
path: ${{ github.workspace }}/build
- name: Run Unit Tests
run: |
chmod +x ${{ github.workspace }}/build/test/utApp
docker run --rm --user "$(id -u):$(id -g)" -v ${{ github.workspace }}:/workspace ${{ needs.build_docker.outputs.image_tag }} \
bash -c " \
set -e \
&& ctest --test-dir build/test \
"
- name: Generate Coverage Report
run: |
docker run --rm --user "$(id -u):$(id -g)" -v ${{ github.workspace }}:/workspace ${{ needs.build_docker.outputs.image_tag }} \
bash -c " \
set -e \
&& cd build \
&& mkdir -p coverage \
&& gcovr -r .. \
--exclude '.*/test/.*\.h' \
--exclude '.*/test/.*\.cpp' \
--decisions \
--medium-threshold 50 --high-threshold 75 \
--lcov coverage/filtered_coverage.info \
--html-details coverage/index.html \
--cobertura coverage.cobertura.xml \
"
- name: Upload Coverage Report
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: ${{ github.workspace }}/build/coverage/
- name: Upload unit test lcov coverage
uses: actions/upload-artifact@v4
with:
name: coverage-unit
path: ${{ github.workspace }}/build/coverage/filtered_coverage.info
- name: Code Coverage Summary Report
uses: irongut/CodeCoverageSummary@v1.3.0
with:
filename: build/coverage.cobertura.xml
badge: true
hide_complexity: true
format: markdown
output: both
thresholds: "50 75"
fail_below_min: false
- name: Add coverage summary to job summary
run: cat code-coverage-results.md >> $GITHUB_STEP_SUMMARY
component_tests:
permissions:
contents: read
packages: read
needs: [build_docker, build_project]
runs-on: ubuntu-latest
steps:
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout Code
uses: actions/checkout@v4
- name: Download build directory
uses: actions/download-artifact@v4
with:
name: build-dir
path: ${{ github.workspace }}/build
- name: Setup Mock-Firebolt
id: setup-mock
uses: ./.github/actions/setup-mock
- name: Restore Mock-Firebolt Cache
uses: actions/cache@v4
with:
path: ${{ env.MOCK_PATH }}
key: ${{ runner.os }}-mock-${{ steps.setup-mock.outputs.deps_cache_key }}
- name: Run Component Tests
run: |
chmod +x ${{ github.workspace }}/build/test/ctApp
docker run --rm --user "$(id -u):$(id -g)" -v ${{ github.workspace }}:/workspace -v ${{ env.MOCK_PATH }}:/mock ${{ needs.build_docker.outputs.image_tag }} \
./.github/scripts/run-component-tests.sh \
--mock /mock \
--protocol ${{ github.event.inputs.protocol || 'rpc_v2' }} \
--config /workspace/.github/mock-firebolt/config.json \
--openrpc /workspace/docs/openrpc/the-spec/firebolt-open-rpc.json \
--app-openrpc /workspace/docs/openrpc/the-spec/firebolt-app-open-rpc.json \
--test-exe /workspace/build/test/ctApp
- name: Generate Coverage Report
run: |
docker run --rm --user "$(id -u):$(id -g)" -v ${{ github.workspace }}:/workspace ${{ needs.build_docker.outputs.image_tag }} \
bash -c " \
set -e \
&& cd build \
&& mkdir -p coverage \
&& gcovr -r .. \
--exclude '.*/test/.*\.h' \
--exclude '.*/test/.*\.cpp' \
--lcov coverage/filtered_coverage.info \
"
- name: Upload component test lcov coverage
uses: actions/upload-artifact@v4
with:
name: coverage-component
path: ${{ github.workspace }}/build/coverage/filtered_coverage.info
api_test_app:
permissions:
contents: read
packages: read
needs: [build_docker, build_project]
runs-on: ubuntu-latest
steps:
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout Code
uses: actions/checkout@v4
- name: Download build directory
uses: actions/download-artifact@v4
with:
name: build-dir
path: ${{ github.workspace }}/build
- name: Build api-test-app standalone
run: |
docker run --rm --user "$(id -u):$(id -g)" -v ${{ github.workspace }}:/workspace ${{ needs.build_docker.outputs.image_tag }} \
bash -c " \
set -e \
&& cd test/api_test_app \
&& cmake -B build -S . \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_PREFIX_PATH=/workspace/build/install \
&& cmake --build build --parallel \
"
- name: Setup Mock-Firebolt
id: setup-mock
uses: ./.github/actions/setup-mock
- name: Restore Mock-Firebolt Cache
uses: actions/cache@v4
with:
path: ${{ env.MOCK_PATH }}
key: ${{ runner.os }}-mock-${{ steps.setup-mock.outputs.deps_cache_key }}
- name: Run api-test-app with mock server
run: |
chmod +x ${{ github.workspace }}/test/api_test_app/build/api-test-app
docker run --rm --user "$(id -u):$(id -g)" -v ${{ github.workspace }}:/workspace -v ${{ env.MOCK_PATH }}:/mock ${{ needs.build_docker.outputs.image_tag }} \
./.github/scripts/run-api-test-app.sh \
--mock /mock \
--config /workspace/.github/mock-firebolt/config.json \
--openrpc /workspace/docs/openrpc/the-spec/firebolt-open-rpc.json \
--app-openrpc /workspace/docs/openrpc/the-spec/firebolt-app-open-rpc.json \
--test-exe /workspace/test/api_test_app/build/api-test-app
coverage_gate:
name: Coverage Gate
needs: [unit_tests, component_tests]
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Run coverage script tests
run: python3 .github/scripts/compare_coverage_test.py
- name: Fetch baseline from build-metadata branch
# Gracefully handle a missing build-metadata branch (first-time setup)
continue-on-error: true
run: |
set -euo pipefail
if git fetch origin build-metadata 2>/dev/null; then
if git cat-file -e FETCH_HEAD:coverage-baseline.json 2>/dev/null; then
git show FETCH_HEAD:coverage-baseline.json > coverage-baseline.json
echo "Loaded coverage-baseline.json from build-metadata branch"
else
echo "build-metadata branch exists but coverage-baseline.json not found — skipping baseline comparison"
echo "{}" > coverage-baseline.json
fi
else
echo "build-metadata branch not found — absolute threshold check only (first-time setup)"
echo "{}" > coverage-baseline.json
fi
- name: Download unit test coverage artifact
continue-on-error: true
uses: actions/download-artifact@v4
with:
name: coverage-unit
path: ./unit-coverage
- name: Download component test coverage artifact
continue-on-error: true
uses: actions/download-artifact@v4
with:
name: coverage-component
path: ./component-coverage
- name: Compare coverage to baseline
run: |
python3 .github/scripts/compare_coverage.py \
--baseline coverage-baseline.json \
--unit ./unit-coverage/filtered_coverage.info \
--component ./component-coverage/filtered_coverage.info
update_baseline:
name: Update Coverage Baseline
# Runs on push to develop when both test suites pass.
# Independent of coverage_gate — the gate is informational and must never
# block the baseline from reflecting the actual state of passing tests.
if: >-
github.event_name == 'push' &&
github.ref == 'refs/heads/develop' &&
needs.unit_tests.result == 'success' &&
needs.component_tests.result == 'success'
needs: [unit_tests, component_tests]
runs-on: ubuntu-latest
permissions:
contents: write
actions: read
# Queue concurrent runs; do not cancel in-progress — each merge deserves
# a baseline update and force-push is atomic so queuing is safe.
concurrency:
group: update-baseline-develop
cancel-in-progress: false
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Fetch existing baseline for comparison report
# Best-effort — if the branch or file is absent we compare against nothing.
continue-on-error: true
run: |
set -euo pipefail
if git fetch origin build-metadata 2>/dev/null; then
if git cat-file -e FETCH_HEAD:coverage-baseline.json 2>/dev/null; then
git show FETCH_HEAD:coverage-baseline.json > old-baseline.json
echo "Loaded existing baseline for comparison"
else
echo '{}' > old-baseline.json
fi
else
echo '{}' > old-baseline.json
fi
- name: Download unit test coverage artifact
uses: actions/download-artifact@v4
with:
name: coverage-unit
path: ./unit-coverage
- name: Download component test coverage artifact
uses: actions/download-artifact@v4
with:
name: coverage-component
path: ./component-coverage
- name: Extract coverage and write new baseline
id: extract
run: |
set -euo pipefail
BL_ARG="old-baseline.json"
[ -f "$BL_ARG" ] || echo '{}' > "$BL_ARG"
python3 .github/scripts/compare_coverage.py \
--baseline "$BL_ARG" \
--unit ./unit-coverage/filtered_coverage.info \
--component ./component-coverage/filtered_coverage.info \
--output-json new-baseline.json \
--commit "$GITHUB_SHA" \
--timestamp "$(date -u '+%Y-%m-%dT%H:%M:%SZ')"
if [ ! -s new-baseline.json ]; then
echo "Coverage extraction produced no output — skipping baseline update"
echo "skip=true" >> "$GITHUB_OUTPUT"
else
echo "New baseline to commit:"
cat new-baseline.json
echo "skip=false" >> "$GITHUB_OUTPUT"
fi
- name: Commit and push updated baseline to build-metadata
if: steps.extract.outputs.skip == 'false'
run: |
set -euo pipefail
git config user.email "github-actions[bot]@users.noreply.github.com"
git config user.name "github-actions[bot]"
# Check out the build-metadata branch, or create it as an orphan.
if git fetch origin build-metadata 2>/dev/null; then
git checkout -B build-metadata FETCH_HEAD
else
git checkout --orphan build-metadata
git rm -rf . --quiet 2>/dev/null || true
fi
cp -f new-baseline.json coverage-baseline.json
git add coverage-baseline.json
# Only commit when there is an actual change.
if git diff --cached --quiet; then
echo "Coverage baseline unchanged — no commit needed"
else
MSG=$(printf \
'chore: update coverage baseline after develop merge [skip ci]\n\nCommit : %s\nRun ID : %s' \
"$GITHUB_SHA" "$GITHUB_RUN_ID")
git commit -m "$MSG"
git push --force-with-lease origin build-metadata
echo "Pushed updated baseline to build-metadata"
fi