Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add coverage in action summary #16

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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