diff --git a/src/tox_ansible/plugin.py b/src/tox_ansible/plugin.py index c648f20..5cdfbf8 100644 --- a/src/tox_ansible/plugin.py +++ b/src/tox_ansible/plugin.py @@ -15,7 +15,6 @@ from typing import TYPE_CHECKING, List, TypeVar import yaml -# import q from tox.config.loader.memory import MemoryLoader from tox.config.loader.section import Section from tox.config.loader.str_convert import StrConvert @@ -110,13 +109,18 @@ def tox_add_option(parser: ToxParser) -> None: :param parser: The tox CLI parser. """ + parser.add_argument( + "--matrix-scope", + default="all", + choices=["all", "sanity", "integration", "unit"], + help="Emit a github matrix specific to scope mentioned", + ) + parser.add_argument( "--gh-matrix", action="store_true", default=False, - # choices=["all", "sanity", "integration", "unit"], help="Emit a github matrix", - # type=str, ) parser.add_argument( @@ -157,11 +161,11 @@ def tox_add_core_config( global TOX_WORK_DIR # pylint: disable=global-statement # noqa: PLW0603 TOX_WORK_DIR = state.conf.work_dir env_list = add_ansible_matrix(state) - # q(state.conf.options.gh_matrix) + if not state.conf.options.gh_matrix: return - generate_gh_matrix(env_list=env_list) + generate_gh_matrix(env_list=env_list, section=state.conf.options.matrix_scope) sys.exit(0) @@ -258,14 +262,17 @@ def add_ansible_matrix(state: State) -> EnvList: return env_list -def generate_gh_matrix(env_list: EnvList) -> None: +def generate_gh_matrix(env_list: EnvList, section: str) -> None: """Generate the github matrix. :param env_list: The environment list. + :param section: The test section to be generated. """ results = [] for env_name in env_list.envs: + if section != "all" and not env_name.startswith(section): + continue candidates = [] factors = env_name.split("-") for factor in factors: