From 657adf176fadbd6c89e3c636b1a58221f3c92cf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Br=C3=A9nainn=20Woodsend?= Date: Wed, 13 Nov 2024 00:06:41 +0000 Subject: [PATCH] WIP --- .github/workflows/test.yml | 10 +++++----- polycotylus/_docker.py | 12 ++++++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3a06c0a..1cc9d16 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,14 +13,14 @@ jobs: - python: 3.8.12 # Test https://docs.python.org/3/library/tarfile.html#supporting-older-python-versions docker: podman suite: - - tests/test_mirror.py tests/test_docker.py tests/test_project.py tests/test_desktopfile.py tests/test_docs.py +# - tests/test_mirror.py tests/test_docker.py tests/test_project.py tests/test_desktopfile.py tests/test_docs.py - tests/test_alpine.py tests/test_completion.py - tests/test_arch.py tests/test_configuration.py - - tests/test_manjaro.py +# - tests/test_manjaro.py - tests/test_fedora.py - - tests/test_void.py - - tests/test_debian.py - - tests/test_ubuntu.py +# - tests/test_void.py +# - tests/test_debian.py +# - tests/test_ubuntu.py fail-fast: false runs-on: ubuntu-latest diff --git a/polycotylus/_docker.py b/polycotylus/_docker.py index 42eb9a5..08fc88f 100644 --- a/polycotylus/_docker.py +++ b/polycotylus/_docker.py @@ -65,6 +65,7 @@ def __init__(self, base, command=None, *flags, volumes=(), check=True, interactive=False, tty=False, root=True, post_mortem=False, architecture=machine(), verbosity=None): tty = tty and sys.stdin.isatty() + github_actions = os.environ.get("GITHUB_ACTIONS") if interactive: verbosity = 2 if verbosity is None: @@ -96,6 +97,8 @@ def __init__(self, base, command=None, *flags, volumes=(), check=True, arguments += command human_friendly = f"$ {docker} run --rm " + shlex.join(arguments) if verbosity >= 1: + if verbosity >= 2 and github_actions: + print("::group::", end="") print(termcolor.colored(human_friendly, "blue"), flush=True) p = _run([docker, "create"] + arguments, stdout=PIPE, stderr=PIPE) @@ -105,8 +108,12 @@ def __init__(self, base, command=None, *flags, volumes=(), check=True, p = _run([docker, "container", "start", "-ia" if interactive else "-a", self.id], stdout=None if verbosity >= 2 else DEVNULL, stderr=STDOUT if verbosity >= 2 else PIPE) + + if verbosity >= 2 and github_actions: + print("::endgroup::", end="") if verbosity >= 2 and self.output: print(flush=True) + self.returncode = p.returncode if check and self.returncode: if post_mortem and globals()["post_mortem"]: @@ -195,13 +202,18 @@ def build(dockerfile, root, *flags, target=None, architecture=machine(), verbosi command = [docker, "build", "-f", str(dockerfile), "--network=host", "."] if verbosity is None: verbosity = _verbosity() + github_actions = os.environ.get("GITHUB_ACTIONS") if target: command += ["--target", target] command += ["--pull", "--platform=linux/" + architecture, *flags] if verbosity >= 1: + if verbosity >= 2 and github_actions: + print("::group::", end="") print(termcolor.colored("$ " + shlex.join(command), "blue")) returncode, output = _tee_run(command, verbosity, cwd=root, env={"DOCKER_SCAN_SUGGEST": "false", **os.environ}) + if verbosity >= 2 and github_actions: + print("::endgroup::", flush=True) if returncode: raise Error("$ " + shlex.join(command), output) return _audit_image(_parse_build_output(output))