Skip to content

Commit

Permalink
Allow use of custom runners (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea authored Oct 9, 2024
1 parent 6385e27 commit 44bc2f0
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 16 deletions.
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ repos:
- prettier
- prettier-plugin-toml
- repo: https://github.com/streetsidesoftware/cspell-cli
rev: v8.13.3
rev: v8.14.0
hooks:
- id: cspell
# entry: codespell --relative
args: [--relative, --no-progress, --no-summary]
name: Spell check with cspell
- repo: https://github.com/sirosen/check-jsonschema
rev: 0.29.2
rev: 0.29.3
hooks:
- id: check-github-workflows
- repo: https://github.com/pre-commit/pre-commit-hooks.git
rev: v4.6.0
rev: v5.0.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
Expand All @@ -36,14 +36,14 @@ repos:
- id: check-executables-have-shebangs
- id: check-merge-conflict
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.6.3"
rev: "v0.6.9"
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
additional_dependencies:
- pytest
- repo: https://github.com/psf/black
rev: 24.8.0
rev: 24.10.0
hooks:
- id: black
language_version: python3
Expand All @@ -57,7 +57,7 @@ repos:
- actions-toolkit
- pytest
- repo: https://github.com/pycqa/pylint
rev: v3.2.7
rev: v3.3.1
hooks:
- id: pylint
args:
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ jobs:
lint
pkg
py39-all:tox -f py39
py39-arm64:tox -e py39:runner=ubuntu-24.04-arm64
# ^ job-visible name : optional command : optional arguments
# command can use ; as separator to run multiple commands
# the only recognized argument is now 'runner'

build:
name: ${{ matrix.name }}
Expand Down
37 changes: 28 additions & 9 deletions entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def produce_output(output: dict[str, Any]) -> None:


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

for line in other_names:
name, _ = line.split(":", 1) if ":" in line else (line, f"tox -e {line}")
commands = _.split(";")
# line can look like:
# - name
# - name:command1;command2
# - name:command:runner=ubuntu-20.04
segments = line.split(":")
name = segments[0]
commands = [f"tox -e {name}"] # implicit commands if not provided
args = {}
if len(segments) > 1 and segments[1]:
commands = segments[1].split(";")
if len(segments) > 2: # noqa: PLR2004
# we have arguments foo=bar;baz=qux
try:
args = dict(x.split("=") for x in segments[2].split(";"))
except ValueError:
core.set_failed(
f"Action failed due to optional args not having the expected format 'a=b;c=d', value being '{segments[2]}'",
)

env_python = default_python
# Check for using correct python version for other_names like py310-devel.
pythons: list[str] = []
Expand All @@ -131,17 +148,19 @@ def sort_key(s: str) -> tuple[int, str]:
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
else:
platform_name = "linux" # implicit platform (os) to use
if "runner" not in args:
for platform_name in platform_names_sorted:
if platform_name in name:
break
else:
platform_name = "linux" # implicit platform (os) to use
args["runner"] = PLATFORM_MAP[platform_name]

data = {
"name": name,
"command": commands[0],
"python_version": "\n".join(pythons),
"os": PLATFORM_MAP[platform_name],
"os": args["runner"],
}
for index, command in enumerate(commands[1:]):
data[f"command{index + 2}"] = command
Expand Down
8 changes: 7 additions & 1 deletion 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 py38-unit;tox -e py310-integration",
"INPUT_OTHER_NAMES": "z\nall-linux-arm64:tox -e py38-unit;tox -e py310-integration\nfoo::runner=custom-arm64",
"INPUT_PLATFORMS": "linux-arm64:ubuntu-24.04-arm64-2core",
"INPUT_SKIP_EXPLODE": "1",
"INPUT_WINDOWS": "minmax",
Expand All @@ -34,6 +34,12 @@
"os": "ubuntu-24.04-arm64-2core",
"python_version": "3.8\n3.10",
},
{
"command": "tox -e foo",
"name": "foo",
"os": "custom-arm64",
"python_version": "3.8",
},
{
"command": "tox -e z",
"name": "z",
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ commands_pre =
{envpython} -m pip check
commands =
coverage run -m pytest {posargs:\
-v \
-n 0 \
-ra \
--showlocals \
Expand Down

0 comments on commit 44bc2f0

Please sign in to comment.