diff --git a/Makefile b/Makefile index a7ed6f5..a730cfb 100644 --- a/Makefile +++ b/Makefile @@ -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' ; \ diff --git a/README.md b/README.md index 320bce6..60f8b4b 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/update_coverage.py b/update_coverage.py new file mode 100644 index 0000000..126e4d8 --- /dev/null +++ b/update_coverage.py @@ -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)