Skip to content

Commit 60f0e3d

Browse files
authored
Return multiple python versions when needed (#40)
1 parent 0b15c49 commit 60f0e3d

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,22 @@ The returned tox environment name from returned `passed_name` was replaced by
3030
- run: ${{ matrix.command }}
3131
```
3232
33+
## Returned values
34+
35+
This action returns a list of actions to be executed, each of them containing
36+
the following fields:
37+
38+
- `name` of the job to run
39+
40+
- `command`, and optional `command2`, `command3`, ... which are the commands
41+
to be executed using `run: ` step.
42+
43+
- `python_version` is a string compatible with the expected format used by
44+
[actions/setup-python](https://github.com/actions/setup-python) github action,
45+
like `3.12` or `3.11\n3.12` when multiple python versions are to be installed.
46+
47+
- `os` the name of an github runner, should be passed to `runs_on: `
48+
3349
## Examples
3450
3551
Simple workflow using coactions/dynamic-matrix

entrypoint.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,12 @@ def sort_key(s: str) -> tuple[int, str]:
122122
commands = _.split(";")
123123
env_python = default_python
124124
# Check for using correct python version for other_names like py310-devel.
125-
match = re.search(r"py(\d+)", name)
126-
if match:
127-
py_version = match.groups()[0]
125+
pythons: list[str] = []
126+
for py_version in re.findall(r"py(\d+)", line):
128127
env_python = f"{py_version[0]}.{py_version[1:]}"
128+
pythons.append(PYTHON_REDIRECTS.get(env_python, env_python))
129+
if not pythons:
130+
pythons.append(default_python)
129131
for platform_name in platform_names_sorted:
130132
if platform_name in name:
131133
break
@@ -135,7 +137,7 @@ def sort_key(s: str) -> tuple[int, str]:
135137
data = {
136138
"name": name,
137139
"command": commands[0],
138-
"python_version": PYTHON_REDIRECTS.get(env_python, env_python),
140+
"python_version": "\n".join(pythons),
139141
"os": PLATFORM_MAP[platform_name],
140142
}
141143
for index, command in enumerate(commands[1:]):

tests/test_action.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"INPUT_MACOS": "minmax",
2020
"INPUT_MAX_PYTHON": "3.8",
2121
"INPUT_MIN_PYTHON": "3.8",
22-
"INPUT_OTHER_NAMES": "z\nall-linux-arm64:tox -e unit;tox -e integration",
22+
"INPUT_OTHER_NAMES": "z\nall-linux-arm64:tox -e py38-unit;tox -e py310-integration",
2323
"INPUT_PLATFORMS": "linux-arm64:ubuntu-24.04-arm64-2core",
2424
"INPUT_SKIP_EXPLODE": "1",
2525
"INPUT_WINDOWS": "minmax",
@@ -28,11 +28,11 @@
2828
"matrix": {
2929
"include": [
3030
{
31-
"command": "tox -e unit",
32-
"command2": "tox -e integration",
31+
"command": "tox -e py38-unit",
32+
"command2": "tox -e py310-integration",
3333
"name": "all-linux-arm64",
3434
"os": "ubuntu-24.04-arm64-2core",
35-
"python_version": "3.8",
35+
"python_version": "3.8\n3.10",
3636
},
3737
{
3838
"command": "tox -e z",
@@ -71,5 +71,5 @@ def test_action(passed_env: dict[str, str], expected: dict[str, str]) -> None:
7171
assert isinstance(data, dict), data
7272
assert len(data) == 1
7373
assert "matrix" in data
74-
assert data == expected
74+
assert data == expected, result
7575
# TestCase().assertDictEqual(data, expected)

0 commit comments

Comments
 (0)