From 62c776afc2141a22e21d0bba13564eb217868c4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Behrmann?= Date: Tue, 12 Mar 2024 16:16:29 +0100 Subject: [PATCH] ci: print group section lines for GitHub workflow Partially fixes: #2361 --- tests/__init__.py | 13 +++++++++++++ tests/conftest.py | 8 +++++++- tests/test_initrd.py | 19 +++++++++++-------- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/tests/__init__.py b/tests/__init__.py index 471151cc98..0cf8718aa3 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,5 +1,6 @@ # SPDX-License-Identifier: LGPL-2.1+ +import contextlib import os import subprocess import sys @@ -167,3 +168,15 @@ def suspend_capture_stdin(pytestconfig: Any) -> Iterator[None]: if pytestconfig.getoption("capture") == "no": capmanager.resume_global_capture() + + +@contextlib.contextmanager +def ci_group(s: str) -> Iterator[None]: + github_action = os.getenv("GITHUB_ACTIONS") == "true" + if github_action: + print(f"\n::group::{s}", flush=True) + try: + yield + finally: + if github_action: + print("\n::endgroup::", flush=True) diff --git a/tests/conftest.py b/tests/conftest.py index 641dfedf6d..dfde645450 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -6,7 +6,7 @@ from mkosi.config import parse_config from mkosi.distributions import Distribution, detect_distribution -from . import Image +from . import Image, ci_group def pytest_addoption(parser: Any) -> None: @@ -50,3 +50,9 @@ def config(request: Any) -> Image.Config: tools_tree_distribution=cast(Distribution, request.config.getoption("--tools-tree-distribution")), debug_shell=request.config.getoption("--debug-shell"), ) + + +@pytest.fixture(autouse=True) +def ci_sections(request: Any) -> Any: + with ci_group(request.node.name): + yield diff --git a/tests/test_initrd.py b/tests/test_initrd.py index 916c94a0d4..6181599181 100644 --- a/tests/test_initrd.py +++ b/tests/test_initrd.py @@ -20,7 +20,7 @@ from mkosi.user import INVOKING_USER from mkosi.versioncomp import GenericVersion -from . import Image +from . import Image, ci_group pytestmark = pytest.mark.integration @@ -40,13 +40,16 @@ def passphrase() -> Iterator[Path]: @pytest.fixture(scope="module") def initrd(config: Image.Config) -> Iterator[Image]: - with Image( - config, - options=[ - "--directory", "", - "--include=mkosi-initrd/", - ], - ) as initrd: + with ( + ci_group(f"Initrd image {config.distribution}/{config.release}"), + Image( + config, + options=[ + "--directory", "", + "--include=mkosi-initrd/", + ], + ) as initrd + ): if initrd.config.distribution == Distribution.rhel_ubi: pytest.skip("Cannot build RHEL-UBI initrds")