diff --git a/src/tox_gh/plugin.py b/src/tox_gh/plugin.py index 5802429..bc03547 100644 --- a/src/tox_gh/plugin.py +++ b/src/tox_gh/plugin.py @@ -6,7 +6,7 @@ import pathlib import shutil import sys -from typing import TYPE_CHECKING, Dict +from typing import TYPE_CHECKING, Any, Dict from tox.config.loader.memory import MemoryLoader from tox.config.loader.section import Section @@ -80,14 +80,37 @@ def tox_add_core_config(core_conf: ConfigSet, state: State) -> None: state.conf.core.loaders.insert(0, MemoryLoader(env_list=env_list)) +installing = False + + +@impl +def tox_on_install(tox_env: ToxEnv, arguments: Any, section: str, of_type: str) -> None: # noqa: ANN401, ARG001 + """ + Run before installing to prepare an environment. + + :param tox_env: the tox environment + :param arguments: installation arguments + :param section: section of the installation + :param of_type: type of the installation + """ + global installing # noqa: PLW0603 + if tox_env.core["is_on_gh_action"] and not installing: + installing = True + print("::group::tox:install") # noqa: T201 + + @impl -def tox_before_run_commands(tox_env: ToxEnv) -> None: +def tox_before_run_commands(tox_env: ToxEnv) -> None: # noqa: ARG001 """ Run logic before tox run commands. :param tox_env: the tox environment """ + global installing # noqa: PLW0603 if tox_env.core["is_on_gh_action"]: + assert installing # noqa: S101 + installing = False + print("::endgroup::") # noqa: T201 print(f"::group::tox:{tox_env.name}") # noqa: T201 diff --git a/tests/test_tox_gh.py b/tests/test_tox_gh.py index b1bb67b..d3d0416 100644 --- a/tests/test_tox_gh.py +++ b/tests/test_tox_gh.py @@ -58,13 +58,17 @@ def test_gh_ok(monkeypatch: MonkeyPatch, tox_project: ToxProjectCreator, tmp_pat assert result.out.splitlines() == [ "ROOT: running tox-gh", "ROOT: tox-gh set a, b", + "::group::tox:install", "a: freeze> python -m pip freeze --all", ANY, # freeze list + "::endgroup::", "::group::tox:a", "::endgroup::", ANY, # a finished + "::group::tox:install", "b: freeze> python -m pip freeze --all", ANY, # freeze list + "::endgroup::", "::group::tox:b", "::endgroup::", ANY, # a status @@ -101,15 +105,19 @@ def test_gh_fail(monkeypatch: MonkeyPatch, tox_project: ToxProjectCreator, tmp_p assert result.out.splitlines() == [ "ROOT: running tox-gh", "ROOT: tox-gh set a, b", + "::group::tox:install", "a: freeze> python -m pip freeze --all", ANY, # freeze list + "::endgroup::", "::group::tox:a", ANY, # "a: commands[0]> python -c 'exit(1)'", but without the quotes on Windows. ANY, # process details "::endgroup::", ANY, # a finished + "::group::tox:install", "b: freeze> python -m pip freeze --all", ANY, # freeze list + "::endgroup::", "::group::tox:b", ANY, # "b: commands[0]> python -c 'exit(1)'", but without the quotes on Windows. ANY, # b process details