2021-10-29 09:58:25 +00:00
|
|
|
#!/usr/bin/env python3
|
2022-04-19 21:35:39 +00:00
|
|
|
import argparse
|
2023-04-24 08:39:49 +00:00
|
|
|
import atexit
|
2021-10-29 09:58:25 +00:00
|
|
|
import logging
|
|
|
|
import subprocess
|
|
|
|
import os
|
|
|
|
import sys
|
2023-01-03 14:23:19 +00:00
|
|
|
|
2021-10-29 09:58:25 +00:00
|
|
|
from github import Github
|
2021-11-26 14:00:09 +00:00
|
|
|
|
2023-01-03 14:23:19 +00:00
|
|
|
from clickhouse_helper import ClickHouseHelper, prepare_tests_results_for_clickhouse
|
2023-04-18 14:58:17 +00:00
|
|
|
from commit_status_helper import (
|
2023-04-24 13:41:43 +00:00
|
|
|
NotSet,
|
2023-04-18 14:58:17 +00:00
|
|
|
RerunHelper,
|
|
|
|
get_commit,
|
|
|
|
post_commit_status,
|
|
|
|
update_mergeable_check,
|
|
|
|
)
|
2023-01-03 14:23:19 +00:00
|
|
|
from docker_pull_helper import get_image_with_version
|
2022-08-11 13:01:32 +00:00
|
|
|
from env_helper import TEMP_PATH, REPO_COPY
|
2021-10-29 09:58:25 +00:00
|
|
|
from get_robot_token import get_best_robot_token
|
2023-01-03 14:23:19 +00:00
|
|
|
from pr_info import PRInfo
|
|
|
|
from report import TestResults, TestResult
|
|
|
|
from s3_helper import S3Helper
|
|
|
|
from stopwatch import Stopwatch
|
2021-12-03 08:33:16 +00:00
|
|
|
from tee_popen import TeePopen
|
2023-01-03 14:23:19 +00:00
|
|
|
from upload_result_helper import upload_results
|
2021-10-29 09:58:25 +00:00
|
|
|
|
|
|
|
|
2022-07-21 11:10:22 +00:00
|
|
|
NAME = "Docs Check"
|
2021-10-29 09:58:25 +00:00
|
|
|
|
2023-01-03 14:23:19 +00:00
|
|
|
|
|
|
|
def main():
|
2022-04-19 21:35:39 +00:00
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
|
|
|
description="Script to check the docs integrity",
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"--docs-branch",
|
|
|
|
default="",
|
|
|
|
help="a branch to get from docs repository",
|
|
|
|
)
|
2022-04-29 12:34:24 +00:00
|
|
|
parser.add_argument(
|
|
|
|
"--force",
|
|
|
|
action="store_true",
|
|
|
|
help="check the docs even if there no changes",
|
|
|
|
)
|
2022-04-19 21:35:39 +00:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
2021-10-29 09:58:25 +00:00
|
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
|
|
2021-11-19 14:47:04 +00:00
|
|
|
stopwatch = Stopwatch()
|
|
|
|
|
2021-11-26 14:00:09 +00:00
|
|
|
temp_path = TEMP_PATH
|
|
|
|
repo_path = REPO_COPY
|
2021-10-29 09:58:25 +00:00
|
|
|
|
2021-11-26 14:00:09 +00:00
|
|
|
pr_info = PRInfo(need_changed_files=True)
|
2021-10-29 09:58:25 +00:00
|
|
|
|
2022-07-30 05:07:22 +00:00
|
|
|
gh = Github(get_best_robot_token(), per_page=100)
|
2023-04-18 14:58:17 +00:00
|
|
|
commit = get_commit(gh, pr_info.sha)
|
2021-12-01 14:23:51 +00:00
|
|
|
|
2023-04-18 14:58:17 +00:00
|
|
|
rerun_helper = RerunHelper(commit, NAME)
|
2021-12-01 14:23:51 +00:00
|
|
|
if rerun_helper.is_already_finished_by_status():
|
|
|
|
logging.info("Check is already finished according to github status, exiting")
|
|
|
|
sys.exit(0)
|
2023-04-24 08:39:49 +00:00
|
|
|
atexit.register(update_mergeable_check, gh, pr_info, NAME)
|
2021-12-01 14:23:51 +00:00
|
|
|
|
2022-04-29 12:34:24 +00:00
|
|
|
if not pr_info.has_changes_in_documentation() and not args.force:
|
2021-11-26 14:00:09 +00:00
|
|
|
logging.info("No changes in documentation")
|
2023-04-24 13:41:43 +00:00
|
|
|
post_commit_status(
|
|
|
|
commit, "success", NotSet, "No changes in docs", NAME, pr_info
|
|
|
|
)
|
2021-10-29 09:58:25 +00:00
|
|
|
sys.exit(0)
|
|
|
|
|
2022-04-29 12:34:24 +00:00
|
|
|
if pr_info.has_changes_in_documentation():
|
|
|
|
logging.info("Has changes in docs")
|
|
|
|
elif args.force:
|
|
|
|
logging.info("Check the docs because of force flag")
|
2021-10-29 09:58:25 +00:00
|
|
|
|
|
|
|
if not os.path.exists(temp_path):
|
|
|
|
os.makedirs(temp_path)
|
|
|
|
|
2022-04-14 22:58:01 +00:00
|
|
|
docker_image = get_image_with_version(temp_path, "clickhouse/docs-builder")
|
2021-10-29 09:58:25 +00:00
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
test_output = os.path.join(temp_path, "docs_check_log")
|
2021-10-29 09:58:25 +00:00
|
|
|
if not os.path.exists(test_output):
|
|
|
|
os.makedirs(test_output)
|
|
|
|
|
2022-04-19 21:35:39 +00:00
|
|
|
cmd = (
|
|
|
|
f"docker run --cap-add=SYS_PTRACE -e GIT_DOCS_BRANCH={args.docs_branch} "
|
|
|
|
f"--volume={repo_path}:/ClickHouse --volume={test_output}:/output_path "
|
|
|
|
f"{docker_image}"
|
|
|
|
)
|
2021-10-29 09:58:25 +00:00
|
|
|
|
2022-12-26 15:29:32 +00:00
|
|
|
run_log_path = os.path.join(test_output, "run.log")
|
2022-01-14 08:15:41 +00:00
|
|
|
logging.info("Running command: '%s'", cmd)
|
2021-10-29 09:58:25 +00:00
|
|
|
|
2021-12-03 08:33:16 +00:00
|
|
|
with TeePopen(cmd, run_log_path) as process:
|
|
|
|
retcode = process.wait()
|
|
|
|
if retcode == 0:
|
|
|
|
logging.info("Run successfully")
|
|
|
|
status = "success"
|
|
|
|
description = "Docs check passed"
|
|
|
|
else:
|
|
|
|
description = "Docs check failed (non zero exit code)"
|
|
|
|
status = "failure"
|
|
|
|
logging.info("Run failed")
|
2021-10-29 09:58:25 +00:00
|
|
|
|
|
|
|
subprocess.check_call(f"sudo chown -R ubuntu:ubuntu {temp_path}", shell=True)
|
|
|
|
files = os.listdir(test_output)
|
2023-01-03 14:23:19 +00:00
|
|
|
test_results = [] # type: TestResults
|
2021-10-29 09:58:25 +00:00
|
|
|
additional_files = []
|
|
|
|
if not files:
|
|
|
|
logging.error("No output files after docs check")
|
|
|
|
description = "No output files after docs check"
|
|
|
|
status = "failure"
|
|
|
|
else:
|
|
|
|
for f in files:
|
|
|
|
path = os.path.join(test_output, f)
|
|
|
|
additional_files.append(path)
|
2022-03-22 16:39:58 +00:00
|
|
|
with open(path, "r", encoding="utf-8") as check_file:
|
2021-10-29 09:58:25 +00:00
|
|
|
for line in check_file:
|
|
|
|
if "ERROR" in line:
|
2023-01-03 14:23:19 +00:00
|
|
|
test_results.append(TestResult(line.split(":")[-1], "FAIL"))
|
|
|
|
if test_results:
|
2021-10-29 09:58:25 +00:00
|
|
|
status = "failure"
|
2021-10-29 17:40:28 +00:00
|
|
|
description = "Found errors in docs"
|
2021-10-29 13:57:47 +00:00
|
|
|
elif status != "failure":
|
2023-01-03 14:23:19 +00:00
|
|
|
test_results.append(TestResult("No errors found", "OK"))
|
2021-10-29 13:57:47 +00:00
|
|
|
else:
|
2023-01-03 14:23:19 +00:00
|
|
|
test_results.append(TestResult("Non zero exit code", "FAIL"))
|
2021-10-29 09:58:25 +00:00
|
|
|
|
2022-08-11 13:01:32 +00:00
|
|
|
s3_helper = S3Helper()
|
2021-11-19 14:47:04 +00:00
|
|
|
ch_helper = ClickHouseHelper()
|
2021-10-29 09:58:25 +00:00
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
report_url = upload_results(
|
2023-01-03 14:23:19 +00:00
|
|
|
s3_helper, pr_info.number, pr_info.sha, test_results, additional_files, NAME
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|
2021-10-29 09:58:25 +00:00
|
|
|
print("::notice ::Report url: {report_url}")
|
2023-04-18 23:03:48 +00:00
|
|
|
post_commit_status(commit, status, report_url, description, NAME, pr_info)
|
2021-11-19 14:47:04 +00:00
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
prepared_events = prepare_tests_results_for_clickhouse(
|
|
|
|
pr_info,
|
2023-01-03 14:23:19 +00:00
|
|
|
test_results,
|
2022-03-22 16:39:58 +00:00
|
|
|
status,
|
|
|
|
stopwatch.duration_seconds,
|
|
|
|
stopwatch.start_time_str,
|
|
|
|
report_url,
|
|
|
|
NAME,
|
|
|
|
)
|
2022-03-29 12:41:47 +00:00
|
|
|
|
2022-03-30 09:15:54 +00:00
|
|
|
ch_helper.insert_events_into(db="default", table="checks", events=prepared_events)
|
2023-01-03 14:23:19 +00:00
|
|
|
if status == "failure":
|
2022-03-29 12:41:47 +00:00
|
|
|
sys.exit(1)
|
2023-01-03 14:23:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|