Skip to content

Commit

Permalink
Generate with library
Browse files Browse the repository at this point in the history
  • Loading branch information
ocelotl committed Jul 15, 2024
1 parent 2367af6 commit 89d200f
Show file tree
Hide file tree
Showing 5 changed files with 7,954 additions and 32 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/generate_workflows.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from generate_workflows_lib import generate_test_workflow
from pathlib import Path

from generate_workflows_lib import generate_test_workflow


generate_test_workflow(
Path(__file__).parent.parent.parent.joinpath("tox.ini"),
Path(__file__).parent
Path(__file__).parent,
"ubuntu-latest"
)
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def get_tox_envs(tox_ini_path: Path) -> list:
return core_config_set.load("env_list")


def get_test_jobs_data(tox_envs: list, oss: list) -> list:
def get_test_jobs_data(tox_envs: list, operating_systems: list) -> list:

os_alias = {
"ubuntu-latest": "Ubuntu",
Expand All @@ -60,34 +60,44 @@ def get_test_jobs_data(tox_envs: list, oss: list) -> list:
r"(?P<name>[-\w]+\w)-?(?P<test_requirements>\d+)?"
)

for tox_env in tox_envs:
for operating_system in operating_systems:
for tox_env in tox_envs:

tox_test_env_match = tox_test_env_regex.match(tox_env)
tox_test_env_match = tox_test_env_regex.match(tox_env)

if tox_test_env_match is None:
continue
if tox_test_env_match is None:
continue

groups = tox_test_env_match.groupdict()
groups = tox_test_env_match.groupdict()

aliased_python_version = python_version_alias(groups["python_version"])
tox_env = tox_test_env_match.groups(0)
os = groups["os"]

test_jobs_data.append(
{
"name": f"{tox_env}_{os}",
"ui_name": (
f"{groups['name']}-"
f"{groups['test-requirements']} "
f"{aliased_python_version}"
f"{os_alias[os]}"
),
"python_version": aliased_python_version,
"tox_env": tox_test_env_match.groups(0),
"os": os
}
aliased_python_version = (
python_version_alias[groups["python_version"]]
)
tox_env = tox_test_env_match.string

test_requirements = groups["test_requirements"]

if test_requirements is None:
test_requirements = " "

else:
test_requirements = f"-{test_requirements} "

test_jobs_data.append(
{
"name": f"{tox_env}_{operating_system}",
"ui_name": (
f"{groups['name']}"
f"{test_requirements}"
f"{aliased_python_version} "
f"{os_alias[operating_system]}"
),
"python_version": aliased_python_version,
"tox_env": tox_env,
"os": operating_system
}

)
)

return test_jobs_data

Expand All @@ -96,7 +106,11 @@ def get_lint_jobs_data(tox_envs: list) -> list:
pass


def generate_test_workflow(tox_ini_path: Path, workflow_directory_path: Path):
def generate_test_workflow(
tox_ini_path: Path,
workflow_directory_path: Path,
*operating_systems
) -> None:

with (
open(workflow_directory_path.joinpath("test.yml"), "w") as
Expand All @@ -106,13 +120,19 @@ def generate_test_workflow(tox_ini_path: Path, workflow_directory_path: Path):
Environment(
loader=FileSystemLoader(Path(__file__).parent)
).get_template("test.yml.j2").render(
test_jobs_data=get_test_jobs_data(tox_ini_path)
jobs=get_test_jobs_data(
get_tox_envs(tox_ini_path), operating_systems
)
)
)
test_yml_file.write("\n")


def generate_lint_workflow(tox_ini_path: Path, workflow_directory_path: Path):
def generate_lint_workflow(
tox_ini_path: Path,
workflow_directory_path: Path,
*operating_systems
) -> None:

with (
open(workflow_directory_path.joinpath("lint.yml"), "w") as
Expand All @@ -122,7 +142,9 @@ def generate_lint_workflow(tox_ini_path: Path, workflow_directory_path: Path):
Environment(
loader=FileSystemLoader(Path(__file__).parent)
).get_template("lint.yml.j2").render(
lint_jobs_data=get_lint_jobs_data(tox_ini_path)
lint_jobs_data=get_lint_jobs_data(
tox_ini_path, operating_systems
)
)
)
lint_yml_file.write("\n")
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Do not edit this file.
# This file is generated automatically by executing generate_tests.py.
# This file is generated automatically by executing tox -e generate_workflows

name: Test

Expand Down
Loading

0 comments on commit 89d200f

Please sign in to comment.