2021-10-29 09:58:25 +00:00
|
|
|
#!/usr/bin/env python3
|
2022-04-19 21:35:39 +00:00
|
|
|
import argparse
|
2021-10-29 09:58:25 +00:00
|
|
|
import logging
|
2024-09-23 12:35:05 +00:00
|
|
|
import os
|
2021-10-29 09:58:25 +00:00
|
|
|
import sys
|
2023-09-22 11:16:46 +00:00
|
|
|
from pathlib import Path
|
2023-01-03 14:23:19 +00:00
|
|
|
|
2023-12-18 08:07:22 +00:00
|
|
|
from docker_images_helper import get_docker_image, pull_image
|
2024-09-23 12:35:05 +00:00
|
|
|
from env_helper import REPO_COPY, TEMP_PATH
|
2023-01-03 14:23:19 +00:00
|
|
|
from pr_info import PRInfo
|
2024-09-23 12:35:05 +00:00
|
|
|
from report import FAIL, FAILURE, OK, SUCCESS, JobReport, TestResult, TestResults
|
2023-01-03 14:23:19 +00:00
|
|
|
from stopwatch import Stopwatch
|
2021-12-03 08:33:16 +00:00
|
|
|
from tee_popen import TeePopen
|
2021-10-29 09:58:25 +00:00
|
|
|
|
|
|
|
|
2023-09-22 11:16:46 +00:00
|
|
|
def parse_args() -> argparse.Namespace:
|
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",
|
|
|
|
)
|
2024-09-23 12:35:05 +00:00
|
|
|
parser.add_argument("--pull-image", default=True, help=argparse.SUPPRESS)
|
|
|
|
parser.add_argument(
|
|
|
|
"--no-pull-image",
|
|
|
|
dest="pull_image",
|
|
|
|
action="store_false",
|
|
|
|
default=argparse.SUPPRESS,
|
|
|
|
help="do not pull docker image, use existing",
|
|
|
|
)
|
2023-09-22 11:16:46 +00:00
|
|
|
return parser.parse_args()
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
args = parse_args()
|
2022-04-19 21:35:39 +00:00
|
|
|
|
2021-10-29 09:58:25 +00:00
|
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
|
|
2021-11-19 14:47:04 +00:00
|
|
|
stopwatch = Stopwatch()
|
|
|
|
|
2023-09-22 11:16:46 +00:00
|
|
|
temp_path = Path(TEMP_PATH)
|
|
|
|
temp_path.mkdir(parents=True, exist_ok=True)
|
|
|
|
repo_path = 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-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")
|
2024-01-04 15:35:09 +00:00
|
|
|
JobReport(
|
|
|
|
description="No changes in docs",
|
|
|
|
test_results=[],
|
2024-02-06 12:39:34 +00:00
|
|
|
status=SUCCESS,
|
2024-01-04 15:35:09 +00:00
|
|
|
start_time=stopwatch.start_time_str,
|
|
|
|
duration=stopwatch.duration_seconds,
|
|
|
|
additional_files=[],
|
|
|
|
).dump()
|
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
|
|
|
|
2024-09-23 12:35:05 +00:00
|
|
|
docker_image = get_docker_image("clickhouse/docs-builder")
|
|
|
|
if args.pull_image:
|
|
|
|
docker_image = pull_image(docker_image)
|
2021-10-29 09:58:25 +00:00
|
|
|
|
2024-09-23 12:35:05 +00:00
|
|
|
test_output = temp_path / "docs_check"
|
2023-09-22 11:16:46 +00:00
|
|
|
test_output.mkdir(parents=True, exist_ok=True)
|
2021-10-29 09:58:25 +00:00
|
|
|
|
2022-04-19 21:35:39 +00:00
|
|
|
cmd = (
|
2024-09-23 12:35:05 +00:00
|
|
|
f"docker run --cap-add=SYS_PTRACE --user={os.geteuid()}:{os.getegid()} "
|
|
|
|
f"-e GIT_DOCS_BRANCH={args.docs_branch} "
|
2022-04-19 21:35:39 +00:00
|
|
|
f"--volume={repo_path}:/ClickHouse --volume={test_output}:/output_path "
|
|
|
|
f"{docker_image}"
|
|
|
|
)
|
2021-10-29 09:58:25 +00:00
|
|
|
|
2023-09-22 11:16:46 +00:00
|
|
|
run_log_path = 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
|
|
|
|
2024-09-23 12:35:05 +00:00
|
|
|
test_results = [] # type: TestResults
|
|
|
|
|
|
|
|
test_sw = Stopwatch()
|
|
|
|
with TeePopen(f"{cmd} --out-dir /output_path/build", run_log_path) as process:
|
2021-12-03 08:33:16 +00:00
|
|
|
retcode = process.wait()
|
|
|
|
if retcode == 0:
|
|
|
|
logging.info("Run successfully")
|
2024-09-23 12:35:05 +00:00
|
|
|
job_status = SUCCESS
|
|
|
|
build_status = OK
|
2021-12-03 08:33:16 +00:00
|
|
|
description = "Docs check passed"
|
|
|
|
else:
|
|
|
|
description = "Docs check failed (non zero exit code)"
|
2024-09-23 12:35:05 +00:00
|
|
|
job_status = FAILURE
|
|
|
|
build_status = FAIL
|
2021-12-03 08:33:16 +00:00
|
|
|
logging.info("Run failed")
|
2021-10-29 09:58:25 +00:00
|
|
|
|
2024-09-23 12:35:05 +00:00
|
|
|
if build_status == OK:
|
|
|
|
with open(run_log_path, "r", encoding="utf-8") as lfd:
|
|
|
|
for line in lfd:
|
|
|
|
if "ERROR" in line:
|
|
|
|
build_status = FAIL
|
|
|
|
job_status = FAIL
|
|
|
|
break
|
2024-06-13 18:46:55 +00:00
|
|
|
|
2024-09-23 12:35:05 +00:00
|
|
|
test_results.append(
|
|
|
|
TestResult("Docs build", build_status, test_sw.duration_seconds, [run_log_path])
|
|
|
|
)
|
2024-06-13 18:46:55 +00:00
|
|
|
|
2024-09-23 12:35:05 +00:00
|
|
|
htmltest_log = test_output / "htmltest.log"
|
2024-06-13 18:46:55 +00:00
|
|
|
|
2024-09-23 12:35:05 +00:00
|
|
|
# FIXME: after all issues in htmltest will be fixed, consider the failure as a
|
|
|
|
# failed job
|
|
|
|
test_sw.reset()
|
|
|
|
with TeePopen(
|
|
|
|
f"{cmd} htmltest -c /ClickHouse/docs/.htmltest.yml /output_path/build",
|
|
|
|
htmltest_log,
|
|
|
|
) as process:
|
|
|
|
retcode = process.wait()
|
|
|
|
if retcode == 0:
|
|
|
|
logging.info("Run successfully")
|
|
|
|
test_results.append(
|
|
|
|
TestResult("htmltest", OK, test_sw.duration_seconds, [htmltest_log])
|
|
|
|
)
|
2021-10-29 13:57:47 +00:00
|
|
|
else:
|
2024-09-23 12:35:05 +00:00
|
|
|
logging.info("Run failed")
|
|
|
|
test_results.append(
|
|
|
|
TestResult(
|
|
|
|
"htmltest", "FLAKY", test_sw.duration_seconds, [htmltest_log]
|
|
|
|
)
|
|
|
|
)
|
2021-10-29 09:58:25 +00:00
|
|
|
|
2024-01-04 15:35:09 +00:00
|
|
|
JobReport(
|
|
|
|
description=description,
|
|
|
|
test_results=test_results,
|
2024-09-23 12:35:05 +00:00
|
|
|
status=job_status,
|
2024-01-04 15:35:09 +00:00
|
|
|
start_time=stopwatch.start_time_str,
|
|
|
|
duration=stopwatch.duration_seconds,
|
2024-09-23 12:35:05 +00:00
|
|
|
additional_files=[],
|
2024-01-04 15:35:09 +00:00
|
|
|
).dump()
|
2022-03-29 12:41:47 +00:00
|
|
|
|
2024-09-23 12:35:05 +00:00
|
|
|
if job_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()
|