Create coverage badge

This commit is contained in:
2024-04-08 11:24:25 +02:00
parent 50543e7929
commit a8fc29e2b2
3 changed files with 35 additions and 3 deletions

25
update_coverage.py Normal file
View File

@@ -0,0 +1,25 @@
import subprocess
import os
import sys
readme_file = "README.md"
print("Updating coverage...")
# Generate badge line
output = subprocess.check_output(
"lcov --summary " + sys.argv[1] + "/coverage.info|cut -d' ' -f4 |head -2|"
"tail -1",
shell=True,
)
percentage = output.decode("utf-8").strip().replace(".", ",")
coverage_line = (
f"![Static Badge](https://img.shields.io/badge/Coverage-{percentage}25-green)"
)
# Update README.md
with open(readme_file, "r") as f:
lines = f.readlines()
with open(readme_file, "w") as f:
for line in lines:
if "Coverage" in line:
f.write(coverage_line + "\n")
else:
f.write(line)