Skip to content

Commit

Permalink
Remove duplication of test running information
Browse files Browse the repository at this point in the history
Fixes #2686
  • Loading branch information
ocelotl committed Jul 10, 2024
1 parent 5ff46ac commit dde7615
Show file tree
Hide file tree
Showing 7 changed files with 8,150 additions and 201 deletions.
156 changes: 156 additions & 0 deletions .github/workflows/generate_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
from configparser import ConfigParser
from os.path import join
from pathlib import Path
from re import compile as re_compile
from jinja2 import Environment, FileSystemLoader


tox_ini_paths = []

test_env_regex = re_compile(
r"py(?P<pypy>py)?3(\{(?P<cpython_versions>[\w,]+)\})?-test-"
r"(?P<name>[-\w]+\w)-?(\{(?P<test_versions>[\d,]+)\})?"
)

short_regex = re_compile(r"-test-")
tox_ini_path = join(str(Path(__file__).parents[2]), "tox.ini")
config_parser = ConfigParser()
config_parser.read(tox_ini_path)

long_regex_counter = 0
short_regex_counter = 0

envs = {}

for env in config_parser["tox"]["envlist"].split():
env = env.strip()

if env.startswith(";"):
continue

test_env_regex_match = test_env_regex.match(env)
short_regex_match = short_regex.search(env)

if test_env_regex_match is not None:
long_regex_counter += 1

env_dict = test_env_regex_match.groupdict()
env_dict_name = env_dict["name"]

if env_dict_name not in envs.keys():
envs[env_dict_name] = []

python_test_versions = {"python_versions": [], "test_versions": []}

if env_dict["pypy"] is not None:
python_test_versions["python_versions"].append("py3")

if env_dict["cpython_versions"] is not None:
(
python_test_versions["python_versions"].
extend(
[
f"3{cpython_version}"
for cpython_version
in env_dict["cpython_versions"].split(",")
]
)
)

if env_dict["test_versions"] is not None:
(
python_test_versions["test_versions"].
extend(env_dict["test_versions"].split(","))
)

envs[env_dict_name].append(python_test_versions)

if short_regex_match is not None:
short_regex_counter += 1

assert short_regex_counter == long_regex_counter

sorted_envs = []

for key, value in envs.items():
sorted_envs.append([key, value])

sorted_envs = sorted(sorted_envs)

jobs = []


def get_os_alias(os):
return os.replace("-latest", "")


def get_python_version_alias(python_version):
if python_version == "py3":
return "pypy-3.8"

return f"3.{python_version.replace('3', '')}"


for os in ["ubuntu-latest"]:

for env_name, python_test_versions in sorted_envs:

for python_test_version in python_test_versions:

for python_version in python_test_version["python_versions"]:

tox_env = f"py{python_version}-test-{env_name}"

if python_test_version["test_versions"]:
for test_version in python_test_version["test_versions"]:

jobs.append(
{
"tox_env": f"{tox_env}-{test_version}",
"python_version": (
f"{get_python_version_alias(python_version)}"
),
"os": os,
"ui_name": (
f"{env_name}-{test_version} "
f"{get_python_version_alias(python_version)} "
f"{get_os_alias(os)}"
),
"name": (
f"{env_name}_"
f"{test_version}_"
f"{python_version}_"
f"{os}"
)
}
)

else:
jobs.append(
{
"tox_env": f"{tox_env}",
"python_version": (
f"{get_python_version_alias(python_version)}"
),
"os": os,
"ui_name": (
f"{env_name} "
f"{get_python_version_alias(python_version)} "
f"{get_os_alias(os)}"
),
"name": (
f"{env_name}_"
f"{python_version}_"
f"{os}"
)
}
)

current_directory_path = Path(__file__).parent

with open(current_directory_path.joinpath("tests.yml"), "w") as test_yml_file:
test_yml_file.write(
Environment(
loader=FileSystemLoader(current_directory_path)
).get_template("tests.yml.j2").render(**locals())
)
130 changes: 0 additions & 130 deletions .github/workflows/instrumentations_0.yml

This file was deleted.

63 changes: 0 additions & 63 deletions .github/workflows/instrumentations_1.yml

This file was deleted.

23 changes: 22 additions & 1 deletion .github/workflows/test.yml → .github/workflows/misc.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Contrib Repo Tests
name: Misc tests

on:
push:
Expand Down Expand Up @@ -38,3 +38,24 @@ jobs:
- name: Ensure generated code is up to date
if: matrix.tox-environment == 'generate'
run: git diff --exit-code || (echo 'Generated code is out of date, please run "tox -e generate" and commit the changes in this PR.' && exit 1)

check-tests:
name: check-tests
runs-on: ubuntu-latest
steps:
- name: Checkout Contrib Repo @ SHA - {{ github.sha }}
uses: actions/checkout@v4

- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Install jinja
run: pip install Jinja2

- name: Run tests workflow generator
run: python .github/workflows/generate_tests.py

- name: Check tests workflow for updates
run: git diff --exit-code || (echo '.github/workflows/tests.yml is out of date, please run "python .github/workflows/generate_tests.py" and commit the changes in this PR.' && exit 1)
Loading

0 comments on commit dde7615

Please sign in to comment.