Skip to content

Commit 85a8f62

Browse files
committed
Add coverage in action summary
1 parent 381984b commit 85a8f62

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

.github/workflows/ci.yml

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ jobs:
1313
run: make dev-install
1414
- name: Run tests
1515
run: make test
16+
- name: Report
17+
run: |
18+
python .github/workflows/get_markdown.py .coverage.xml 90
1619
1720
check:
1821
runs-on: ubuntu-20.04

.github/workflows/get_markdown.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import os
2+
import re
3+
import sys
4+
import xml.dom.minidom
5+
6+
if len(sys.argv)<3:
7+
print("Not enough parameters")
8+
sys.exit(-1)
9+
10+
with open(os.environ['GITHUB_STEP_SUMMARY'], 'a') as fh:
11+
print("| File | Coverage | |", file=fh)
12+
print("|---------------|:--------:|:------------------:|", file=fh)
13+
14+
min_perc = int(sys.argv[2])
15+
16+
with open(sys.argv[1], "r") as f:
17+
xml_doc = xml.dom.minidom.parse(f)
18+
perc_total = int(round(float(xml_doc.documentElement.getAttribute('line-rate'))*1000))
19+
sign_total = ":white_check_mark:" if (perc_total>=(min_perc*10)) else ":x:"
20+
print(f"| **All files** | `{perc_total/10}%` | {sign_total} |", file=fh)
21+
22+
for cl in xml_doc.getElementsByTagName('class'):
23+
perc = int(round(float(cl.getAttribute('line-rate'))*1000))
24+
sign = ":white_check_mark:" if (perc>=(min_perc*10)) else ":x:"
25+
escape_chars = r'_*[]()~`>#+-=|{}.!'
26+
text = re.sub(f'([{re.escape(escape_chars)}])', r'\\\1', cl.getAttribute('filename'))
27+
print(f"| {text} | `{perc/10}%` | {sign} |", file=fh)
28+
29+
print("", file=fh)
30+
if (perc_total<min_perc):
31+
print("**Minimum coverage requirement was not satisfied**", file=fh)
32+
sys.exit(-1)

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ docs-%:
4646

4747
test:
4848
$(PYTHON) -m pytest \
49-
--cov-report html --cov-report term \
49+
--cov-report html --cov-report xml:.coverage.xml --cov-report term \
5050
--cov yosys_mau \
5151
-n auto -q $(O)
5252

@@ -71,4 +71,4 @@ dev-install:
7171
ci: formatting lint typecheck test docs-html
7272

7373
clean: docs-clean
74-
rm -rf .coverage .pytest_cache .mypy_cache .ruff_cache htmlcov
74+
rm -rf .coverage .pytest_cache .mypy_cache .ruff_cache htmlcov .coverage.xml

0 commit comments

Comments
 (0)