Skip to content

Commit

Permalink
Use github action summary to store coverage results
Browse files Browse the repository at this point in the history
  • Loading branch information
mmicko committed Apr 16, 2024
1 parent 622dbea commit 9063c45
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
8 changes: 2 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,5 @@ jobs:
- name: Report
if: (github.event_name != 'schedule')
uses: 5monkeys/cobertura-action@master
with:
path: coverage.xml
minimum_coverage: 90
skip_covered: false
fail_below_threshold: true
run: |
python3 .github/workflows/get_markdown.py coverage.xml 90
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)

0 comments on commit 9063c45

Please sign in to comment.