2021-02-26 11:43:58 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
import csv
|
2024-03-11 12:07:39 +00:00
|
|
|
import logging
|
|
|
|
import os
|
2021-02-26 11:43:58 +00:00
|
|
|
|
|
|
|
|
2023-01-03 22:47:46 +00:00
|
|
|
# TODO: add typing and log files to the fourth column, think about launching
|
|
|
|
# everything from the python and not bash
|
2021-02-26 11:43:58 +00:00
|
|
|
def process_result(result_folder):
|
|
|
|
status = "success"
|
|
|
|
description = ""
|
|
|
|
test_results = []
|
2022-02-03 16:59:29 +00:00
|
|
|
checks = (
|
2024-03-20 16:50:40 +00:00
|
|
|
# "duplicate includes", # disabled in favor of clang-tidy
|
2024-03-12 09:50:44 +00:00
|
|
|
"shellcheck",
|
2022-11-29 13:08:04 +00:00
|
|
|
"style",
|
2024-03-09 20:38:23 +00:00
|
|
|
"pylint",
|
2024-03-11 12:07:39 +00:00
|
|
|
"black",
|
2023-12-29 13:51:24 +00:00
|
|
|
"flake8",
|
2022-11-29 14:48:52 +00:00
|
|
|
"mypy",
|
2022-11-29 13:08:04 +00:00
|
|
|
"typos",
|
|
|
|
"whitespaces",
|
|
|
|
"workflows",
|
2022-12-19 16:29:54 +00:00
|
|
|
"submodules",
|
2022-12-01 13:06:17 +00:00
|
|
|
"docs spelling",
|
2022-02-03 16:59:29 +00:00
|
|
|
)
|
|
|
|
|
2022-11-29 13:08:04 +00:00
|
|
|
for name in checks:
|
|
|
|
out_file = name.replace(" ", "_") + "_output.txt"
|
2022-02-03 16:59:29 +00:00
|
|
|
full_path = os.path.join(result_folder, out_file)
|
|
|
|
if not os.path.exists(full_path):
|
2024-03-11 08:45:58 +00:00
|
|
|
test_results.append((f"Check {name}", "SKIPPED"))
|
2022-02-03 16:59:29 +00:00
|
|
|
elif os.stat(full_path).st_size != 0:
|
2024-03-11 12:07:39 +00:00
|
|
|
with open(full_path, "r") as file:
|
2024-03-11 09:55:13 +00:00
|
|
|
lines = file.readlines()
|
|
|
|
if len(lines) > 100:
|
2024-03-11 12:07:39 +00:00
|
|
|
lines = lines[:100] + ["====TRIMMED===="]
|
2024-03-11 09:55:13 +00:00
|
|
|
content = "\n".join(lines)
|
2022-02-03 16:59:29 +00:00
|
|
|
description += f"Check {name} failed. "
|
2024-03-11 09:55:13 +00:00
|
|
|
test_results.append((f"Check {name}", "FAIL", None, content))
|
2022-02-03 16:59:29 +00:00
|
|
|
status = "failure"
|
|
|
|
else:
|
|
|
|
test_results.append((f"Check {name}", "OK"))
|
2021-02-26 11:43:58 +00:00
|
|
|
|
|
|
|
if not description:
|
|
|
|
description += "Style check success"
|
|
|
|
|
2024-03-11 08:45:58 +00:00
|
|
|
assert test_results, "No single style-check output found"
|
|
|
|
|
2021-02-26 11:43:58 +00:00
|
|
|
return status, description, test_results
|
|
|
|
|
|
|
|
|
|
|
|
def write_results(results_file, status_file, results, status):
|
2022-07-19 11:31:43 +00:00
|
|
|
with open(results_file, "w", encoding="utf-8") as f:
|
2022-01-13 19:59:36 +00:00
|
|
|
out = csv.writer(f, delimiter="\t")
|
2021-02-26 11:43:58 +00:00
|
|
|
out.writerows(results)
|
2022-07-19 11:31:43 +00:00
|
|
|
with open(status_file, "w", encoding="utf-8") as f:
|
2022-01-13 19:59:36 +00:00
|
|
|
out = csv.writer(f, delimiter="\t")
|
2021-02-26 11:43:58 +00:00
|
|
|
out.writerow(status)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2022-01-13 19:59:36 +00:00
|
|
|
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(message)s")
|
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
description="ClickHouse script for parsing results of style check"
|
|
|
|
)
|
2022-07-19 11:31:43 +00:00
|
|
|
default_dir = "/test_output"
|
|
|
|
parser.add_argument("--in-results-dir", default=default_dir)
|
|
|
|
parser.add_argument("--out-results-file", default=f"{default_dir}/test_results.tsv")
|
|
|
|
parser.add_argument("--out-status-file", default=f"{default_dir}/check_status.tsv")
|
2021-02-26 11:43:58 +00:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
state, description, test_results = process_result(args.in_results_dir)
|
|
|
|
logging.info("Result parsed")
|
|
|
|
status = (state, description)
|
|
|
|
write_results(args.out_results_file, args.out_status_file, test_results, status)
|
|
|
|
logging.info("Result written")
|