Skip to content

Commit 4e40859

Browse files
Added Github PR Comment for Coverage
1 parent 20dba6b commit 4e40859

1 file changed

Lines changed: 68 additions & 0 deletions

File tree

.github/workflows/coverage.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,72 @@ jobs:
6767
out/coverage/coverage/coverage.xml
6868
out/coverage/coverage/html
6969
retention-days: 30
70+
71+
- name: Extract coverage summaries
72+
id: cov
73+
shell: bash
74+
run: |
75+
set -euo pipefail
76+
77+
# --- LCOV summary ---
78+
LCOV_SUMMARY="$(lcov --summary out/coverage/coverage/lcov_final.info 2>/dev/null || true)"
79+
80+
LCOV_LINES_PCT="$(echo "$LCOV_SUMMARY" | awk -F'[:()%]' '/lines\.*:/{gsub(/ /,"",$0); print $3}' | head -n1)"
81+
LCOV_LINES_COVERED="$(echo "$LCOV_SUMMARY" | awk -F'[()]' '/lines\.*:/{print $2}' | awk '{print $1}' | head -n1)"
82+
LCOV_LINES_TOTAL="$(echo "$LCOV_SUMMARY" | awk -F'[()]' '/lines\.*:/{print $2}' | awk '{print $3}' | head -n1)"
83+
84+
LCOV_FUNCS_PCT="$(echo "$LCOV_SUMMARY" | awk -F'[:()%]' '/functions\.*:/{gsub(/ /,"",$0); print $3}' | head -n1)"
85+
LCOV_FUNCS_COVERED="$(echo "$LCOV_SUMMARY" | awk -F'[()]' '/functions\.*:/{print $2}' | awk '{print $1}' | head -n1)"
86+
LCOV_FUNCS_TOTAL="$(echo "$LCOV_SUMMARY" | awk -F'[()]' '/functions\.*:/{print $2}' | awk '{print $3}' | head -n1)"
87+
88+
# --- Cobertura XML (gcovr) ---
89+
python3 - <<'PY'
90+
import xml.etree.ElementTree as ET
91+
p="out/coverage/coverage/coverage.xml"
92+
root=ET.parse(p).getroot()
93+
lr=float(root.attrib.get("line-rate","0"))*100
94+
br=float(root.attrib.get("branch-rate","0"))*100
95+
lc=int(root.attrib.get("lines-covered","0"))
96+
lv=int(root.attrib.get("lines-valid","0"))
97+
bc=int(root.attrib.get("branches-covered","0"))
98+
bv=int(root.attrib.get("branches-valid","0"))
99+
print(f"COB_LINES_PCT={lr:.1f}")
100+
print(f"COB_BRANCH_PCT={br:.1f}")
101+
print(f"COB_LINES={lc}/{lv}")
102+
print(f"COB_BRANCHES={bc}/{bv}")
103+
PY > cobertura_vars.txt
104+
105+
source cobertura_vars.txt
106+
107+
# Expose outputs to later steps
108+
{
109+
echo "lcov_lines_pct=${LCOV_LINES_PCT:-N/A}"
110+
echo "lcov_lines=${LCOV_LINES_COVERED:-?}/${LCOV_LINES_TOTAL:-?}"
111+
echo "lcov_funcs_pct=${LCOV_FUNCS_PCT:-N/A}"
112+
echo "lcov_funcs=${LCOV_FUNCS_COVERED:-?}/${LCOV_FUNCS_TOTAL:-?}"
113+
echo "cob_lines_pct=${COB_LINES_PCT}"
114+
echo "cob_lines=${COB_LINES}"
115+
echo "cob_branch_pct=${COB_BRANCH_PCT}"
116+
echo "cob_branches=${COB_BRANCHES}"
117+
} >> "$GITHUB_OUTPUT"
118+
119+
- name: Create/update PR comment
120+
uses: peter-evans/create-or-update-comment@v4
121+
with:
122+
issue-number: ${{ github.event.pull_request.number }}
123+
body: |
124+
## ✅ Coverage Summary
125+
126+
**LCOV (summary):**
127+
- Lines: **${{ steps.cov.outputs.lcov_lines_pct }}%** ( ${{ steps.cov.outputs.lcov_lines }} )
128+
- Functions: **${{ steps.cov.outputs.lcov_funcs_pct }}%** ( ${{ steps.cov.outputs.lcov_funcs }} )
129+
130+
**Cobertura XML (gcovr):**
131+
- Lines: **${{ steps.cov.outputs.cob_lines_pct }}%** ( ${{ steps.cov.outputs.cob_lines }} )
132+
- Branches: **${{ steps.cov.outputs.cob_branch_pct }}%** ( ${{ steps.cov.outputs.cob_branches }} )
133+
134+
**Artifacts:** [Download coverage report (XML + HTML)](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})**
135+
136+
<sub>Note: LCOV and Cobertura often differ due to file filters and line-counting rules.</sub>
137+
edit-mode: replace
70138

0 commit comments

Comments
 (0)