Skip to content

Commit c08be35

Browse files
authored
Merge pull request #124 from tremble/tox/labels
Support running tox with labels
2 parents d74ea0a + 3dd6289 commit c08be35

File tree

3 files changed

+62
-4
lines changed

3 files changed

+62
-4
lines changed

.github/actions/tox/action.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ inputs:
1414
description: tox env list
1515
required: false
1616
default: ""
17+
tox_labellist:
18+
description: tox label list
19+
required: false
20+
default: ""
1721
tox_config_file:
1822
description: tox configuration file
1923
required: false
@@ -63,6 +67,9 @@ runs:
6367
if [ ! -z "${TOX_ENV_LIST}" ]; then
6468
PY_OPTIONS="${PY_OPTIONS} --tox-envname ${TOX_ENV_LIST}"
6569
fi
70+
if [ ! -z "${TOX_LABEL_LIST}" ]; then
71+
PY_OPTIONS="${PY_OPTIONS} --tox-labelname ${TOX_LABEL_LIST}"
72+
fi
6673
if [ ! -z "${TOX_CONSTRAINTS}" ]; then
6774
PY_OPTIONS="${PY_OPTIONS} --tox-constraints-file ${TOX_CONSTRAINTS}"
6875
fi
@@ -73,6 +80,7 @@ runs:
7380
env:
7481
TOX_CONFIG_FILE: ${{ inputs.tox_config_file }}
7582
TOX_ENV_LIST: ${{ inputs.tox_envlist }}
83+
TOX_LABEL_LIST: ${{ inputs.tox_labellist }}
7684
TOX_CONSTRAINTS: ${{ inputs.tox_constraints_file }}
7785
TOX_ENVIRONMENT: ${{ inputs.tox_environment }}
7886

@@ -98,9 +106,13 @@ runs:
98106
if [ ! -z "${TOX_ENV_LIST}" ]; then
99107
TOX_CMD_OPTIONS="${TOX_CMD_OPTIONS} -e ${TOX_ENV_LIST}"
100108
fi
109+
if [ ! -z "${TOX_LABEL_LIST}" ]; then
110+
TOX_CMD_OPTIONS="${TOX_CMD_OPTIONS} -m ${TOX_LABEL_LIST}"
111+
fi
101112
echo "tox_common_args=${TOX_CMD_OPTIONS}" >> $GITHUB_OUTPUT
102113
env:
103114
TOX_CONFIG_FILE: ${{ inputs.tox_config_file }}
115+
TOX_LABEL_LIST: ${{ inputs.tox_labellist }}
104116
TOX_ENV_LIST: ${{ inputs.tox_envlist }}
105117

106118
- name: Set environment variables

.github/actions/tox/install_packages.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@
2424
logger.setLevel(logging.DEBUG)
2525

2626

27+
# pylint: disable-next=too-many-arguments
2728
def run_tox_command(
2829
project_dir: PosixPath,
2930
env_name: Optional[str],
31+
label_name: Optional[str],
3032
config_file: Optional[PosixPath],
3133
env_vars: Optional[dict[Any, Any]],
3234
extra_args: list[str],
@@ -35,6 +37,7 @@ def run_tox_command(
3537
3638
:param project_dir: The location of the project containing tox.ini file.
3739
:param env_name: An optional tox env name.
40+
:param label_name: An optional tox label name.
3841
:param config_file: An optional tox configuration file.
3942
:param env_vars: An optional dictionary of environment to set when running command.
4043
:param extra_args: Tox extra args.
@@ -43,6 +46,8 @@ def run_tox_command(
4346
tox_cmd = ["tox"]
4447
if env_name:
4548
tox_cmd.extend(["-e", env_name])
49+
if label_name:
50+
tox_cmd.extend(["-m", label_name])
4651
if config_file:
4752
tox_cmd.extend(["-c", str(config_file)])
4853
if extra_args:
@@ -320,12 +325,15 @@ def main() -> None:
320325
parser.add_argument(
321326
"--tox-config-file", type=PosixPath, help="the location of the tox configuration file"
322327
)
323-
parser.add_argument("--tox-envname", help="the tox env name. e.g: env1=value1\nenv2=value2")
328+
parser.add_argument("--tox-envname", help="the tox env name.")
329+
parser.add_argument("--tox-labelname", help="the tox label name.")
324330
parser.add_argument(
325331
"--tox-project-dir", default=".", help="the location of the project containing tox.ini file"
326332
)
327333
parser.add_argument(
328-
"--tox-env-vars", default="", help="the environment to set when running tox command."
334+
"--tox-env-vars",
335+
default="",
336+
help="the environment to set when running tox command. e.g: env1=value1\nenv2=value2",
329337
)
330338
parser.add_argument(
331339
"--tox-constraints-file", type=PosixPath, help="the location to the tox constraints file."
@@ -352,13 +360,23 @@ def main() -> None:
352360
if tox_extra_args:
353361
extra_args.append(tox_extra_args)
354362
run_tox_command(
355-
args.tox_project_dir, args.tox_envname, args.tox_config_file, tox_environment, extra_args
363+
args.tox_project_dir,
364+
args.tox_envname,
365+
args.tox_labelname,
366+
args.tox_config_file,
367+
tox_environment,
368+
extra_args,
356369
)
357370

358371
# show environment config
359372
extra_args = ["--showconfig"]
360373
tox_raw_config = run_tox_command(
361-
args.tox_project_dir, args.tox_envname, args.tox_config_file, tox_environment, extra_args
374+
args.tox_project_dir,
375+
args.tox_envname,
376+
args.tox_labelname,
377+
args.tox_config_file,
378+
tox_environment,
379+
extra_args,
362380
)
363381
logger.info("Show config => %s", tox_raw_config)
364382

.github/workflows/tox.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: tox
2+
on:
3+
workflow_call:
4+
inputs:
5+
envname:
6+
description: Tox environment name to use to limit the run
7+
required: false
8+
type: string
9+
default: ""
10+
labelname:
11+
description: Tox label to use to limit the run
12+
required: false
13+
type: string
14+
default: ""
15+
jobs:
16+
tox:
17+
runs-on: ubuntu-latest
18+
name: Run Tox based code tests
19+
steps:
20+
- name: Code checkout
21+
uses: actions/checkout@v3
22+
23+
- name: Run tests
24+
uses: ansible-network/github_actions/.github/actions/tox@main
25+
with:
26+
path: "."
27+
tox_envlist: ${{ inputs.envname }}
28+
tox_labellist: ${{ inputs.labelname }}

0 commit comments

Comments
 (0)