Add typing to create_build_html_report

This commit is contained in:
Mikhail f. Shiryaev 2023-01-04 12:18:53 +01:00
parent 84861c2b7c
commit 36e402b10d
No known key found for this signature in database
GPG Key ID: 4B02ED204C7D93F4
2 changed files with 29 additions and 36 deletions

View File

@ -10,13 +10,14 @@ from typing import Dict, List, Tuple
from github import Github from github import Github
from env_helper import ( from env_helper import (
GITHUB_JOB_URL,
GITHUB_REPOSITORY, GITHUB_REPOSITORY,
GITHUB_RUN_URL, GITHUB_RUN_URL,
GITHUB_SERVER_URL, GITHUB_SERVER_URL,
REPORTS_PATH, REPORTS_PATH,
TEMP_PATH, TEMP_PATH,
) )
from report import create_build_html_report from report import create_build_html_report, BuildResult, BuildResults
from s3_helper import S3Helper from s3_helper import S3Helper
from get_robot_token import get_best_robot_token from get_robot_token import get_best_robot_token
from pr_info import NeedsDataType, PRInfo from pr_info import NeedsDataType, PRInfo
@ -31,24 +32,6 @@ from rerun_helper import RerunHelper
NEEDS_DATA_PATH = os.getenv("NEEDS_DATA_PATH", "") NEEDS_DATA_PATH = os.getenv("NEEDS_DATA_PATH", "")
class BuildResult:
def __init__(
self,
compiler,
build_type,
sanitizer,
status,
elapsed_seconds,
with_coverage,
):
self.compiler = compiler
self.build_type = build_type
self.sanitizer = sanitizer
self.status = status
self.elapsed_seconds = elapsed_seconds
self.with_coverage = with_coverage
def group_by_artifacts(build_urls: List[str]) -> Dict[str, List[str]]: def group_by_artifacts(build_urls: List[str]) -> Dict[str, List[str]]:
groups = { groups = {
"apk": [], "apk": [],
@ -81,7 +64,7 @@ def group_by_artifacts(build_urls: List[str]) -> Dict[str, List[str]]:
def get_failed_report( def get_failed_report(
job_name: str, job_name: str,
) -> Tuple[List[BuildResult], List[List[str]], List[str]]: ) -> Tuple[BuildResults, List[List[str]], List[str]]:
message = f"{job_name} failed" message = f"{job_name} failed"
build_result = BuildResult( build_result = BuildResult(
compiler="unknown", compiler="unknown",
@ -89,14 +72,13 @@ def get_failed_report(
sanitizer="unknown", sanitizer="unknown",
status=message, status=message,
elapsed_seconds=0, elapsed_seconds=0,
with_coverage=False,
) )
return [build_result], [[""]], [GITHUB_RUN_URL] return [build_result], [[""]], [GITHUB_RUN_URL]
def process_report( def process_report(
build_report: dict, build_report: dict,
) -> Tuple[List[BuildResult], List[List[str]], List[str]]: ) -> Tuple[BuildResults, List[List[str]], List[str]]:
build_config = build_report["build_config"] build_config = build_report["build_config"]
build_result = BuildResult( build_result = BuildResult(
compiler=build_config["compiler"], compiler=build_config["compiler"],
@ -104,7 +86,6 @@ def process_report(
sanitizer=build_config["sanitizer"], sanitizer=build_config["sanitizer"],
status="success" if build_report["status"] else "failure", status="success" if build_report["status"] else "failure",
elapsed_seconds=build_report["elapsed_seconds"], elapsed_seconds=build_report["elapsed_seconds"],
with_coverage=False,
) )
build_results = [] build_results = []
build_urls = [] build_urls = []
@ -207,9 +188,9 @@ def main():
logging.info("Got exactly %s builds", len(builds_report_map)) logging.info("Got exactly %s builds", len(builds_report_map))
# Group build artifacts by groups # Group build artifacts by groups
build_results = [] # type: List[BuildResult] build_results = [] # type: BuildResults
build_artifacts = [] # build_artifacts = [] # type: List[List[str]]
build_logs = [] build_logs = [] # type: List[str]
for build_report in build_reports: for build_report in build_reports:
_build_results, build_artifacts_url, build_logs_url = process_report( _build_results, build_artifacts_url, build_logs_url = process_report(
@ -244,7 +225,7 @@ def main():
branch_name = f"PR #{pr_info.number}" branch_name = f"PR #{pr_info.number}"
branch_url = f"{GITHUB_SERVER_URL}/{GITHUB_REPOSITORY}/pull/{pr_info.number}" branch_url = f"{GITHUB_SERVER_URL}/{GITHUB_REPOSITORY}/pull/{pr_info.number}"
commit_url = f"{GITHUB_SERVER_URL}/{GITHUB_REPOSITORY}/commit/{pr_info.sha}" commit_url = f"{GITHUB_SERVER_URL}/{GITHUB_REPOSITORY}/commit/{pr_info.sha}"
task_url = GITHUB_RUN_URL task_url = GITHUB_JOB_URL()
report = create_build_html_report( report = create_build_html_report(
build_check_name, build_check_name,
build_results, build_results,

View File

@ -232,6 +232,18 @@ def read_test_results(results_path: Path, with_raw_logs: bool = True) -> TestRes
return results return results
@dataclass
class BuildResult:
compiler: str
build_type: str
sanitizer: str
status: str
elapsed_seconds: int
BuildResults = List[BuildResult]
class ReportColorTheme: class ReportColorTheme:
class ReportColor: class ReportColor:
yellow = "#FFB400" yellow = "#FFB400"
@ -447,15 +459,15 @@ LINK_TEMPLATE = '<a href="{url}">{text}</a>'
def create_build_html_report( def create_build_html_report(
header, header: str,
build_results, build_results: BuildResults,
build_logs_urls, build_logs_urls: List[str],
artifact_urls_list, artifact_urls_list: List[List[str]],
task_url, task_url: str,
branch_url, branch_url: str,
branch_name, branch_name: str,
commit_url, commit_url: str,
): ) -> str:
rows = "" rows = ""
for (build_result, build_log_url, artifact_urls) in zip( for (build_result, build_log_url, artifact_urls) in zip(
build_results, build_logs_urls, artifact_urls_list build_results, build_logs_urls, artifact_urls_list