@@ -13,7 +13,8 @@ concurrency:
13
13
env :
14
14
FEATURES : lzma,jpegxr
15
15
TEST_OPTS : --workspace --locked --no-fail-fast -j 4
16
- LLVM_COV_OPTS : --branch --profile ci ${TEST_OPTS} --features ${FEATURES},imgtests
16
+ LLVM_COV_OPTS : --branch --profile ci
17
+ LLVM_COV_TEST_OPTS : ${LLVM_COV_OPTS} ${TEST_OPTS} --features ${FEATURES},imgtests
17
18
18
19
LINUX_DEPENDENCIES : libasound2-dev mesa-vulkan-drivers libudev-dev
19
20
@@ -163,6 +164,37 @@ jobs:
163
164
runs-on : ubuntu-24.04
164
165
steps :
165
166
- uses : actions/checkout@v5
167
+ with :
168
+ # We need history for delta coverage, but we also don't want to fetch
169
+ # the whole repo. 42 commits seem reasonable
170
+ fetch-depth : 42
171
+
172
+ - name : Set up Python
173
+ uses : actions/setup-python@v5
174
+ with :
175
+ python-version : " 3.13"
176
+
177
+ - name : Install diff-cover
178
+ run : pip install diff-cover==9.6.0
179
+
180
+ - name : Calculate base ref
181
+ id : base_ref
182
+ run : |
183
+ if [ "${{ github.event_name }}" = "pull_request" ] || [ "${{ github.event_name }}" = "pull_request_target" ]; then
184
+ # For PRs always compute delta with base ref
185
+ git fetch origin ${{ github.base_ref }}
186
+ echo "::notice::Using the PR base as base ref for delta coverage."
187
+ echo "value=origin/${{ github.base_ref }}" | tee -a $GITHUB_OUTPUT
188
+ elif git merge-base --is-ancestor ${{ github.event.before }} HEAD; then
189
+ # Use the before SHA if it's an ancestor of HEAD
190
+ echo "::notice::Using the last pushed commit as base ref for delta coverage."
191
+ echo "value=${{ github.event.before }}" | tee -a $GITHUB_OUTPUT
192
+ else
193
+ # If not, someone force pushed and just use the parent
194
+ echo "::warning::Failed to compute the base ref for delta coverage. Using parent commit."
195
+ parent=$(git rev-parse HEAD~1)
196
+ echo "value=${parent}" | tee -a $GITHUB_OUTPUT
197
+ fi
166
198
167
199
- name : Install Rust toolchain
168
200
# We need nightly for coverage due to:
@@ -192,15 +224,41 @@ jobs:
192
224
working-directory : tests
193
225
env :
194
226
RUFFLE_TEST_OPTS : --ignore-known-failures
195
- run : cargo llvm-cov --html ${{ env.LLVM_COV_OPTS }}
227
+ run : cargo llvm-cov --no-report ${{ env.LLVM_COV_TEST_OPTS }}
228
+
229
+ - name : Generate llvm-cov reports
230
+ run : |
231
+ mkdir -p target/llvm-cov
232
+ cargo llvm-cov report --html --output-dir target/llvm-cov/ ${{ env.LLVM_COV_OPTS }}
233
+ cargo llvm-cov report --lcov --output-path target/llvm-cov/coverage.lcov ${{ env.LLVM_COV_OPTS }}
196
234
197
- - name : Upload report
235
+ - name : Upload llvm-cov reports
198
236
if : always()
199
237
uses : actions/upload-artifact@v4
200
238
with :
201
239
name : llvm-cov
202
240
path : target/llvm-cov
203
241
242
+ - name : Run diff-cover
243
+ run : |
244
+ mkdir -p target/diff-cover
245
+ diff-cover target/llvm-cov/coverage.lcov \
246
+ --html-report target/diff-cover/report.html \
247
+ --json-report target/diff-cover/report.json \
248
+ --markdown-report target/diff-cover/report.md \
249
+ --compare-branch ${{ steps.base_ref.outputs.value }}
250
+
251
+ - name : Upload diff-cover reports
252
+ if : always()
253
+ uses : actions/upload-artifact@v4
254
+ with :
255
+ name : diff-cover
256
+ path : target/diff-cover
257
+
258
+ - name : Upload diff-cover summary
259
+ if : always()
260
+ run : cat target/diff-cover/report.md >> $GITHUB_STEP_SUMMARY
261
+
204
262
dependencies :
205
263
needs : changes
206
264
if : needs.changes.outputs.should_run == 'true'
0 commit comments