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 dd03656
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ jobs:
- name: Run integration tests
run: |
sudo timeout -k 30 1h python3 -m pytest \
sudo --preserve-env timeout -k 30 1h python3 -m pytest \
--tb=no \
--capture=no \
--verbose \
Expand Down
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_actions = os.getenv("GITHUB_ACTIONS")
if github_actions:
print(f"\n::group::{s}", flush=True)
try:
yield
finally:
if github_actions:
print("\n::endgroup::", flush=True)
9 changes: 8 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# SPDX-License-Identifier: LGPL-2.1+
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 @@ -50,3 +51,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):
yield
22 changes: 13 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,17 @@ 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}"),
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 dd03656

Please sign in to comment.