-
Notifications
You must be signed in to change notification settings - Fork 0
116 lines (95 loc) · 2.79 KB
/
Copy pathcoverage.yml
File metadata and controls
116 lines (95 loc) · 2.79 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
name: "Coverage"
on:
workflow_call:
inputs:
runs-on:
type: string
required: true
levels:
description: |
Coverage grading levels.
type: string
required: true
timeout:
description: |
Timeout in minutes before the workflow is failed.
type: number
default: 3
cmake-flags:
description: |
Additional cmake flags.
type: string
default: ""
outputs:
results:
value: ${{ jobs.coverage.outputs.results }}
config:
value: ${{ inputs.levels }}
jobs:
coverage:
runs-on: ${{ inputs.runs-on }}
timeout-minutes: ${{ inputs.timeout }}
name: Coverage
outputs:
results: ${{ steps.output.outputs.results }}
verdict: ${{ steps.output.outputs.verdict }}
steps:
- uses: actions/checkout@v7
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Generate build system
run: |
cmake \
-B /tmp/cicd/build \
-DCMAKE_BUILD_TYPE=Debug \
-DWITH_COVERAGE=ON \
-DNO_COVERAGE_HTML=ON \
${{ inputs.cmake-flags }}
- name: Build tests
run: |
cmake \
--build /tmp/cicd/build \
--parallel "${JOBS:-1}"
- name: Check coverage
run: |
export CTEST_PARALLEL_LEVEL="${JOBS:-1}"
cmake \
--build /tmp/cicd/build \
--target coverage
- name: Show coverage log
run: |
cat /tmp/cicd/build/coverage.txt
- name: Save output
id: output
if: ${{ always() }}
env:
LEVELS: ${{ inputs.levels }}
shell: 'python3 {0}'
run: |
import json
from gha_helper import gh
levels = gh.input.get_json("LEVELS")
try:
with open("/tmp/cicd/build/coverage.json") as f:
coverage = json.load(f)
with open("/tmp/cicd/build/coverage.txt") as f:
coverage_log = f.read()
percent = coverage["line_percent"]
verdict = "pass" if percent >= levels[1] else "fail"
print(f"\nCoverage: {percent}%")
print(f"Verdict: {verdict}")
gh.output.save("verdict", verdict)
gh.output.save_json("results", {
"ran": True,
"percent": percent,
"log": coverage_log,
})
except FileNotFoundError:
print("\nVerdict: fail (coverage did not run)")
gh.output.save("verdict", "fail")
gh.output.save_json("results", {
"ran": False
})
- name: Fail the workflow
if: ${{ steps.output.outputs.verdict != 'pass' }}
run: exit 1