Skip to content

Commit

Permalink
Merge pull request #16 from mmicko/mmicko/summary
Browse files Browse the repository at this point in the history
Add coverage in action summary
  • Loading branch information
jix authored Apr 16, 2024
2 parents 381984b + 85a8f62 commit fb93dd9
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ jobs:
run: make dev-install
- name: Run tests
run: make test
- name: Report
run: |
python .github/workflows/get_markdown.py .coverage.xml 90
check:
runs-on: ubuntu-20.04
Expand Down
32 changes: 32 additions & 0 deletions .github/workflows/get_markdown.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import os
import re
import sys
import xml.dom.minidom

if len(sys.argv)<3:
print("Not enough parameters")
sys.exit(-1)

with open(os.environ['GITHUB_STEP_SUMMARY'], 'a') as fh:
print("| File | Coverage | |", file=fh)
print("|---------------|:--------:|:------------------:|", file=fh)

min_perc = int(sys.argv[2])

with open(sys.argv[1], "r") as f:
xml_doc = xml.dom.minidom.parse(f)
perc_total = int(round(float(xml_doc.documentElement.getAttribute('line-rate'))*1000))
sign_total = ":white_check_mark:" if (perc_total>=(min_perc*10)) else ":x:"
print(f"| **All files** | `{perc_total/10}%` | {sign_total} |", file=fh)

for cl in xml_doc.getElementsByTagName('class'):
perc = int(round(float(cl.getAttribute('line-rate'))*1000))
sign = ":white_check_mark:" if (perc>=(min_perc*10)) else ":x:"
escape_chars = r'_*[]()~`>#+-=|{}.!'
text = re.sub(f'([{re.escape(escape_chars)}])', r'\\\1', cl.getAttribute('filename'))
print(f"| {text} | `{perc/10}%` | {sign} |", file=fh)

print("", file=fh)
if (perc_total<min_perc):
print("**Minimum coverage requirement was not satisfied**", file=fh)
sys.exit(-1)
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ docs-%:

test:
$(PYTHON) -m pytest \
--cov-report html --cov-report term \
--cov-report html --cov-report xml:.coverage.xml --cov-report term \
--cov yosys_mau \
-n auto -q $(O)

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

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

0 comments on commit fb93dd9

Please sign in to comment.