Skip to content

Commit

Permalink
Merge pull request #124 from tremble/tox/labels
Browse files Browse the repository at this point in the history
Support running tox with labels
  • Loading branch information
jillr authored Sep 28, 2023
2 parents d74ea0a + 3dd6289 commit c08be35
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 4 deletions.
12 changes: 12 additions & 0 deletions .github/actions/tox/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ inputs:
description: tox env list
required: false
default: ""
tox_labellist:
description: tox label list
required: false
default: ""
tox_config_file:
description: tox configuration file
required: false
Expand Down Expand Up @@ -63,6 +67,9 @@ runs:
if [ ! -z "${TOX_ENV_LIST}" ]; then
PY_OPTIONS="${PY_OPTIONS} --tox-envname ${TOX_ENV_LIST}"
fi
if [ ! -z "${TOX_LABEL_LIST}" ]; then
PY_OPTIONS="${PY_OPTIONS} --tox-labelname ${TOX_LABEL_LIST}"
fi
if [ ! -z "${TOX_CONSTRAINTS}" ]; then
PY_OPTIONS="${PY_OPTIONS} --tox-constraints-file ${TOX_CONSTRAINTS}"
fi
Expand All @@ -73,6 +80,7 @@ runs:
env:
TOX_CONFIG_FILE: ${{ inputs.tox_config_file }}
TOX_ENV_LIST: ${{ inputs.tox_envlist }}
TOX_LABEL_LIST: ${{ inputs.tox_labellist }}
TOX_CONSTRAINTS: ${{ inputs.tox_constraints_file }}
TOX_ENVIRONMENT: ${{ inputs.tox_environment }}

Expand All @@ -98,9 +106,13 @@ runs:
if [ ! -z "${TOX_ENV_LIST}" ]; then
TOX_CMD_OPTIONS="${TOX_CMD_OPTIONS} -e ${TOX_ENV_LIST}"
fi
if [ ! -z "${TOX_LABEL_LIST}" ]; then
TOX_CMD_OPTIONS="${TOX_CMD_OPTIONS} -m ${TOX_LABEL_LIST}"
fi
echo "tox_common_args=${TOX_CMD_OPTIONS}" >> $GITHUB_OUTPUT
env:
TOX_CONFIG_FILE: ${{ inputs.tox_config_file }}
TOX_LABEL_LIST: ${{ inputs.tox_labellist }}
TOX_ENV_LIST: ${{ inputs.tox_envlist }}

- name: Set environment variables
Expand Down
26 changes: 22 additions & 4 deletions .github/actions/tox/install_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
logger.setLevel(logging.DEBUG)


# pylint: disable-next=too-many-arguments
def run_tox_command(
project_dir: PosixPath,
env_name: Optional[str],
label_name: Optional[str],
config_file: Optional[PosixPath],
env_vars: Optional[dict[Any, Any]],
extra_args: list[str],
Expand All @@ -35,6 +37,7 @@ def run_tox_command(
:param project_dir: The location of the project containing tox.ini file.
:param env_name: An optional tox env name.
:param label_name: An optional tox label name.
:param config_file: An optional tox configuration file.
:param env_vars: An optional dictionary of environment to set when running command.
:param extra_args: Tox extra args.
Expand All @@ -43,6 +46,8 @@ def run_tox_command(
tox_cmd = ["tox"]
if env_name:
tox_cmd.extend(["-e", env_name])
if label_name:
tox_cmd.extend(["-m", label_name])
if config_file:
tox_cmd.extend(["-c", str(config_file)])
if extra_args:
Expand Down Expand Up @@ -320,12 +325,15 @@ def main() -> None:
parser.add_argument(
"--tox-config-file", type=PosixPath, help="the location of the tox configuration file"
)
parser.add_argument("--tox-envname", help="the tox env name. e.g: env1=value1\nenv2=value2")
parser.add_argument("--tox-envname", help="the tox env name.")
parser.add_argument("--tox-labelname", help="the tox label name.")
parser.add_argument(
"--tox-project-dir", default=".", help="the location of the project containing tox.ini file"
)
parser.add_argument(
"--tox-env-vars", default="", help="the environment to set when running tox command."
"--tox-env-vars",
default="",
help="the environment to set when running tox command. e.g: env1=value1\nenv2=value2",
)
parser.add_argument(
"--tox-constraints-file", type=PosixPath, help="the location to the tox constraints file."
Expand All @@ -352,13 +360,23 @@ def main() -> None:
if tox_extra_args:
extra_args.append(tox_extra_args)
run_tox_command(
args.tox_project_dir, args.tox_envname, args.tox_config_file, tox_environment, extra_args
args.tox_project_dir,
args.tox_envname,
args.tox_labelname,
args.tox_config_file,
tox_environment,
extra_args,
)

# show environment config
extra_args = ["--showconfig"]
tox_raw_config = run_tox_command(
args.tox_project_dir, args.tox_envname, args.tox_config_file, tox_environment, extra_args
args.tox_project_dir,
args.tox_envname,
args.tox_labelname,
args.tox_config_file,
tox_environment,
extra_args,
)
logger.info("Show config => %s", tox_raw_config)

Expand Down
28 changes: 28 additions & 0 deletions .github/workflows/tox.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: tox
on:
workflow_call:
inputs:
envname:
description: Tox environment name to use to limit the run
required: false
type: string
default: ""
labelname:
description: Tox label to use to limit the run
required: false
type: string
default: ""
jobs:
tox:
runs-on: ubuntu-latest
name: Run Tox based code tests
steps:
- name: Code checkout
uses: actions/checkout@v3

- name: Run tests
uses: ansible-network/github_actions/.github/actions/tox@main
with:
path: "."
tox_envlist: ${{ inputs.envname }}
tox_labellist: ${{ inputs.labelname }}

0 comments on commit c08be35

Please sign in to comment.