-
Notifications
You must be signed in to change notification settings - Fork 0
220 lines (191 loc) · 7.86 KB
/
Copy pathcoverage.yml
File metadata and controls
220 lines (191 loc) · 7.86 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
name: coverage
true:
push:
branches:
- prerelease
pull_request:
branches:
- prerelease
jobs:
coverage-linux:
strategy:
fail-fast: false
matrix:
include:
- arch: x86_64
runner: ubuntu-latest
- arch: aarch64
runner: ubuntu-24.04-arm
runs-on: ${{ matrix.runner }}
steps:
- uses: actions/checkout@v4
- name: Install dependencies
run: 'sudo apt-get update
sudo apt-get install -y lcov cmake build-essential
'
- name: Configure
run: 'cmake -S . -B build -DENABLE_COVERAGE=ON
'
- name: Build
run: cmake --build build
- name: Test
run: ctest --test-dir build --output-on-failure
- name: Generate coverage report
run: 'lcov --capture --directory build --output-file coverage.info
lcov --ignore-errors unused --remove coverage.info ''/usr/*'' --output-file
coverage.info
genhtml coverage.info --output-directory docs/coverage --title "yafl Code
Coverage"
'
- name: Generate coverage badge
run: 'chmod +x scripts/make_coverage_badge.sh
scripts/make_coverage_badge.sh docs/coverage_linux_${{ matrix.arch }}.svg
coverage.info
'
- name: Upload Coverage Artifacts
uses: actions/upload-artifact@v4
with:
name: coverage-linux-${{ matrix.arch }}
path: 'docs/coverage
docs/coverage_linux_${{ matrix.arch }}.svg
'
coverage-windows:
strategy:
fail-fast: false
matrix:
include:
- arch: x86_64
runner: windows-latest
cmake_arch: x64
runs-on: ${{ matrix.runner }}
steps:
- uses: actions/checkout@v4
- name: Install OpenCppCoverage
run: 'choco install opencppcoverage
echo "C:\Program Files (x86)\OpenCppCoverage" | Out-File -FilePath $env:GITHUB_PATH
-Encoding utf8 -Append
'
- name: Configure
run: cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug -A ${{ matrix.cmake_arch
}}
- name: Build
run: cmake --build build --config Debug
- name: Generate Coverage Report
run: "# Find OpenCppCoverage installation\n$opencppcoverage = Get-ChildItem\
\ -Path \"C:\\Program Files*\" -Recurse -Filter \"OpenCppCoverage.exe\"\
\ -ErrorAction SilentlyContinue | Select-Object -First 1\nif (-not $opencppcoverage)\
\ {\n Write-Error \"OpenCppCoverage.exe not found\"\n exit 1\n}\nWrite-Host\
\ \"Using OpenCppCoverage from: $($opencppcoverage.FullName)\"\n& $opencppcoverage.FullName\
\ --sources \"${{ github.workspace }}\" --cover_children --export_type=html:build/coverage_report\
\ --export_type=cobertura:build/cobertura.xml -- ctest --test-dir build\
\ -C Debug --output-on-failure\n"
shell: pwsh
- name: Generate Coverage Badge
shell: powershell
run: "if (-Not (Test-Path build/cobertura.xml)) { Write-Error \"Cobertura\
\ XML not found\"; exit 1 }\n[xml]$xml = Get-Content build/cobertura.xml\n\
$rate = $xml.coverage.'line-rate'\n$percentage = [math]::Round([double]$rate\
\ * 100)\n\nif ($percentage -ge 90) { $color = \"brightgreen\" }\nelseif\
\ ($percentage -ge 75) { $color = \"yellow\" }\nelse { $color = \"red\"\
\ }\n\n$svg = @\"\n<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"120\"\
\ height=\"20\">\n <linearGradient id=\"b\" x2=\"0\" y2=\"100%\">\n \
\ <stop offset=\"0\" stop-color=\"#bbb\" stop-opacity=\".1\"/>\n <stop\
\ offset=\"1\" stop-opacity=\".1\"/>\n </linearGradient>\n <mask id=\"\
a\">\n <rect width=\"120\" height=\"20\" rx=\"3\" fill=\"#fff\"/>\n \
\ </mask>\n <g mask=\"url(#a)\">\n <rect width=\"70\" height=\"20\"\
\ fill=\"#555\"/>\n <rect x=\"70\" width=\"50\" height=\"20\" fill=\"\
$color\"/>\n <rect width=\"120\" height=\"20\" fill=\"url(#b)\"/>\n \
\ </g>\n <g fill=\"#fff\" text-anchor=\"middle\"\n font-family=\"DejaVu\
\ Sans,Verdana,Geneva,sans-serif\"\n font-size=\"11\">\n <text x=\"\
35\" y=\"14\">coverage</text>\n <text x=\"95\" y=\"14\">${percentage}%</text>\n\
\ </g>\n</svg>\n\"@\n\nNew-Item -ItemType Directory -Force -Path docs\n\
$badgePath = \"docs/coverage_windows_${{ matrix.arch }}.svg\"\nSet-Content\
\ -Path $badgePath -Value $svg\nif (Test-Path $badgePath) {\n Write-Host\
\ \"Badge created: $badgePath (${percentage}% coverage)\"\n Get-Content\
\ $badgePath | Select-Object -First 5\n} else {\n Write-Error \"Failed\
\ to create badge file\"\n exit 1\n}\n"
- name: Upload Coverage Report
uses: actions/upload-artifact@v4
with:
name: coverage-windows-${{ matrix.arch }}
path: 'build/coverage_report
docs/coverage_windows_${{ matrix.arch }}.svg
'
coverage-macos:
strategy:
fail-fast: false
matrix:
include:
- arch: x86_64
runner: macos-15-intel
cmake_arch: x86_64
- arch: aarch64
runner: macos-latest
cmake_arch: arm64
runs-on: ${{ matrix.runner }}
steps:
- uses: actions/checkout@v4
- name: Install dependencies
run: brew install lcov
- name: Configure
run: "cmake -S . -B build \\\n -DENABLE_COVERAGE=ON \\\n -DCMAKE_BUILD_TYPE=Debug\
\ \\\n -DCMAKE_OSX_ARCHITECTURES=${{ matrix.cmake_arch }}\n"
- name: Build
run: cmake --build build
- name: Test
run: ctest --test-dir build --output-on-failure
- name: Create gcov wrapper
run: 'cat > /usr/local/bin/llvm-gcov << ''EOF''
#!/bin/bash
exec xcrun llvm-cov gcov "$@"
EOF
chmod +x /usr/local/bin/llvm-gcov
'
- name: Generate Coverage Report
run: 'lcov --gcov-tool llvm-gcov --capture --directory build --output-file
coverage.info
lcov --gcov-tool llvm-gcov --ignore-errors unused --remove coverage.info
''/usr/*'' --output-file coverage.info
genhtml coverage.info --output-directory docs/coverage --title "yafl Code
Coverage"
'
- name: Generate Coverage Badge
run: 'chmod +x scripts/make_coverage_badge.sh
scripts/make_coverage_badge.sh docs/coverage_macos_${{ matrix.arch }}.svg
coverage.info
'
- name: Upload Coverage Report
uses: actions/upload-artifact@v4
with:
name: coverage-macos-${{ matrix.arch }}
path: 'docs/coverage
docs/coverage_macos_${{ matrix.arch }}.svg
'
commit-badges:
needs:
- coverage-linux
- coverage-macos
- coverage-windows
runs-on: ubuntu-latest
if: always() && github.event_name == 'push' && github.ref == 'refs/heads/prerelease'
steps:
- uses: actions/checkout@v4
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Move badges
run: 'mkdir -p docs
find artifacts -name "coverage_*.svg" -exec cp {} docs/ \;
'
- name: Create GitHub Pages configuration
run: 'touch docs/.nojekyll
'
- name: Commit and push coverage badges
run: "git config user.name \"GitHub Actions\"\ngit config user.email \"actions@github.com\"\
\ngit add docs/coverage_*.svg docs/.nojekyll\nif git diff --quiet --cached;\
\ then\n echo \"No coverage badge changes to commit\"\nelse\n git commit\
\ -m \"Update code coverage badges [skip ci]\" && git push origin prerelease\n\
fi\n"
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: 'true'