Repository navigation
342 lines (301 loc) · 11.1 KB
/
Copy pathtests-trigger.yml
File metadata and controls
342 lines (301 loc) · 11.1 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
name: main-workflow
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, '*.rc' ]
pull_request:
branches: [ main, develop, '*.rc' ]
defaults:
run:
shell: bash
env:
HUSKY: 0
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@c94ce9fb468520275223c153574b00df6fe4bcc9
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@c94ce9fb468520275223c153574b00df6fe4bcc9
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@c94ce9fb468520275223c153574b00df6fe4bcc9
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
trigger-L1:
permissions:
contents: read
packages: read
needs: [build_docker, build_project]
uses: ./.github/workflows/L1-tests.yml
with:
image_tag: ${{ needs.build_docker.outputs.image_tag }}
trigger-L2:
permissions:
contents: read
packages: read
needs: [build_docker, build_project]
uses: ./.github/workflows/L2-tests.yml
with:
image_tag: ${{ needs.build_docker.outputs.image_tag }}
protocol: ${{ github.event.inputs.protocol || 'rpc_v2' }}
coverage_gate:
name: Coverage Gate
needs: [trigger-L1, trigger-L2]
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: artifacts-L1-client
path: ./unit-coverage
- name: Download component test coverage artifact
continue-on-error: true
uses: actions/download-artifact@v4
with:
name: artifacts-L2-client
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.trigger-L1.result == 'success' &&
needs.trigger-L2.result == 'success'
needs: [trigger-L1, trigger-L2]
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: artifacts-L1-client
path: ./unit-coverage
- name: Download component test coverage artifact
uses: actions/download-artifact@v4
with:
name: artifacts-L2-client
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