Skip to content

Commit

Permalink
Add skip_explode optional argument (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea authored Aug 7, 2024
1 parent 832e995 commit 4f9eaa8
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 30 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ projects using:
- `linux`: matrix expansion strategy for Linux, `full` or `minmax`.
- `windows`: matrix expansion strategy for Windows, `full` or `minmax`.
- `macos`: matrix expansion strategy for MacOS, `full` or `minmax`.
- `skip_explode`: pass 1 if you want to avoid generating implicit pyXY jobs.

## Examples

Expand Down
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ inputs:
description: >
Expansion strategy for windows, full or minmax.
default: minmax # costly/slow
skip_explode:
description: >
If changed to "1", it will disable generating jobs for each python
version and will only return values for jobs inside 'other_names'.
default: "0"

outputs:
matrix_include:
Expand Down
68 changes: 38 additions & 30 deletions entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
IMPLICIT_MIN_PYTHON = "3.8"
IMPLICIT_MAX_PYTHON = "3.12"
IMPLICIT_DEFAULT_PYTHON = "3.9"

IMPLICIT_SKIP_EXPLODE = "0"

# loop list staring with given item
def main() -> None:
Expand All @@ -34,20 +34,26 @@ def main() -> None:
min_python = core.get_input("min_python") or IMPLICIT_MIN_PYTHON
max_python = core.get_input("max_python") or IMPLICIT_MAX_PYTHON
default_python = core.get_input("default_python") or IMPLICIT_DEFAULT_PYTHON
skip_explode = int(core.get_input("skip_explode") or IMPLICIT_SKIP_EXPLODE)
strategies = {}
for platform in PLATFORM_MAP:
strategies[platform] = core.get_input(platform, required=False)

core.debug(f"Testing strategy: {strategies}")

result = []
if max_python == "3.13":
python_names = KNOWN_PYTHONS[KNOWN_PYTHONS.index(min_python) :]
else:
python_names = KNOWN_PYTHONS[
KNOWN_PYTHONS.index(min_python) : (KNOWN_PYTHONS.index(max_python) + 1)
]
try:
if max_python == "3.13":
python_names = KNOWN_PYTHONS[KNOWN_PYTHONS.index(min_python) :]
else:
python_names = KNOWN_PYTHONS[
KNOWN_PYTHONS.index(min_python) : (KNOWN_PYTHONS.index(max_python) + 1)
]
except Exception as e:
core.debug(e)
python_names = ()
python_flavours = len(python_names)
core.debug("...")
for env in other_names:
env_python = default_python
# Check for using correct python version for other_names like py310-devel.
Expand All @@ -64,27 +70,28 @@ def main() -> None:
}
)

for platform in platforms:
for i, python in enumerate(python_names):
py_name = re.sub(r"[^0-9]", "", python.strip("."))
if platform == IMPLICIT_PLATFORM:
suffix = ""
else:
suffix = f"-{platform}"
if not skip_explode:
for platform in platforms:
for i, python in enumerate(python_names):
py_name = re.sub(r"[^0-9]", "", python.strip("."))
if platform == IMPLICIT_PLATFORM:
suffix = ""
else:
suffix = f"-{platform}"

if strategies[platform] == "minmax" and (
i not in (0, python_flavours - 1)
):
continue
if strategies[platform] == "minmax" and (
i not in (0, python_flavours - 1)
):
continue

result.append(
{
"name": f"py{py_name}{suffix}",
"python_version": python,
"os": PLATFORM_MAP.get(platform, platform),
"passed_name": f"py{py_name}",
}
)
result.append(
{
"name": f"py{py_name}{suffix}",
"python_version": python,
"os": PLATFORM_MAP.get(platform, platform),
"passed_name": f"py{py_name}",
}
)

core.info(f"Generated {len(result)} matrix entries.")
names = [k["name"] for k in result]
Expand All @@ -100,12 +107,13 @@ def main() -> None:
if __name__ == "__main__":
# only used for local testing, emulating use from github actions
if os.getenv("GITHUB_ACTIONS") is None:
os.environ["INPUT_OTHER_NAMES"] = "lint\npkg\npy313-devel"
os.environ["INPUT_MIN_PYTHON"] = "3.8"
os.environ["INPUT_MAX_PYTHON"] = "3.13"
os.environ["INPUT_DEFAULT_PYTHON"] = "3.10"
os.environ["INPUT_PLATFORMS"] = "linux,macos" # macos and windows
os.environ["INPUT_LINUX"] = "full"
os.environ["INPUT_MACOS"] = "minmax"
os.environ["INPUT_MAX_PYTHON"] = "3.13"
os.environ["INPUT_MIN_PYTHON"] = "3.8"
os.environ["INPUT_OTHER_NAMES"] = "lint\npkg\npy313-devel"
os.environ["INPUT_PLATFORMS"] = "linux,macos" # macos and windows
os.environ["INPUT_SKIP_EXPLODE"] = "0"
os.environ["INPUT_WINDOWS"] = "minmax"
main()

0 comments on commit 4f9eaa8

Please sign in to comment.