Skip to content

Commit 8119fdb

Browse files
committed
Add code coverage reporting
Assisted-by: Cursor
1 parent 894a75f commit 8119fdb

2 files changed

Lines changed: 47 additions & 2 deletions

File tree

.github/workflows/ci.yml

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,64 @@ jobs:
2525
diffutils \
2626
xmlto \
2727
libpcre2-dev \
28-
gnulib
28+
gnulib \
29+
lcov
2930
3031
- name: Bootstrap
3132
run: ./bootstrap
3233

3334
- name: Configure
3435
run: |
3536
./configure \
36-
--with-pcre2
37+
--with-pcre2 \
38+
CFLAGS="--coverage -g -O0" \
39+
LDFLAGS="--coverage"
3740
3841
- name: Build
3942
run: make -j$(nproc)
4043

4144
- name: Run tests
4245
run: make check
4346

47+
- name: Generate coverage report
48+
run: |
49+
# Create coverage directory
50+
mkdir -p coverage
51+
52+
# Capture coverage data with geninfo options to handle warnings
53+
lcov --capture --directory . --output-file coverage/coverage.info --rc geninfo_unexecuted_blocks=1
54+
55+
# Remove coverage data for system headers, lib files, and test files
56+
lcov --remove coverage/coverage.info '/usr/*' '*/lib/*' '*/tests/*' --output-file coverage/coverage_filtered.info --ignore-errors unused
57+
58+
# Generate HTML report
59+
genhtml coverage/coverage_filtered.info --output-directory coverage/html
60+
61+
# Generate summary for CI and extract coverage percentage
62+
lcov --summary coverage/coverage_filtered.info > coverage/summary.txt
63+
64+
# Extract coverage percentage for badge
65+
COVERAGE=$(grep -o 'lines......: [0-9.]*%' coverage/summary.txt | grep -o '[0-9.]*')
66+
echo "COVERAGE_PERCENT=$COVERAGE" >> $GITHUB_ENV
67+
echo "Coverage: $COVERAGE%"
68+
69+
- name: Create coverage badge
70+
if: github.ref == 'refs/heads/master' && github.event_name == 'push' && secrets.GIST_ID != ''
71+
uses: schneegans/dynamic-badges-action@v1.7.0
72+
with:
73+
auth: ${{ secrets.GITHUB_TOKEN }}
74+
gistID: ${{ secrets.GIST_ID }}
75+
filename: patchutils-coverage.json
76+
label: coverage
77+
message: ${{ env.COVERAGE_PERCENT }}%
78+
color: ${{ env.COVERAGE_PERCENT > 80 && 'brightgreen' || env.COVERAGE_PERCENT > 60 && 'yellow' || 'red' }}
79+
80+
- name: Upload coverage reports
81+
uses: actions/upload-artifact@v4
82+
with:
83+
name: coverage-report
84+
path: coverage/
85+
4486
- name: Show test results on failure
4587
if: failure()
4688
run: |

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Patchutils
22

3+
[![CI](https://github.com/twaugh/patchutils/actions/workflows/ci.yml/badge.svg)](https://github.com/twaugh/patchutils/actions/workflows/ci.yml)
4+
[![Coverage](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/twaugh/bb6c2090db1f9d5af4689a0d9affdc02/raw/patchutils-coverage.json)](https://github.com/twaugh/patchutils/actions/workflows/ci.yml)
5+
36
A collection of tools that operate on patch files.
47

58
## Overview

0 commit comments

Comments
 (0)