Skip to content

Commit

Permalink
breaking(gitlab): run a test matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
gforcada committed Feb 21, 2025
1 parent 67e7e7c commit c73e66d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
37 changes: 33 additions & 4 deletions src/plone/meta/config_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@

MXDEV_CONSTRAINTS = "constraints-mxdev.txt"

DOCKER_IMAGE = "python:3.11-bullseye"
DOCKER_IMAGES = {
"3.13": "python:3.13-bookworm",
"3.12": "python:3.12-bookworm",
"3.11": "python:3.11-bookworm",
"3.10": "python:3.10-bookworm",
"3.9": "python:3.9-bookworm",
}

# Rather than pointing configured repositories to `plone.meta`'s `main` branch
# to get their GHA workflows, point them to an ever evolving branch.
Expand Down Expand Up @@ -539,19 +545,42 @@ def gitlab_ci(self):
options = self._get_options_for(
"gitlab",
(
"custom_image",
"custom_images",
"os_dependencies",
"extra_lines",
"jobs",
),
)
if not options["custom_image"]:
options["custom_image"] = DOCKER_IMAGE
options.update(self._gitlab_testing_matrix(options["custom_images"]))
options["destination"] = self.path / ".gitlab-ci.yml"
if not options.get("jobs"):
options["jobs"] = GITLAB_DEFAULT_JOBS
return self.copy_with_meta("gitlab-ci.yml.j2", **options)

def _gitlab_testing_matrix(self, custom_images):
options = self._get_options_for("tox", ("test_matrix",))
test_matrix = getattr(options, "test_matrix", TOX_TEST_MATRIX)
combinations = []
image = ""
for plone_version, python_versions in test_matrix.items():
no_dot_plone = plone_version.replace(".", "")
for py_version in (python_versions[0], python_versions[-1]):
no_dot_python = py_version.replace(".", "")
image = DOCKER_IMAGES.get(py_version)
if custom_images:
image = custom_images.get(py_version)
if not image:
raise ValueError(
f"There is no Docker image defined for Python {py_version}. "
"Either provide it in the `custom_images` option or report an issue to `plone.meta`."
)

combinations.append((image, f"py{no_dot_python}-plone{no_dot_plone}"))
return {
"testing_matrix": combinations,
"custom_image": image,
}

def flake8(self):
options = self._get_options_for("flake8", ("extra_lines",))
destination = self.path / ".flake8"
Expand Down
11 changes: 9 additions & 2 deletions src/plone/meta/default/gitlab-ci.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ image: %(custom_image)s
##
# Add extra configuration options in .meta.toml:
# [gitlab]
# custom_image = "python:3.11-bullseye"
# custom_images = {"3.13" = "python:3.13-bookworm", "3.12" = "python:3.12-bookworm"}
##

stages:
Expand Down Expand Up @@ -75,10 +75,17 @@ circular-dependencies:
{% if "testing" in jobs %}
testing:
stage: test
image: $DOCKER_IMAGE
script:
%(os_dependencies)s
- pip install tox
- tox -e test -- --xml reports
- tox -e $TOX_ENV -- --xml reports
parallel:
matrix:
{% for docker_image, tox_env in testing_matrix %}
- DOCKER_IMAGE: %(docker_image)s
TOX_ENV: %(tox_env)s
{% endfor %}
artifacts:
when: always
reports:
Expand Down

0 comments on commit c73e66d

Please sign in to comment.