CI: check cpp and py files style on changes only

#do_not_test
This commit is contained in:
Max Kainov 2024-03-11 08:45:58 +00:00
parent d4146c1e26
commit 49b78e0a0c
6 changed files with 96 additions and 39 deletions

View File

@ -288,6 +288,9 @@ class JobReport:
# if False no GH commit status will be created by CI # if False no GH commit status will be created by CI
need_commit_status: bool = True need_commit_status: bool = True
def __post_init__(self):
assert self.status in (SUCCESS, ERROR, FAILURE, PENDING)
@classmethod @classmethod
def exist(cls) -> bool: def exist(cls) -> bool:
return JOB_REPORT_FILE.is_file() return JOB_REPORT_FILE.is_file()

View File

@ -4,13 +4,14 @@ from concurrent.futures import ProcessPoolExecutor
import csv import csv
import logging import logging
import os import os
import shutil
import subprocess import subprocess
import sys import sys
from pathlib import Path from pathlib import Path
from typing import List, Tuple from typing import List, Tuple
from docker_images_helper import get_docker_image, pull_image from docker_images_helper import get_docker_image, pull_image
from env_helper import REPO_COPY, TEMP_PATH from env_helper import CI, REPO_COPY, TEMP_PATH
from git_helper import GIT_PREFIX, git_runner from git_helper import GIT_PREFIX, git_runner
from pr_info import PRInfo from pr_info import PRInfo
from report import ERROR, FAILURE, SUCCESS, JobReport, TestResults, read_test_results from report import ERROR, FAILURE, SUCCESS, JobReport, TestResults, read_test_results
@ -126,33 +127,56 @@ def main():
repo_path = Path(REPO_COPY) repo_path = Path(REPO_COPY)
temp_path = Path(TEMP_PATH) temp_path = Path(TEMP_PATH)
if temp_path.is_dir():
shutil.rmtree(temp_path)
temp_path.mkdir(parents=True, exist_ok=True) temp_path.mkdir(parents=True, exist_ok=True)
# pr_info = PRInfo() pr_info = PRInfo()
IMAGE_NAME = "clickhouse/style-test" IMAGE_NAME = "clickhouse/style-test"
image = pull_image(get_docker_image(IMAGE_NAME)) image = pull_image(get_docker_image(IMAGE_NAME))
cmd_1 = ( cmd_cpp = (
f"docker run -u $(id -u ${{USER}}):$(id -g ${{USER}}) --cap-add=SYS_PTRACE " f"docker run -u $(id -u ${{USER}}):$(id -g ${{USER}}) --cap-add=SYS_PTRACE "
f"--volume={repo_path}:/ClickHouse --volume={temp_path}:/test_output " f"--volume={repo_path}:/ClickHouse --volume={temp_path}:/test_output "
f"--entrypoint= -w/ClickHouse/utils/check-style " f"--entrypoint= -w/ClickHouse/utils/check-style "
f"{image} ./check_cpp_docs.sh" f"{image} ./check_cpp.sh"
) )
cmd_2 = ( cmd_py = (
f"docker run -u $(id -u ${{USER}}):$(id -g ${{USER}}) --cap-add=SYS_PTRACE " f"docker run -u $(id -u ${{USER}}):$(id -g ${{USER}}) --cap-add=SYS_PTRACE "
f"--volume={repo_path}:/ClickHouse --volume={temp_path}:/test_output " f"--volume={repo_path}:/ClickHouse --volume={temp_path}:/test_output "
f"--entrypoint= -w/ClickHouse/utils/check-style " f"--entrypoint= -w/ClickHouse/utils/check-style "
f"{image} ./check_py.sh" f"{image} ./check_py.sh"
) )
logging.info("Is going to run the command: %s", cmd_1) cmd_docs = (
logging.info("Is going to run the command: %s", cmd_2) f"docker run -u $(id -u ${{USER}}):$(id -g ${{USER}}) --cap-add=SYS_PTRACE "
f"--volume={repo_path}:/ClickHouse --volume={temp_path}:/test_output "
f"--entrypoint= -w/ClickHouse/utils/check-style "
f"{image} ./check_docs.sh"
)
with ProcessPoolExecutor(max_workers=2) as executor: with ProcessPoolExecutor(max_workers=2) as executor:
# Submit commands for execution in parallel logging.info("Run docs files check: %s", cmd_docs)
future1 = executor.submit(subprocess.run, cmd_1, shell=True) future = executor.submit(subprocess.run, cmd_docs, shell=True)
future2 = executor.submit(subprocess.run, cmd_2, shell=True) # Parallelization does not make it faster - run subsequently
# Wait for both commands to complete _ = future.result()
run_cppcheck = True
run_pycheck = True
if CI and pr_info.number > 0:
pr_info.fetch_changed_files()
if not any(file.endswith(".py") for file in pr_info.changed_files):
run_pycheck = False
if all(file.endswith(".py") for file in pr_info.changed_files):
run_cppcheck = False
if run_cppcheck:
logging.info("Run source files check: %s", cmd_cpp)
future1 = executor.submit(subprocess.run, cmd_cpp, shell=True)
_ = future1.result() _ = future1.result()
if run_pycheck:
logging.info("Run py files check: %s", cmd_py)
future2 = executor.submit(subprocess.run, cmd_py, shell=True)
_ = future2.result() _ = future2.result()
# if args.push: # if args.push:

View File

@ -4,31 +4,35 @@
cd /ClickHouse/utils/check-style || echo -e "failure\tRepo not found" > /test_output/check_status.tsv cd /ClickHouse/utils/check-style || echo -e "failure\tRepo not found" > /test_output/check_status.tsv
start_total=`date +%s`
# FIXME: 30 sec to wait # FIXME: 30 sec to wait
# echo "Check duplicates" | ts # echo "Check duplicates" | ts
# ./check-duplicate-includes.sh |& tee /test_output/duplicate_includes_output.txt # ./check-duplicate-includes.sh |& tee /test_output/duplicate_includes_output.txt
echo "Check style" | ts start=`date +%s`
./check-style -n |& tee /test_output/style_output.txt ./check-style -n |& tee /test_output/style_output.txt
echo "Check typos" | ts runtime=$((`date +%s`-start))
./check-typos |& tee /test_output/typos_output.txt echo "Check style. Done. $runtime seconds."
echo "Check docs spelling" | ts
./check-doc-aspell |& tee /test_output/docs_spelling_output.txt start=`date +%s`
echo "Check whitespaces" | ts
./check-whitespaces -n |& tee /test_output/whitespaces_output.txt ./check-whitespaces -n |& tee /test_output/whitespaces_output.txt
echo "Check workflows" | ts runtime=$((`date +%s`-start))
echo "Check whitespaces. Done. $runtime seconds."
start=`date +%s`
./check-workflows |& tee /test_output/workflows_output.txt ./check-workflows |& tee /test_output/workflows_output.txt
echo "Check submodules" | ts runtime=$((`date +%s`-start))
echo "Check workflows. Done. $runtime seconds."
start=`date +%s`
./check-submodules |& tee /test_output/submodules_output.txt ./check-submodules |& tee /test_output/submodules_output.txt
echo "Check style. Done" | ts runtime=$((`date +%s`-start))
echo "Check submodules. Done. $runtime seconds."
# FIXME: 6 min to wait # FIXME: 6 min to wait
# echo "Check shell scripts with shellcheck" | ts # echo "Check shell scripts with shellcheck" | ts
# ./shellcheck-run.sh |& tee /test_output/shellcheck_output.txt # ./shellcheck-run.sh |& tee /test_output/shellcheck_output.txt
runtime=$((`date +%s`-start_total))
# FIXME: move out echo "Check style total. Done. $runtime seconds."
# /process_style_check_result.py || echo -e "failure\tCannot parse results" > /test_output/check_status.tsv
# echo "Check help for changelog generator works" | ts
# cd ../changelog || exit 1
# ./changelog.py -h 2>/dev/null 1>&2

20
utils/check-style/check_docs.sh Executable file
View File

@ -0,0 +1,20 @@
#!/bin/bash
# yaml check is not the best one
cd /ClickHouse/utils/check-style || echo -e "failure\tRepo not found" > /test_output/check_status.tsv
start_total=`date +%s`
start=`date +%s`
./check-typos |& tee /test_output/typos_output.txt
runtime=$((`date +%s`-start))
echo "Check typos. Done. $runtime seconds."
start=`date +%s`
./check-doc-aspell |& tee /test_output/docs_spelling_output.txt
runtime=$((`date +%s`-start))
echo "Check docs spelling. Done. $runtime seconds."
runtime=$((`date +%s`-start_total))
echo "Check Docs, total. Done. $runtime seconds."

View File

@ -1,17 +1,22 @@
#!/bin/bash #!/bin/bash
# yaml check is not the best one
cd /ClickHouse/utils/check-style || echo -e "failure\tRepo not found" > /test_output/check_status.tsv cd /ClickHouse/utils/check-style || echo -e "failure\tRepo not found" > /test_output/check_status.tsv
start_total=`date +%s`
# FIXME: 1 min to wait + head checkout # FIXME: 1 min to wait + head checkout
# echo "Check python formatting with black" | ts # echo "Check python formatting with black" | ts
# ./check-black -n |& tee /test_output/black_output.txt # ./check-black -n |& tee /test_output/black_output.txt
echo "Check pylint" | ts start=`date +%s`
./check-pylint -n |& tee /test_output/pylint_output.txt ./check-pylint -n |& tee /test_output/pylint_output.txt
echo "Check pylint. Done" | ts runtime=$((`date +%s`-start))
echo "Check pylint. Done. $runtime seconds."
echo "Check python type hinting with mypy" | ts start=`date +%s`
./check-mypy -n |& tee /test_output/mypy_output.txt ./check-mypy -n |& tee /test_output/mypy_output.txt
echo "Check python type hinting with mypy. Done" | ts runtime=$((`date +%s`-start))
echo "Check python type hinting with mypy. Done. $runtime seconds."
runtime=$((`date +%s`-start_total))
echo "Check python total. Done. $runtime seconds."

View File

@ -30,8 +30,7 @@ def process_result(result_folder):
out_file = name.replace(" ", "_") + "_output.txt" out_file = name.replace(" ", "_") + "_output.txt"
full_path = os.path.join(result_folder, out_file) full_path = os.path.join(result_folder, out_file)
if not os.path.exists(full_path): if not os.path.exists(full_path):
logging.info("No %s check log on path %s", name, full_path) test_results.append((f"Check {name}", "SKIPPED"))
return "exception", f"No {name} check log", []
elif os.stat(full_path).st_size != 0: elif os.stat(full_path).st_size != 0:
description += f"Check {name} failed. " description += f"Check {name} failed. "
test_results.append((f"Check {name}", "FAIL")) test_results.append((f"Check {name}", "FAIL"))
@ -42,6 +41,8 @@ def process_result(result_folder):
if not description: if not description:
description += "Style check success" description += "Style check success"
assert test_results, "No single style-check output found"
return status, description, test_results return status, description, test_results