Create coverage badge

This commit is contained in:
Ricardo Montañana Gómez 2024-04-08 11:24:25 +02:00
parent 50543e7929
commit a8fc29e2b2
Signed by: rmontanana
GPG Key ID: 46064262FD9A7ADE
3 changed files with 35 additions and 3 deletions

View File

@ -1,6 +1,6 @@
SHELL := /bin/bash
.DEFAULT_GOAL := help
.PHONY: viewcoverage coverage setup help install uninstall buildr buildd test clean debug release sample
.PHONY: viewcoverage coverage setup help install uninstall buildr buildd test clean debug release sample updatebadge
f_release = build_release
f_debug = build_debug
@ -103,6 +103,7 @@ coverage: ## Run tests and generate coverage report (build/index.html)
viewcoverage: ## Run tests, generate coverage report and upload it to codecov (build/index.html)
@echo ">>> Building tests with coverage..."
@folder=`pwd` ;
@$(MAKE) coverage
@echo ">>> Building report..."
@cd $(f_debug)/tests; \
@ -112,10 +113,15 @@ viewcoverage: ## Run tests, generate coverage report and upload it to codecov (b
lcov --remove coverage.info 'libtorch/*' --output-file coverage.info >/dev/null 2>&1; \
lcov --remove coverage.info 'tests/*' --output-file coverage.info >/dev/null 2>&1; \
lcov --remove coverage.info 'bayesnet/utils/loguru.*' --output-file coverage.info >/dev/null 2>&1; \
genhtml coverage.info --output-directory $(f_debug)/tests/coverage >/dev/null 2>&1; \
xdg-open $(f_debug)/tests/coverage/index.html || open $(f_debug)/tests/coverage/index.html 2>/dev/null
genhtml coverage.info --output-directory $(f_debug)/tests/coverage >/dev/null 2>&1;
@$(MAKE) updatebadge
@xdg-open $(f_debug)/tests/coverage/index.html || open $(f_debug)/tests/coverage/index.html 2>/dev/null
@echo ">>> Done";
updatebadge: ## Update the coverage badge in README.md
@echo ">>> Updating coverage badge..."
@env python update_coverage.py $(f_debug)/tests
@echo ">>> Done";
help: ## Show help message
@IFS=$$'\n' ; \

View File

@ -5,6 +5,7 @@
![Gitea Release](https://img.shields.io/gitea/v/release/rmontanana/bayesnet?gitea_url=https://gitea.rmontanana.es:3000)
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/cf3e0ac71d764650b1bf4d8d00d303b1)](https://app.codacy.com/gh/Doctorado-ML/BayesNet/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
![Gitea Last Commit](https://img.shields.io/gitea/last-commit/rmontanana/bayesnet?gitea_url=https://gitea.rmontanana.es:3000&logo=gitea)
![Static Badge](https://img.shields.io/badge/Coverage-92,4%25-green)
Bayesian Network Classifiers using libtorch from scratch

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)