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 b67c98e commit 663c7d4
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 10 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ jobs:
--tb=no \
--capture=no \
--verbose \
--ci-sections \
-m integration \
--distribution ${{ matrix.distro }} \
--tools-tree-distribution ${{ matrix.tools }} \
Expand Down
10 changes: 10 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,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)
15 changes: 14 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# SPDX-License-Identifier: LGPL-2.1+
import contextlib
from collections.abc import Iterator
from typing import Any, cast

import pytest

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 @@ -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")
Expand All @@ -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
26 changes: 17 additions & 9 deletions tests/test_initrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import time
from collections.abc import Iterator
from pathlib import Path
from typing import Any

import pytest

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

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

Expand Down

0 comments on commit 663c7d4

Please sign in to comment.