Skip to content

Commit 44bc2f0

Browse files
authored
Allow use of custom runners (#44)
1 parent 6385e27 commit 44bc2f0

File tree

5 files changed

+46
-16
lines changed

5 files changed

+46
-16
lines changed

.pre-commit-config.yaml

+6-6
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@ repos:
1616
- prettier
1717
- prettier-plugin-toml
1818
- repo: https://github.com/streetsidesoftware/cspell-cli
19-
rev: v8.13.3
19+
rev: v8.14.0
2020
hooks:
2121
- id: cspell
2222
# entry: codespell --relative
2323
args: [--relative, --no-progress, --no-summary]
2424
name: Spell check with cspell
2525
- repo: https://github.com/sirosen/check-jsonschema
26-
rev: 0.29.2
26+
rev: 0.29.3
2727
hooks:
2828
- id: check-github-workflows
2929
- repo: https://github.com/pre-commit/pre-commit-hooks.git
30-
rev: v4.6.0
30+
rev: v5.0.0
3131
hooks:
3232
- id: end-of-file-fixer
3333
- id: trailing-whitespace
@@ -36,14 +36,14 @@ repos:
3636
- id: check-executables-have-shebangs
3737
- id: check-merge-conflict
3838
- repo: https://github.com/astral-sh/ruff-pre-commit
39-
rev: "v0.6.3"
39+
rev: "v0.6.9"
4040
hooks:
4141
- id: ruff
4242
args: [--fix, --exit-non-zero-on-fix]
4343
additional_dependencies:
4444
- pytest
4545
- repo: https://github.com/psf/black
46-
rev: 24.8.0
46+
rev: 24.10.0
4747
hooks:
4848
- id: black
4949
language_version: python3
@@ -57,7 +57,7 @@ repos:
5757
- actions-toolkit
5858
- pytest
5959
- repo: https://github.com/pycqa/pylint
60-
rev: v3.2.7
60+
rev: v3.3.1
6161
hooks:
6262
- id: pylint
6363
args:

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ jobs:
6868
lint
6969
pkg
7070
py39-all:tox -f py39
71+
py39-arm64:tox -e py39:runner=ubuntu-24.04-arm64
72+
# ^ job-visible name : optional command : optional arguments
73+
# command can use ; as separator to run multiple commands
74+
# the only recognized argument is now 'runner'
7175

7276
build:
7377
name: ${{ matrix.name }}

entrypoint.py

+28-9
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def produce_output(output: dict[str, Any]) -> None:
7676

7777

7878
# loop list staring with given item
79-
# pylint: disable=too-many-locals,too-many-branches
79+
# pylint: disable=too-many-locals,too-many-branches,too-many-statements
8080
def main() -> None: # noqa: C901,PLR0912,PLR0915
8181
"""Main."""
8282
# print all env vars starting with INPUT_
@@ -121,8 +121,25 @@ def sort_key(s: str) -> tuple[int, str]:
121121
core.info(f"Known platforms sorted: {platform_names_sorted}")
122122

123123
for line in other_names:
124-
name, _ = line.split(":", 1) if ":" in line else (line, f"tox -e {line}")
125-
commands = _.split(";")
124+
# line can look like:
125+
# - name
126+
# - name:command1;command2
127+
# - name:command:runner=ubuntu-20.04
128+
segments = line.split(":")
129+
name = segments[0]
130+
commands = [f"tox -e {name}"] # implicit commands if not provided
131+
args = {}
132+
if len(segments) > 1 and segments[1]:
133+
commands = segments[1].split(";")
134+
if len(segments) > 2: # noqa: PLR2004
135+
# we have arguments foo=bar;baz=qux
136+
try:
137+
args = dict(x.split("=") for x in segments[2].split(";"))
138+
except ValueError:
139+
core.set_failed(
140+
f"Action failed due to optional args not having the expected format 'a=b;c=d', value being '{segments[2]}'",
141+
)
142+
126143
env_python = default_python
127144
# Check for using correct python version for other_names like py310-devel.
128145
pythons: list[str] = []
@@ -131,17 +148,19 @@ def sort_key(s: str) -> tuple[int, str]:
131148
pythons.append(PYTHON_REDIRECTS.get(env_python, env_python))
132149
if not pythons:
133150
pythons.append(default_python)
134-
for platform_name in platform_names_sorted:
135-
if platform_name in name:
136-
break
137-
else:
138-
platform_name = "linux" # implicit platform (os) to use
151+
if "runner" not in args:
152+
for platform_name in platform_names_sorted:
153+
if platform_name in name:
154+
break
155+
else:
156+
platform_name = "linux" # implicit platform (os) to use
157+
args["runner"] = PLATFORM_MAP[platform_name]
139158

140159
data = {
141160
"name": name,
142161
"command": commands[0],
143162
"python_version": "\n".join(pythons),
144-
"os": PLATFORM_MAP[platform_name],
163+
"os": args["runner"],
145164
}
146165
for index, command in enumerate(commands[1:]):
147166
data[f"command{index + 2}"] = command

tests/test_action.py

+7-1
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 py38-unit;tox -e py310-integration",
22+
"INPUT_OTHER_NAMES": "z\nall-linux-arm64:tox -e py38-unit;tox -e py310-integration\nfoo::runner=custom-arm64",
2323
"INPUT_PLATFORMS": "linux-arm64:ubuntu-24.04-arm64-2core",
2424
"INPUT_SKIP_EXPLODE": "1",
2525
"INPUT_WINDOWS": "minmax",
@@ -34,6 +34,12 @@
3434
"os": "ubuntu-24.04-arm64-2core",
3535
"python_version": "3.8\n3.10",
3636
},
37+
{
38+
"command": "tox -e foo",
39+
"name": "foo",
40+
"os": "custom-arm64",
41+
"python_version": "3.8",
42+
},
3743
{
3844
"command": "tox -e z",
3945
"name": "z",

tox.ini

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ commands_pre =
2121
{envpython} -m pip check
2222
commands =
2323
coverage run -m pytest {posargs:\
24+
-v \
2425
-n 0 \
2526
-ra \
2627
--showlocals \

0 commit comments

Comments
 (0)