Skip to content

Commit

Permalink
ci: print group section lines for GitHub workflow
Browse files Browse the repository at this point in the history
Partially fixes: systemd#2361
  • Loading branch information
behrmann committed Mar 13, 2024
1 parent 4243375 commit 62c776a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
13 changes: 13 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# SPDX-License-Identifier: LGPL-2.1+

import contextlib
import os
import subprocess
import sys
Expand Down Expand Up @@ -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)
8 changes: 7 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
19 changes: 11 additions & 8 deletions tests/test_initrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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")

Expand Down

0 comments on commit 62c776a

Please sign in to comment.