Skip to content

Commit be17c39

Browse files
committed
Add support for labels (tox v4) to the tox action
1 parent d74ea0a commit be17c39

File tree

3 files changed

+61
-4
lines changed

3 files changed

+61
-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: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
def run_tox_command(
2828
project_dir: PosixPath,
2929
env_name: Optional[str],
30+
label_name: Optional[str],
3031
config_file: Optional[PosixPath],
3132
env_vars: Optional[dict[Any, Any]],
3233
extra_args: list[str],
@@ -35,6 +36,7 @@ def run_tox_command(
3536
3637
:param project_dir: The location of the project containing tox.ini file.
3738
:param env_name: An optional tox env name.
39+
:param label_name: An optional tox label name.
3840
:param config_file: An optional tox configuration file.
3941
:param env_vars: An optional dictionary of environment to set when running command.
4042
:param extra_args: Tox extra args.
@@ -43,6 +45,8 @@ def run_tox_command(
4345
tox_cmd = ["tox"]
4446
if env_name:
4547
tox_cmd.extend(["-e", env_name])
48+
if label_name:
49+
tox_cmd.extend(["-m", label_name])
4650
if config_file:
4751
tox_cmd.extend(["-c", str(config_file)])
4852
if extra_args:
@@ -320,12 +324,15 @@ def main() -> None:
320324
parser.add_argument(
321325
"--tox-config-file", type=PosixPath, help="the location of the tox configuration file"
322326
)
323-
parser.add_argument("--tox-envname", help="the tox env name. e.g: env1=value1\nenv2=value2")
327+
parser.add_argument("--tox-envname", help="the tox env name.")
328+
parser.add_argument("--tox-labelname", help="the tox label name.")
324329
parser.add_argument(
325330
"--tox-project-dir", default=".", help="the location of the project containing tox.ini file"
326331
)
327332
parser.add_argument(
328-
"--tox-env-vars", default="", help="the environment to set when running tox command."
333+
"--tox-env-vars",
334+
default="",
335+
help="the environment to set when running tox command. e.g: env1=value1\nenv2=value2",
329336
)
330337
parser.add_argument(
331338
"--tox-constraints-file", type=PosixPath, help="the location to the tox constraints file."
@@ -352,13 +359,23 @@ def main() -> None:
352359
if tox_extra_args:
353360
extra_args.append(tox_extra_args)
354361
run_tox_command(
355-
args.tox_project_dir, args.tox_envname, args.tox_config_file, tox_environment, extra_args
362+
args.tox_project_dir,
363+
args.tox_envname,
364+
args.tox_labelname,
365+
args.tox_config_file,
366+
tox_environment,
367+
extra_args,
356368
)
357369

358370
# show environment config
359371
extra_args = ["--showconfig"]
360372
tox_raw_config = run_tox_command(
361-
args.tox_project_dir, args.tox_envname, args.tox_config_file, tox_environment, extra_args
373+
args.tox_project_dir,
374+
args.tox_envname,
375+
args.tox_labelname,
376+
args.tox_config_file,
377+
tox_environment,
378+
extra_args,
362379
)
363380
logger.info("Show config => %s", tox_raw_config)
364381

.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)