ClickHouse/tests/ci/bugfix_validate_check.py

97 lines
2.5 KiB
Python
Raw Normal View History

2022-03-18 12:36:45 +00:00
#!/usr/bin/env python3
import argparse
import csv
import itertools
import logging
2022-03-18 12:36:45 +00:00
import os
2022-10-27 11:32:42 +00:00
from github import Github
from s3_helper import S3Helper
from get_robot_token import get_best_robot_token
from pr_info import PRInfo
from upload_result_helper import upload_results
from commit_status_helper import post_commit_status
2022-03-18 12:36:45 +00:00
def parse_args():
parser = argparse.ArgumentParser()
2022-10-27 11:32:42 +00:00
parser.add_argument("status", nargs="+", help="Path to status file")
2022-03-18 12:36:45 +00:00
return parser.parse_args()
def post_commit_status_from_file(file_path):
res = []
with open(file_path, "r", encoding="utf-8") as f:
fin = csv.reader(f, delimiter="\t")
2022-03-18 12:36:45 +00:00
res = list(itertools.islice(fin, 1))
if len(res) < 1:
raise Exception(f'Can\'t read from "{file_path}"')
if len(res[0]) != 3:
raise Exception(f'Can\'t read from "{file_path}"')
return res[0]
2022-10-27 15:11:16 +00:00
def process_result(file_path):
2022-10-27 11:32:42 +00:00
test_results = []
2022-03-18 12:36:45 +00:00
state, report_url, description = post_commit_status_from_file(file_path)
prefix = os.path.basename(os.path.dirname(file_path))
2022-10-27 13:06:37 +00:00
is_ok = state == "success"
if is_ok and report_url == "null":
return is_ok, None
2022-10-27 13:06:37 +00:00
status = f'OK: Bug reproduced (<a href="{report_url}">Report</a>)'
2022-10-27 16:51:11 +00:00
if not is_ok:
status = f'Bug is not reproduced (<a href="{report_url}">Report</a>)'
test_results.append([f"{prefix}: {description}", status])
2022-10-27 13:06:37 +00:00
return is_ok, test_results
2022-03-18 12:36:45 +00:00
2022-10-27 15:11:16 +00:00
def process_all_results(file_paths):
2022-10-27 16:51:11 +00:00
any_ok = False
2022-10-27 11:32:42 +00:00
all_results = []
2022-10-27 15:11:16 +00:00
for status_path in file_paths:
is_ok, test_results = process_result(status_path)
2022-10-27 16:51:11 +00:00
any_ok = any_ok or is_ok
if test_results is not None:
all_results.extend(test_results)
2022-10-27 16:51:11 +00:00
return any_ok, all_results
2022-10-27 15:11:16 +00:00
2022-10-27 11:32:42 +00:00
2022-10-27 15:11:16 +00:00
def main(args):
logging.basicConfig(level=logging.INFO)
2022-10-27 11:32:42 +00:00
check_name_with_group = "Bugfix validate check"
2022-10-27 15:11:16 +00:00
is_ok, test_results = process_all_results(args.status)
if not test_results:
logging.info("No results to upload")
return
2022-10-27 11:32:42 +00:00
pr_info = PRInfo()
report_url = upload_results(
S3Helper(),
pr_info.number,
pr_info.sha,
2022-10-27 15:11:16 +00:00
test_results,
2022-10-27 11:32:42 +00:00
[],
check_name_with_group,
)
gh = Github(get_best_robot_token(), per_page=100)
post_commit_status(
gh,
pr_info.sha,
check_name_with_group,
2022-10-27 13:06:37 +00:00
"" if is_ok else "Changed tests doesn't reproduce the bug",
2022-10-27 11:32:42 +00:00
"success" if is_ok else "error",
report_url,
)
2022-03-18 12:36:45 +00:00
if __name__ == "__main__":
2022-03-18 12:36:45 +00:00
main(parse_args())