ClickHouse/tests/ci/codebrowser_check.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

92 lines
2.5 KiB
Python
Raw Normal View History

2021-12-20 19:43:37 +00:00
#!/usr/bin/env python3
import os
import subprocess
import logging
from github import Github
from commit_status_helper import get_commit, post_commit_status
from docker_pull_helper import get_image_with_version
from env_helper import (
IMAGES_PATH,
REPO_COPY,
S3_DOWNLOAD,
S3_TEST_REPORTS_BUCKET,
TEMP_PATH,
)
from get_robot_token import get_best_robot_token
from pr_info import PRInfo
from report import TestResult
from s3_helper import S3Helper
from stopwatch import Stopwatch
2021-12-20 19:43:37 +00:00
from tee_popen import TeePopen
from upload_result_helper import upload_results
2021-12-20 19:43:37 +00:00
NAME = "Woboq Build"
2021-12-20 19:43:37 +00:00
2021-12-20 19:43:37 +00:00
def get_run_command(repo_path, output_path, image):
cmd = (
"docker run " + f"--volume={repo_path}:/repo_folder "
f"--volume={output_path}:/test_output "
2022-08-11 13:01:32 +00:00
f"-e 'DATA={S3_DOWNLOAD}/{S3_TEST_REPORTS_BUCKET}/codebrowser/data' {image}"
)
2021-12-20 19:43:37 +00:00
return cmd
2021-12-20 19:43:37 +00:00
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)
stopwatch = Stopwatch()
gh = Github(get_best_robot_token(), per_page=100)
pr_info = PRInfo()
commit = get_commit(gh, pr_info.sha)
2021-12-20 19:43:37 +00:00
if not os.path.exists(TEMP_PATH):
os.makedirs(TEMP_PATH)
2021-12-20 19:43:37 +00:00
docker_image = get_image_with_version(IMAGES_PATH, "clickhouse/codebrowser")
2022-08-11 13:01:32 +00:00
s3_helper = S3Helper()
2021-12-20 19:43:37 +00:00
result_path = os.path.join(TEMP_PATH, "result_path")
2021-12-20 19:43:37 +00:00
if not os.path.exists(result_path):
os.makedirs(result_path)
2021-12-21 07:49:22 +00:00
run_command = get_run_command(REPO_COPY, result_path, docker_image)
2021-12-20 19:43:37 +00:00
logging.info("Going to run codebrowser: %s", run_command)
2022-12-26 15:29:32 +00:00
run_log_path = os.path.join(TEMP_PATH, "run.log")
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")
subprocess.check_call(f"sudo chown -R ubuntu:ubuntu {TEMP_PATH}", shell=True)
2021-12-20 19:43:37 +00:00
report_path = os.path.join(result_path, "html_report")
logging.info("Report path %s", report_path)
s3_path_prefix = "codebrowser"
html_urls = s3_helper.fast_parallel_upload_dir(
report_path, s3_path_prefix, "clickhouse-test-reports"
)
2021-12-20 19:43:37 +00:00
2022-08-10 13:22:04 +00:00
index_html = (
2022-08-11 13:01:32 +00:00
'<a href="{S3_DOWNLOAD}/{S3_TEST_REPORTS_BUCKET}/codebrowser/index.html">'
2022-08-10 13:22:04 +00:00
"HTML report</a>"
)
2021-12-20 19:43:37 +00:00
test_result = TestResult(index_html, "Look at the report")
2021-12-20 19:43:37 +00:00
report_url = upload_results(s3_helper, 0, pr_info.sha, [test_result], [], NAME)
2021-12-20 19:43:37 +00:00
print(f"::notice ::Report url: {report_url}")
post_commit_status(commit, "success", report_url, "Report built", NAME, pr_info)