2021-12-20 19:43:37 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
|
2023-05-09 20:03:20 +00:00
|
|
|
import logging
|
2021-12-20 19:43:37 +00:00
|
|
|
import os
|
2023-05-10 11:02:21 +00:00
|
|
|
from pathlib import Path
|
|
|
|
|
2021-12-20 19:43:37 +00:00
|
|
|
from github import Github
|
|
|
|
|
2023-04-18 23:03:48 +00:00
|
|
|
from commit_status_helper import get_commit, post_commit_status
|
2023-05-09 20:03:20 +00:00
|
|
|
from docker_pull_helper import get_image_with_version, DockerImage
|
2022-11-15 16:57:56 +00:00
|
|
|
from env_helper import (
|
|
|
|
IMAGES_PATH,
|
|
|
|
REPO_COPY,
|
|
|
|
S3_DOWNLOAD,
|
2023-05-09 20:03:20 +00:00
|
|
|
S3_BUILDS_BUCKET,
|
2022-11-15 16:57:56 +00:00
|
|
|
S3_TEST_REPORTS_BUCKET,
|
|
|
|
TEMP_PATH,
|
|
|
|
)
|
|
|
|
from get_robot_token import get_best_robot_token
|
|
|
|
from pr_info import PRInfo
|
2023-01-03 14:23:19 +00:00
|
|
|
from report import TestResult
|
2022-11-15 16:57:56 +00:00
|
|
|
from s3_helper import S3Helper
|
|
|
|
from stopwatch import Stopwatch
|
2021-12-20 19:43:37 +00:00
|
|
|
from tee_popen import TeePopen
|
2022-11-15 16:57:56 +00:00
|
|
|
from upload_result_helper import upload_results
|
2021-12-20 19:43:37 +00:00
|
|
|
|
2022-07-21 11:10:22 +00:00
|
|
|
NAME = "Woboq Build"
|
2021-12-20 19:43:37 +00:00
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
|
2023-05-09 20:03:20 +00:00
|
|
|
def get_run_command(
|
2023-05-10 11:02:21 +00:00
|
|
|
repo_path: Path, output_path: Path, image: DockerImage, sha: str
|
2023-05-09 20:03:20 +00:00
|
|
|
) -> str:
|
|
|
|
user = f"{os.geteuid()}:{os.getegid()}"
|
2022-03-22 16:39:58 +00:00
|
|
|
cmd = (
|
2023-05-09 20:03:20 +00:00
|
|
|
f"docker run --rm --user={user} --volume={repo_path}:/build "
|
|
|
|
f"--volume={output_path}:/workdir/output --network=host "
|
|
|
|
# use sccache, https://github.com/KDAB/codebrowser/issues/111
|
|
|
|
f"-e SCCACHE_BUCKET='{S3_BUILDS_BUCKET}' "
|
|
|
|
"-e SCCACHE_S3_KEY_PREFIX=ccache/sccache "
|
|
|
|
'-e CMAKE_FLAGS="$CMAKE_FLAGS -DCOMPILER_CACHE=sccache" '
|
|
|
|
f"-e 'DATA={S3_DOWNLOAD}/{S3_TEST_REPORTS_BUCKET}/codebrowser/data' "
|
|
|
|
f"-e SHA={sha} {image}"
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2021-12-20 19:43:37 +00:00
|
|
|
return cmd
|
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
|
2023-05-09 20:03:20 +00:00
|
|
|
def main():
|
2021-12-20 19:43:37 +00:00
|
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
|
|
|
|
|
stopwatch = Stopwatch()
|
|
|
|
|
2022-07-30 05:07:22 +00:00
|
|
|
gh = Github(get_best_robot_token(), per_page=100)
|
2022-11-15 16:57:56 +00:00
|
|
|
pr_info = PRInfo()
|
2023-04-18 23:03:48 +00:00
|
|
|
commit = get_commit(gh, pr_info.sha)
|
2023-05-10 11:02:21 +00:00
|
|
|
temp_path = Path(TEMP_PATH)
|
2021-12-20 19:43:37 +00:00
|
|
|
|
2023-05-10 11:02:21 +00:00
|
|
|
if not temp_path.exists():
|
|
|
|
os.makedirs(temp_path)
|
2021-12-20 19:43:37 +00:00
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
docker_image = get_image_with_version(IMAGES_PATH, "clickhouse/codebrowser")
|
2023-05-24 15:36:23 +00:00
|
|
|
# FIXME: the codebrowser is broken with clang-16, workaround with clang-15
|
|
|
|
# See https://github.com/ClickHouse/ClickHouse/issues/50077
|
|
|
|
docker_image.version = "49701-4dcdcf4c11b5604f1c5d3121c9c6fea3e957b605"
|
2022-08-11 13:01:32 +00:00
|
|
|
s3_helper = S3Helper()
|
2021-12-20 19:43:37 +00:00
|
|
|
|
2023-05-10 11:02:21 +00:00
|
|
|
result_path = temp_path / "result_path"
|
|
|
|
if not result_path.exists():
|
2021-12-20 19:43:37 +00:00
|
|
|
os.makedirs(result_path)
|
|
|
|
|
2023-05-09 20:03:20 +00:00
|
|
|
run_command = get_run_command(
|
2023-05-10 11:02:21 +00:00
|
|
|
Path(REPO_COPY), result_path, docker_image, pr_info.sha[:12]
|
2023-05-09 20:03:20 +00:00
|
|
|
)
|
2021-12-20 19:43:37 +00:00
|
|
|
|
|
|
|
logging.info("Going to run codebrowser: %s", run_command)
|
|
|
|
|
2023-05-10 11:02:21 +00:00
|
|
|
run_log_path = result_path / "run.log"
|
2021-12-20 19:43:37 +00:00
|
|
|
|
2023-05-09 20:03:20 +00:00
|
|
|
state = "success"
|
2021-12-20 19:43:37 +00:00
|
|
|
with TeePopen(run_command, run_log_path) as process:
|
|
|
|
retcode = process.wait()
|
|
|
|
if retcode == 0:
|
|
|
|
logging.info("Run successfully")
|
|
|
|
else:
|
|
|
|
logging.info("Run failed")
|
2023-05-09 20:03:20 +00:00
|
|
|
state = "failure"
|
2021-12-20 19:43:37 +00:00
|
|
|
|
2023-05-10 11:02:21 +00:00
|
|
|
report_path = result_path / "html_report"
|
2021-12-20 19:43:37 +00:00
|
|
|
logging.info("Report path %s", report_path)
|
|
|
|
|
2023-06-16 10:51:31 +00:00
|
|
|
s3_path_prefix = "codebrowser"
|
|
|
|
index_template = (
|
|
|
|
f'<a href="{S3_DOWNLOAD}/{S3_TEST_REPORTS_BUCKET}/{s3_path_prefix}/index.html">'
|
|
|
|
"{}</a>"
|
2022-08-10 13:22:04 +00:00
|
|
|
)
|
2023-05-10 11:02:21 +00:00
|
|
|
additional_logs = [path.absolute() for path in result_path.glob("*.log")]
|
2023-05-10 20:16:28 +00:00
|
|
|
test_results = [
|
2023-06-16 10:51:31 +00:00
|
|
|
TestResult(
|
|
|
|
index_template.format("Generate codebrowser site"),
|
|
|
|
state,
|
|
|
|
stopwatch.duration_seconds,
|
|
|
|
additional_logs,
|
|
|
|
)
|
2023-05-10 20:16:28 +00:00
|
|
|
]
|
2021-12-20 19:43:37 +00:00
|
|
|
|
2023-06-16 10:51:31 +00:00
|
|
|
if state == "success":
|
|
|
|
stopwatch.reset()
|
|
|
|
_ = s3_helper.fast_parallel_upload_dir(
|
|
|
|
report_path, s3_path_prefix, S3_TEST_REPORTS_BUCKET
|
|
|
|
)
|
|
|
|
test_results.append(
|
|
|
|
TestResult(
|
|
|
|
index_template.format("Upload codebrowser site"),
|
|
|
|
state,
|
|
|
|
stopwatch.duration_seconds,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2023-05-10 20:16:28 +00:00
|
|
|
# Check if the run log contains `FATAL Error:`, that means the code problem
|
2023-06-16 10:51:31 +00:00
|
|
|
stopwatch.reset()
|
2023-05-10 20:16:28 +00:00
|
|
|
fatal_error = "FATAL Error:"
|
|
|
|
logging.info("Search for '%s' in %s", fatal_error, run_log_path)
|
|
|
|
with open(run_log_path, "r", encoding="utf-8") as rlfd:
|
|
|
|
for line in rlfd.readlines():
|
|
|
|
if "FATAL Error:" in line:
|
|
|
|
logging.warning(
|
|
|
|
"The line '%s' found, mark the run as failure", fatal_error
|
|
|
|
)
|
|
|
|
state = "failure"
|
|
|
|
test_results.append(
|
|
|
|
TestResult(
|
|
|
|
"Indexing error",
|
|
|
|
state,
|
|
|
|
stopwatch.duration_seconds,
|
|
|
|
additional_logs,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
break
|
|
|
|
|
|
|
|
report_url = upload_results(
|
|
|
|
s3_helper, pr_info.number, pr_info.sha, test_results, [], NAME
|
|
|
|
)
|
2021-12-20 19:43:37 +00:00
|
|
|
|
|
|
|
print(f"::notice ::Report url: {report_url}")
|
|
|
|
|
2023-05-09 20:03:20 +00:00
|
|
|
post_commit_status(commit, state, report_url, "Report built", NAME, pr_info)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|