diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1e2c3cd6d8..6506f9f751 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -174,6 +174,7 @@ jobs: --tb=no \ --capture=no \ --verbose \ + --ci-sections \ -m integration \ --distribution ${{ matrix.distro }} \ --tools-tree-distribution ${{ matrix.tools }} \ diff --git a/tests/__init__.py b/tests/__init__.py index 471151cc98..37666bb131 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,12 @@ 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]: + print(f"\n::group::{s}", flush=True) + try: + yield + finally: + print("\n::endgroup::", flush=True) diff --git a/tests/conftest.py b/tests/conftest.py index 641dfedf6d..e8722d4968 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,4 +1,6 @@ # SPDX-License-Identifier: LGPL-2.1+ +import contextlib +from collections.abc import Iterator from typing import Any, cast import pytest @@ -6,7 +8,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: @@ -38,6 +40,11 @@ def pytest_addoption(parser: Any) -> None: help="Pass --debug-shell when running mkosi", action="store_true", ) + parser.addoption( + "--ci-sections", + help="Print GitHub Workflow section markers before and after each test", + action="store_true", + ) @pytest.fixture(scope="session") @@ -50,3 +57,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) -> Iterator[None]: + with ci_group(request.node.name) if request.config.getoption("--ci-sections") else contextlib.nullcontext(): + yield diff --git a/tests/test_initrd.py b/tests/test_initrd.py index c2327734e5..55d71590d1 100644 --- a/tests/test_initrd.py +++ b/tests/test_initrd.py @@ -8,6 +8,7 @@ import time from collections.abc import Iterator from pathlib import Path +from typing import Any import pytest @@ -20,7 +21,7 @@ from mkosi.user import INVOKING_USER from mkosi.versioncomp import GenericVersion -from . import Image +from . import Image, ci_group pytestmark = pytest.mark.integration @@ -39,14 +40,21 @@ 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: +def initrd(request: Any, config: Image.Config) -> Iterator[Image]: + with ( + ( + ci_group(f"Initrd image {config.distribution}/{config.release}") + if request.config.getoption("--ci-sections") else + contextlib.nullcontext() + ), + Image( + config, + options=[ + "--directory", "", + "--include=mkosi-initrd/", + ], + ) as initrd + ): if initrd.config.distribution == Distribution.rhel_ubi: pytest.skip("Cannot build RHEL-UBI initrds")