2021-11-12 11:39:00 +00:00
|
|
|
import os
|
|
|
|
import logging
|
2022-11-14 17:50:31 +00:00
|
|
|
|
|
|
|
from typing import List, Tuple
|
2021-11-12 11:39:00 +00:00
|
|
|
|
2022-08-09 16:49:55 +00:00
|
|
|
from env_helper import (
|
|
|
|
GITHUB_JOB_URL,
|
|
|
|
GITHUB_REPOSITORY,
|
|
|
|
GITHUB_RUN_URL,
|
|
|
|
GITHUB_SERVER_URL,
|
|
|
|
)
|
2022-03-11 13:36:29 +00:00
|
|
|
from report import ReportColorTheme, create_test_html_report
|
2022-11-14 17:50:31 +00:00
|
|
|
from s3_helper import S3Helper
|
2021-11-12 11:39:00 +00:00
|
|
|
|
2021-11-26 14:00:09 +00:00
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
def process_logs(
|
2022-11-14 17:50:31 +00:00
|
|
|
s3_client: S3Helper, additional_logs: List[str], s3_path_prefix: str
|
|
|
|
) -> List[str]:
|
2022-10-26 12:01:12 +00:00
|
|
|
logging.info("Upload files to s3 %s", additional_logs)
|
2022-10-26 08:30:20 +00:00
|
|
|
|
2022-11-14 17:50:31 +00:00
|
|
|
additional_urls = [] # type: List[str]
|
2021-11-12 11:39:00 +00:00
|
|
|
for log_path in additional_logs:
|
|
|
|
if log_path:
|
|
|
|
additional_urls.append(
|
|
|
|
s3_client.upload_test_report_to_s3(
|
2022-03-22 16:39:58 +00:00
|
|
|
log_path, s3_path_prefix + "/" + os.path.basename(log_path)
|
|
|
|
)
|
|
|
|
)
|
2021-11-12 11:39:00 +00:00
|
|
|
|
|
|
|
return additional_urls
|
|
|
|
|
2021-11-26 14:00:09 +00:00
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
def upload_results(
|
2022-11-14 17:50:31 +00:00
|
|
|
s3_client: S3Helper,
|
|
|
|
pr_number: int,
|
|
|
|
commit_sha: str,
|
|
|
|
test_results: List[Tuple[str, str]],
|
|
|
|
additional_files: List[str],
|
|
|
|
check_name: str,
|
|
|
|
with_raw_logs: bool = True,
|
|
|
|
) -> str:
|
2022-03-22 16:39:58 +00:00
|
|
|
s3_path_prefix = f"{pr_number}/{commit_sha}/" + check_name.lower().replace(
|
|
|
|
" ", "_"
|
|
|
|
).replace("(", "_").replace(")", "_").replace(",", "_")
|
2022-11-14 17:50:31 +00:00
|
|
|
additional_urls = process_logs(s3_client, additional_files, s3_path_prefix)
|
2021-11-12 11:39:00 +00:00
|
|
|
|
2021-11-26 14:00:09 +00:00
|
|
|
branch_url = f"{GITHUB_SERVER_URL}/{GITHUB_REPOSITORY}/commits/master"
|
2021-11-12 11:39:00 +00:00
|
|
|
branch_name = "master"
|
|
|
|
if pr_number != 0:
|
|
|
|
branch_name = f"PR #{pr_number}"
|
2021-11-26 14:00:09 +00:00
|
|
|
branch_url = f"{GITHUB_SERVER_URL}/{GITHUB_REPOSITORY}/pull/{pr_number}"
|
|
|
|
commit_url = f"{GITHUB_SERVER_URL}/{GITHUB_REPOSITORY}/commit/{commit_sha}"
|
2021-11-12 11:39:00 +00:00
|
|
|
|
|
|
|
if additional_urls:
|
|
|
|
raw_log_url = additional_urls[0]
|
|
|
|
additional_urls.pop(0)
|
|
|
|
else:
|
2022-08-09 16:49:55 +00:00
|
|
|
raw_log_url = GITHUB_JOB_URL()
|
2021-11-12 11:39:00 +00:00
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
statuscolors = (
|
|
|
|
ReportColorTheme.bugfixcheck if "bugfix validate check" in check_name else None
|
|
|
|
)
|
2022-03-11 13:36:29 +00:00
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
html_report = create_test_html_report(
|
|
|
|
check_name,
|
|
|
|
test_results,
|
|
|
|
raw_log_url,
|
2022-08-09 16:49:55 +00:00
|
|
|
GITHUB_RUN_URL,
|
|
|
|
GITHUB_JOB_URL(),
|
2022-03-22 16:39:58 +00:00
|
|
|
branch_url,
|
|
|
|
branch_name,
|
|
|
|
commit_url,
|
|
|
|
additional_urls,
|
|
|
|
with_raw_logs,
|
|
|
|
statuscolors=statuscolors,
|
|
|
|
)
|
|
|
|
with open("report.html", "w", encoding="utf-8") as f:
|
2021-11-12 11:39:00 +00:00
|
|
|
f.write(html_report)
|
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
url = s3_client.upload_test_report_to_s3("report.html", s3_path_prefix + ".html")
|
2021-11-12 11:39:00 +00:00
|
|
|
logging.info("Search result in url %s", url)
|
|
|
|
return url
|