From b5825bb45636beb1933d6e4d7a681d6cd929470f Mon Sep 17 00:00:00 2001 From: Axel Naumann Date: Sun, 20 Aug 2023 17:57:16 +0200 Subject: [PATCH] [ci] Better log grouping. --- .../workflows/root-ci-config/build_root.py | 63 ++++++++++++------- .../workflows/root-ci-config/build_utils.py | 57 ++++++++--------- 2 files changed, 68 insertions(+), 52 deletions(-) diff --git a/.github/workflows/root-ci-config/build_root.py b/.github/workflows/root-ci-config/build_root.py index f62dbd53146f0..0d94cfdebca7d 100755 --- a/.github/workflows/root-ci-config/build_root.py +++ b/.github/workflows/root-ci-config/build_root.py @@ -159,7 +159,6 @@ def parse_args(): return args -@github_log_group("To reproduce") def print_trace(): build_utils.log.print() @@ -250,7 +249,9 @@ def show_node_state() -> None: if result != 0: build_utils.print_warning("Failed to extract node state") -# Just return the exit code in case of test failures instead of `die()`-ing; report test@github_log_group("Run tests") +# Just return the exit code in case of test failures instead of `die()`-ing; report test +# failures in main(). +@github_log_group("Run tests") def run_ctest(extra_ctest_flags: str) -> int: ctest_result = subprocess_with_log(f""" cd '{WORKDIR}/build' @@ -278,34 +279,36 @@ def archive_and_upload(archive_name, prefix): ) -@github_log_group("Build") -def build(options, buildtype): - generator_flags = "-- '-verbosity:minimal'" if WINDOWS else "" +@github_log_group("Configure") +def cmake_configure(options, buildtype): + result = subprocess_with_log(f""" + cmake -S '{WORKDIR}/src' -B '{WORKDIR}/build' {options} -DCMAKE_BUILD_TYPE={buildtype} + """) - if not os.path.isdir(f'{WORKDIR}/build'): - result = subprocess_with_log(f"mkdir {WORKDIR}/build") + if result != 0: + die(result, "Failed cmake generation step") - if result != 0: - die(result, "Failed to create build directory") - if not os.path.exists(f'{WORKDIR}/build/CMakeCache.txt'): - result = subprocess_with_log(f""" - cmake -S '{WORKDIR}/src' -B '{WORKDIR}/build' {options} -DCMAKE_BUILD_TYPE={buildtype} - """) +@github_log_group("Dump existing configuration") +def cmake_dump_config(): + # Print CMake cached config + result = subprocess_with_log(f""" + cmake -S '{WORKDIR}/src' -B '{WORKDIR}/build' -N -L + """) - if result != 0: - die(result, "Failed cmake generation step") - else: - # Print CMake cached config - result = subprocess_with_log(f""" - cmake -S '{WORKDIR}/src' -B '{WORKDIR}/build' -N -L - """) + if result != 0: + die(result, "Failed cmake cache print step") - if result != 0: - die(result, "Failed cmake cache print step") +@github_log_group("Dump requested build configuration") +def dump_requested_config(options): print(f"\nBUILD OPTIONS: {options}") + +@github_log_group("Build") +def cmake_build(buildtype): + generator_flags = "-- '-verbosity:minimal'" if WINDOWS else "" + result = subprocess_with_log(f""" cmake --build '{WORKDIR}/build' --config '{buildtype}' --parallel '{os.cpu_count()}' {generator_flags} """) @@ -314,6 +317,22 @@ def build(options, buildtype): die(result, "Failed to build") +def build(options, buildtype): + if not os.path.isdir(f'{WORKDIR}/build'): + result = subprocess_with_log(f"mkdir {WORKDIR}/build") + + if result != 0: + die(result, "Failed to create build directory") + + if not os.path.exists(f'{WORKDIR}/build/CMakeCache.txt'): + cmake_configure(options, buildtype) + else: + cmake_dump_config() + + dump_requested_config(options) + + cmake_build(buildtype) + @github_log_group("Rebase") def rebase(base_ref, head_ref) -> None: head_ref_src, _, head_ref_dst = head_ref.partition(":") diff --git a/.github/workflows/root-ci-config/build_utils.py b/.github/workflows/root-ci-config/build_utils.py index 87d989b43a577..0ab7b0af05d15 100755 --- a/.github/workflows/root-ci-config/build_utils.py +++ b/.github/workflows/root-ci-config/build_utils.py @@ -12,6 +12,30 @@ from openstack.connection import Connection from requests import get + +def github_log_group(title: str): + """ decorator that places function's stdout/stderr output in a + dropdown group when running on github workflows """ + def group(func: Callable): + @wraps(func) + def wrapper(*args, **kwargs): + print("::group::" + title) + + try: + result = func(*args, **kwargs) + except Exception as exc: + print("::endgroup::") + raise exc + + print("::endgroup::") + + return result + + return wrapper if os.getenv("GITHUB_ACTIONS") else func + + return group + + class Tracer: """ Trace command invocations and print them to reproduce builds. @@ -31,13 +55,9 @@ def __init__(self, image: str, docker_opts: str): def add(self, command: str) -> None: self.trace += '\n(\n' + textwrap.dedent(command.strip()) + '\n)' + @github_log_group("To replicate this build locally") def print(self) -> None: if self.trace != "": - print("""\ -###################################### -# To replicate build locally # -###################################### -""") if self.image: print(f"""\ Grab the image: @@ -49,28 +69,6 @@ def print(self) -> None: log = Tracer("", "") -def github_log_group(title: str): - """ decorator that places function's stdout/stderr output in a - dropdown group when running on github workflows """ - def group(func: Callable): - @wraps(func) - def wrapper(*args, **kwargs): - print("::group::" + title) - - try: - result = func(*args, **kwargs) - except Exception as exc: - print("::endgroup::") - raise exc - - print("::endgroup::") - - return result - - return wrapper if os.getenv("GITHUB_ACTIONS") else func - - return group - def print_fancy(*values, sgr=1, **kwargs) -> None: """prints message using select graphic rendition, defaults to bold text @@ -112,12 +110,11 @@ def subprocess_with_log(command: str) -> int: return result.returncode - def die(code: int = 1, msg: str = "") -> None: - print_error(f"({code}) {msg}") - log.print() + print_error(f"({code}) {msg}") + sys.exit(code)