mirror of
https://github.com/zama-ai/concrete.git
synced 2026-02-09 12:15:09 -05:00
build(coverage): add comment to PR with diff-cover output
- add script to help format the coverage comment - manage steps logic refs #15
This commit is contained in:
19
script/actions_utils/coverage.sh
Normal file
19
script/actions_utils/coverage.sh
Normal file
@@ -0,0 +1,19 @@
|
||||
CURR_DIR=`dirname $0`
|
||||
|
||||
# Run diff-coverage
|
||||
poetry run diff-cover coverage.xml --fail-under 100 \
|
||||
--html-report coverage.html \
|
||||
--compare-branch origin/"$1" | tee diff-coverage.txt
|
||||
|
||||
# Get exit code without closing the script
|
||||
TEST_EXIT_CODE="$?"
|
||||
|
||||
# Format diff-coverage.txt for PR comment
|
||||
poetry run python script/actions_utils/coverage_report_format.py \
|
||||
--diff-cover-exit-code "$TEST_EXIT_CODE" \
|
||||
--diff-cover-output diff-coverage.txt
|
||||
|
||||
# Set exit code if test failed
|
||||
if [[ "$TEST_EXIT_CODE" != "0" ]]; then
|
||||
exit "$TEST_EXIT_CODE"
|
||||
fi
|
||||
45
script/actions_utils/coverage_report_format.py
Executable file
45
script/actions_utils/coverage_report_format.py
Executable file
@@ -0,0 +1,45 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""Helper script for github actions"""
|
||||
import argparse
|
||||
import traceback
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def main(args):
|
||||
"""Entry point"""
|
||||
diff_cover_file_path = Path(args.diff_cover_output).resolve().absolute()
|
||||
|
||||
diff_cover_content = None
|
||||
|
||||
with open(diff_cover_file_path, "r") as f:
|
||||
diff_cover_content = f.readlines()
|
||||
|
||||
with open(diff_cover_file_path, "w", encoding="utf-8") as f:
|
||||
if args.diff_cover_exit_code == 0:
|
||||
f.write("## Coverage passed ✅\n\n")
|
||||
else:
|
||||
f.write("## Coverage failed ❌\n\n")
|
||||
|
||||
# Open collapsible section
|
||||
f.write("<details><summary>Coverage details</summary>\n<p>\n\n")
|
||||
f.write("```\n")
|
||||
|
||||
f.writelines(diff_cover_content)
|
||||
|
||||
# Close collapsible section
|
||||
f.write("```\n\n")
|
||||
f.write("</p>\n</details>\n\n")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(allow_abbrev=False)
|
||||
|
||||
parser.add_argument("--diff-cover-exit-code", type=int, required=True)
|
||||
parser.add_argument("--diff-cover-output", type=str, required=True)
|
||||
|
||||
cli_args = parser.parse_args()
|
||||
try:
|
||||
main(cli_args)
|
||||
except Exception as e:
|
||||
traceback.print_exc()
|
||||
Reference in New Issue
Block a user