-
Notifications
You must be signed in to change notification settings - Fork 12
447 lines (403 loc) · 16.8 KB
/
coverage.yaml
File metadata and controls
447 lines (403 loc) · 16.8 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
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
name: Code Coverage
run-name: "${{ github.actor }} running code coverage"
"on":
push:
branches: [main, develop]
pull_request:
issue_comment:
types: [created]
workflow_dispatch:
inputs:
ref:
description: "The branch, ref, or SHA to checkout. Defaults to the repository's default branch."
required: false
type: string
phlex-coverage-compiler:
description: "Compiler to use for coverage build (gcc or clang)"
required: false
default: "clang"
phlex-enable-form:
description: "Enable FORM integration (set to OFF to exclude FORM sources)"
required: false
default: "ON"
permissions:
contents: read
pull-requests: read
jobs:
pre-check:
if: >
github.event_name == 'workflow_dispatch' || github.event_name == 'pull_request' || github.event_name == 'push' ||
(
github.event_name == 'issue_comment' &&
github.event.issue.pull_request &&
contains(fromJSON('["OWNER", "COLLABORATOR", "MEMBER"]'), github.event.comment.author_association) &&
startsWith(github.event.comment.body, format('@{0}bot coverage', github.event.repository.name))
)
# Authorization: Only OWNER, COLLABORATOR, or MEMBER can trigger via comments.
# This covers repo owners, invited collaborators, and all org members.
runs-on: ubuntu-latest
outputs:
is_act: ${{ steps.detect_act.outputs.is_act }}
ref:
${{ (github.event_name == 'workflow_dispatch' && (github.event.inputs.ref || github.ref)) ||
steps.pr.outputs.ref || github.sha }}
repo: ${{ steps.pr.outputs.repo || github.repository }}
base_sha: ${{ steps.pr.outputs.base_sha || github.event.pull_request.base.sha || github.event.before }}
steps:
- name: Get PR Info
if: github.event_name == 'issue_comment'
id: pr
uses: Framework-R-D/phlex/.github/actions/get-pr-info@main
- name: Detect act environment
id: detect_act
uses: Framework-R-D/phlex/.github/actions/detect-act-env@main
detect-changes:
needs: pre-check
if: >
needs.pre-check.result == 'success' && github.event_name != 'workflow_dispatch' && github.event_name !=
'issue_comment' && needs.pre-check.outputs.is_act != 'true'
runs-on: ubuntu-latest
permissions:
contents: read
packages: read
outputs:
has_changes: ${{ steps.filter.outputs.matched }}
steps:
- name: Check out source code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
path: phlex-src
ref: ${{ needs.pre-check.outputs.ref }}
repository: ${{ needs.pre-check.outputs.repo }}
- name: Detect relevant changes
id: filter
uses: Framework-R-D/phlex/.github/actions/detect-relevant-changes@main
with:
repo-path: phlex-src
base-ref: ${{ needs.pre-check.outputs.base_sha }}
head-ref: ${{ needs.pre-check.outputs.ref }}
file-type: |
cpp
cmake
python
- name: Report detection outcome
run: |
if [ "${{ steps.filter.outputs.matched }}" != "true" ]; then
echo "::notice::No coverage relevant changes detected; workflow will be skipped."
else
echo "::group::Coverage relevant files"
printf '%s\n' "${{ steps.filter.outputs.matched_files }}"
echo "::endgroup::"
fi
coverage:
needs: [pre-check, detect-changes]
if: >
always() && (
needs.detect-changes.result == 'skipped' ||
(
needs.detect-changes.result == 'success' &&
needs.detect-changes.outputs.has_changes == 'true'
)
)
runs-on: ubuntu-24.04
container:
image: ghcr.io/framework-r-d/phlex-ci:latest
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
outputs:
has_coverage_xml: ${{ steps.coverage_outputs.outputs.has_coverage_xml }}
has_coverage_html: ${{ steps.coverage_outputs.outputs.has_coverage_html }}
has_coverage_llvm_info: ${{ steps.coverage_outputs.outputs.has_coverage_llvm_info }}
artifact_upload_available: ${{ steps.artifact_runtime.outputs.available }}
steps:
- name: Determine coverage options
id: coverage_options
shell: bash
# yamllint disable rule:line-length
run: |
set -euo pipefail
requested_compiler="${{ github.event_name == 'workflow_dispatch' && github.event.inputs['phlex-coverage-compiler'] || '' }}"
default_compiler="clang"
requested_form="${{ github.event_name == 'workflow_dispatch' && github.event.inputs['phlex-enable-form'] || '' }}"
default_form="ON"
compiler="${requested_compiler:-$default_compiler}"
form="${requested_form:-$default_form}"
echo "compiler=$compiler" >> "$GITHUB_OUTPUT"
echo "enable_form=$form" >> "$GITHUB_OUTPUT"
# yamllint enable
- name: Check out source code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
ref: ${{ needs.pre-check.outputs.ref }}
path: phlex-src
repository: ${{ needs.pre-check.outputs.repo }}
- name: Setup build environment
uses: Framework-R-D/phlex/.github/actions/setup-build-env@main
- name: Announce CMake configuration
run: echo "➡️ Configuring CMake for coverage..."
- name: Configure CMake with GCC coverage
id: configure_gcc
if: ${{ steps.coverage_options.outputs.compiler == 'gcc' }}
uses: Framework-R-D/phlex/.github/actions/configure-cmake@main
with:
cpp-compiler: g++
preset: coverage-gcc
enable-form: ${{ steps.coverage_options.outputs.enable_form }}
form-root-storage: ${{ steps.coverage_options.outputs.enable_form }}
- name: Configure CMake with Clang coverage
id: configure_clang
if: ${{ steps.coverage_options.outputs.compiler == 'clang' }}
uses: Framework-R-D/phlex/.github/actions/configure-cmake@main
with:
cpp-compiler: clang++
preset: coverage-clang
enable-form: ${{ steps.coverage_options.outputs.enable_form }}
form-root-storage: ${{ steps.coverage_options.outputs.enable_form }}
- name: Unknown Compiler Error
if:
${{ steps.coverage_options.outputs.compiler != 'gcc' && steps.coverage_options.outputs.compiler != 'clang' }}
run: |
echo "ERROR: Unknown compiler '${{ steps.coverage_options.outputs.compiler }}'. Must be 'gcc' or 'clang'."
exit 1
- name: Announce build
run: echo "➡️ Building with coverage instrumentation..."
- name: Build with coverage instrumentation
id: build
uses: Framework-R-D/phlex/.github/actions/build-cmake@main
- name: Run tests with coverage
run: |
. /entrypoint.sh
cd "$GITHUB_WORKSPACE/phlex-build"
echo "➡️ Running tests with coverage..."
PROFILE_ROOT="$GITHUB_WORKSPACE/phlex-build/test/profraw"
echo "Cleaning LLVM profile directory: $PROFILE_ROOT"
rm -rf "$PROFILE_ROOT"
mkdir -p "$PROFILE_ROOT"
export LLVM_PROFILE_FILE="$PROFILE_ROOT/%m-%p.profraw"
echo "::group::Running ctest for coverage"
if ctest --progress --output-on-failure -j "$(nproc)"; then
echo "::endgroup::"
echo "✅ All tests passed."
else
echo "::endgroup::"
echo "::error::Some tests failed."
exit 1
fi
- name: Generate coverage reports (GCC)
id: report_gcc
if: ${{ steps.coverage_options.outputs.compiler == 'gcc' }}
shell: bash
run: |
. /entrypoint.sh
cd "$GITHUB_WORKSPACE/phlex-build"
echo "➡️ Generating coverage reports for GCC..."
echo "::group::Running coverage-gcov target"
if cmake --build . --target coverage-gcov -v; then
echo "::endgroup::"
echo "✅ GCC coverage report generation succeeded."
else
echo "::endgroup::"
echo "::error::GCC coverage report generation failed."
exit 1
fi
- name: Generate coverage reports (Clang)
id: report_clang
if: ${{ steps.coverage_options.outputs.compiler == 'clang' }}
shell: bash
run: |
. /entrypoint.sh
cd "$GITHUB_WORKSPACE/phlex-build"
echo "➡️ Generating coverage reports for Clang..."
echo "::group::Running coverage-llvm target"
if cmake --build . --target coverage-llvm -v; then
echo "::endgroup::"
echo "✅ Clang coverage report generation succeeded."
else
echo "::endgroup::"
echo "::error::Clang coverage report generation failed."
exit 1
fi
- name: Generate Python coverage report
id: report_python
if: ${{ steps.report_gcc.outcome != 'skipped' || steps.report_clang.outcome != 'skipped' }}
shell: bash
run: |
. /entrypoint.sh
cd "$GITHUB_WORKSPACE/phlex-build"
echo "➡️ Generating Python coverage report..."
echo "::group::Running coverage-python target"
# Check if pytest-cov is available
if python3 -c "import pytest_cov" 2>/dev/null; then
if cmake --build . --target coverage-python -v; then
echo "::endgroup::"
echo "✅ Python coverage report generation succeeded."
else
echo "::endgroup::"
echo "::warning::Python coverage report generation failed (non-fatal)."
fi
else
echo "::endgroup::"
echo "::notice::pytest-cov not available; skipping Python coverage report."
fi
- name: Capture coverage artifact availability
id: coverage_outputs
if: ${{ steps.report_gcc.outcome != 'skipped' || steps.report_clang.outcome != 'skipped' }}
shell: bash
run: |
cd "$GITHUB_WORKSPACE/phlex-build"
if [ -f coverage.xml ]; then
echo "has_coverage_xml=true" >> "$GITHUB_OUTPUT"
else
echo "has_coverage_xml=false" >> "$GITHUB_OUTPUT"
fi
if [ -d coverage-html ]; then
echo "has_coverage_html=true" >> "$GITHUB_OUTPUT"
else
echo "has_coverage_html=false" >> "$GITHUB_OUTPUT"
fi
if [ -f coverage-llvm.info ]; then
echo "has_coverage_llvm_info=true" >> "$GITHUB_OUTPUT"
else
echo "has_coverage_llvm_info=false" >> "$GITHUB_OUTPUT"
fi
if [ -f coverage-python.xml ]; then
echo "has_coverage_python_xml=true" >> "$GITHUB_OUTPUT"
else
echo "has_coverage_python_xml=false" >> "$GITHUB_OUTPUT"
fi
- name: Unknown Coverage Report Error
if: ${{ steps.report_gcc.outcome == 'skipped' && steps.report_clang.outcome == 'skipped' }}
run: |
echo "ERROR: No coverage report was generated. Must run either GCC or Clang coverage report step."
exit 1
- name: Prepare coverage artifact bundle
if: ${{ steps.report_gcc.outcome != 'skipped' || steps.report_clang.outcome != 'skipped' }}
shell: bash
run: |
set -euo pipefail
ARTIFACT_DIR="$GITHUB_WORKSPACE/coverage-artifacts"
rm -rf "$ARTIFACT_DIR"
mkdir -p "$ARTIFACT_DIR"
cd "$GITHUB_WORKSPACE/phlex-build"
for file in \
coverage-llvm.txt \
coverage-llvm.info \
coverage.profdata \
coverage.xml \
coverage.info \
coverage.info.final \
coverage-python.xml; do
if [ -f "$file" ]; then
cp "$file" "$ARTIFACT_DIR/"
fi
done
if [ -d coverage-html ]; then cp -R coverage-html "$ARTIFACT_DIR/"; fi
if [ -d coverage-python-html ]; then cp -R coverage-python-html "$ARTIFACT_DIR/"; fi
- name: Detect artifact upload availability
id: artifact_runtime
if: ${{ steps.report_gcc.outcome != 'skipped' || steps.report_clang.outcome != 'skipped' }}
shell: bash
# yamllint disable rule:line-length
run: |
if [ "${GITHUB_ACTOR}" = "nektos/act" ] || [ "${ACT:-}" = "true" ]; then
echo "::notice::Artifact upload disabled for local act executions."
echo "available=false" >> "$GITHUB_OUTPUT"
elif [ -z "${ACTIONS_RUNTIME_TOKEN:-}" ]; then
echo "::warning::ACTIONS_RUNTIME_TOKEN missing; continuing and trusting actions/upload-artifact to handle authentication."
echo "available=true" >> "$GITHUB_OUTPUT"
else
echo "available=true" >> "$GITHUB_OUTPUT"
fi
# yamllint enable
- name: Install Node.js runtime for artifact publishing
if:
${{ (steps.report_gcc.outcome != 'skipped' || steps.report_clang.outcome != 'skipped') &&
steps.artifact_runtime.outputs.available == 'true' && github.actor != 'nektos/act' }}
run: |
curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
apt-get update
apt-get install -y nodejs
- name: Upload coverage bundle
if:
${{ (steps.report_gcc.outcome != 'skipped' || steps.report_clang.outcome != 'skipped') &&
steps.artifact_runtime.outputs.available == 'true' && github.actor != 'nektos/act' }}
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
with:
name: coverage-generated
path: coverage-artifacts/
retention-days: 30
coverage-upload:
needs: coverage
if:
${{ needs.coverage.result == 'success' && needs.coverage.outputs.artifact_upload_available == 'true' &&
github.actor != 'nektos/act' }}
runs-on: ubuntu-latest
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
steps:
- name: Check out source code for Codecov mapping
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
- name: Download coverage bundle
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: coverage-generated
path: coverage-artifacts
- name: Determine coverage files for Codecov
id: codecov_targets
run: |
set -euo pipefail
files=()
if [ -f coverage-artifacts/coverage.xml ]; then
files+=("coverage-artifacts/coverage.xml")
fi
if [ -f coverage-artifacts/coverage-llvm.info ]; then
files+=("coverage-artifacts/coverage-llvm.info")
fi
if [ -f coverage-artifacts/coverage-python.xml ]; then
files+=("coverage-artifacts/coverage-python.xml")
fi
ls -al coverage-artifacts || true
if [ "${#files[@]}" -eq 0 ]; then
echo "No coverage files detected; skipping Codecov upload." >&2
echo "found=false" >> "$GITHUB_OUTPUT"
echo "files=" >> "$GITHUB_OUTPUT"
else
file_csv=$(IFS=,; printf '%s' "${files[*]}")
echo "Codecov upload targets: ${files[*]}"
echo "found=true" >> "$GITHUB_OUTPUT"
echo "files=${file_csv}" >> "$GITHUB_OUTPUT"
fi
- name: Upload coverage to Codecov
if: ${{ steps.codecov_targets.outputs.found == 'true' }}
uses: codecov/codecov-action@671740ac38dd9b0130fbe1cec585b89eea48d3de # v5.5.2
with:
files: ${{ steps.codecov_targets.outputs.files }}
flags: unittests
name: phlex-coverage
fail_ci_if_error: true
verbose: true
root_dir: .
token: ${{ env.CODECOV_TOKEN }}
- name: Publish HTML coverage report
if: ${{ needs.coverage.outputs.has_coverage_html == 'true' }}
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
with:
name: coverage-html-report
path: coverage-artifacts/coverage-html/
if-no-files-found: warn
retention-days: 30
coverage-skipped:
needs: [pre-check, detect-changes]
if: >
needs.pre-check.result == 'success' && github.event_name != 'workflow_dispatch' && needs.pre-check.outputs.is_act
!= 'true' && (needs.detect-changes.result == 'success' && needs.detect-changes.outputs.has_changes != 'true')
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: No relevant coverage changes detected
run: echo "::notice::No relevant C++ changes detected; coverage workflow skipped."