musichoard/.gitea/scripts/coverage.py
Wojciech Kozlowski 115373667f
Some checks failed
Cargo CI / Lint (pull_request) Successful in 1m0s
Cargo CI / Build and Test (pull_request) Failing after 1m17s
Add some helpful messages to coverage script
2024-01-07 10:33:21 +01:00

29 lines
950 B
Python

import argparse
import json
import sys
def main(coverage_file, fail_under):
with open(coverage_file, encoding="utf-8") as f:
coverage_json = json.load(f)
coverage = float(coverage_json["message"][:-1])
print(f"Code coverage: {coverage:.2f}%; Threshold: {fail_under:.2f}%")
success = coverage >= fail_under
if coverage < fail_under:
print("Insufficient code coverage", file=sys.stderr)
return success
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Check coverage output by grcov")
parser.add_argument("--coverage-file", type=str, required=True,
help="Path to the coverage.json file output by grcov")
parser.add_argument("--fail-under", type=float, default=100.,
help="Threshold under which coverage is insufficient")
args = parser.parse_args()
if not main(args.coverage_file, args.fail_under):
exit(2)