Skip to content

Commit

Permalink
Return multiple python versions when needed (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea authored Aug 23, 2024
1 parent 0b15c49 commit 60f0e3d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,22 @@ The returned tox environment name from returned `passed_name` was replaced by
- run: ${{ matrix.command }}
```
## Returned values
This action returns a list of actions to be executed, each of them containing
the following fields:
- `name` of the job to run

- `command`, and optional `command2`, `command3`, ... which are the commands
to be executed using `run: ` step.
- `python_version` is a string compatible with the expected format used by
[actions/setup-python](https://github.com/actions/setup-python) github action,
like `3.12` or `3.11\n3.12` when multiple python versions are to be installed.

- `os` the name of an github runner, should be passed to `runs_on: `
## Examples
Simple workflow using coactions/dynamic-matrix
Expand Down
10 changes: 6 additions & 4 deletions entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,12 @@ def sort_key(s: str) -> tuple[int, str]:
commands = _.split(";")
env_python = default_python
# Check for using correct python version for other_names like py310-devel.
match = re.search(r"py(\d+)", name)
if match:
py_version = match.groups()[0]
pythons: list[str] = []
for py_version in re.findall(r"py(\d+)", line):
env_python = f"{py_version[0]}.{py_version[1:]}"
pythons.append(PYTHON_REDIRECTS.get(env_python, env_python))
if not pythons:
pythons.append(default_python)
for platform_name in platform_names_sorted:
if platform_name in name:
break
Expand All @@ -135,7 +137,7 @@ def sort_key(s: str) -> tuple[int, str]:
data = {
"name": name,
"command": commands[0],
"python_version": PYTHON_REDIRECTS.get(env_python, env_python),
"python_version": "\n".join(pythons),
"os": PLATFORM_MAP[platform_name],
}
for index, command in enumerate(commands[1:]):
Expand Down
10 changes: 5 additions & 5 deletions tests/test_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"INPUT_MACOS": "minmax",
"INPUT_MAX_PYTHON": "3.8",
"INPUT_MIN_PYTHON": "3.8",
"INPUT_OTHER_NAMES": "z\nall-linux-arm64:tox -e unit;tox -e integration",
"INPUT_OTHER_NAMES": "z\nall-linux-arm64:tox -e py38-unit;tox -e py310-integration",
"INPUT_PLATFORMS": "linux-arm64:ubuntu-24.04-arm64-2core",
"INPUT_SKIP_EXPLODE": "1",
"INPUT_WINDOWS": "minmax",
Expand All @@ -28,11 +28,11 @@
"matrix": {
"include": [
{
"command": "tox -e unit",
"command2": "tox -e integration",
"command": "tox -e py38-unit",
"command2": "tox -e py310-integration",
"name": "all-linux-arm64",
"os": "ubuntu-24.04-arm64-2core",
"python_version": "3.8",
"python_version": "3.8\n3.10",
},
{
"command": "tox -e z",
Expand Down Expand Up @@ -71,5 +71,5 @@ def test_action(passed_env: dict[str, str], expected: dict[str, str]) -> None:
assert isinstance(data, dict), data
assert len(data) == 1
assert "matrix" in data
assert data == expected
assert data == expected, result
# TestCase().assertDictEqual(data, expected)

0 comments on commit 60f0e3d

Please sign in to comment.