Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/python-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
name: Upload Python Package

on:
- push
push:
tags: ["*.*.*"]

permissions:
contents: read
Expand Down
117 changes: 73 additions & 44 deletions .mergify.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,72 @@
# Check one PR at a time, on the PR itself. Mergify then updates the PR
# with main and merges it once CI passes, which the "branches must be up
# to date" rule requires. Do not raise this: with more than one parallel
# check, Mergify tests copies of PRs on branches in this repository instead.
merge_queue:
max_parallel_checks: 1

queue_rules:
- name: default
update_method: rebase
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
merge_method: merge
# No merge_conditions: Mergify then reuses queue_conditions, which keeps
# the checks on the PR itself.
queue_conditions:
- "-draft"
# At least 1 reviewer from maintainers
- "#approved-reviews-by>=1"
# Fork PRs that change workflows are merged by hand. So are fork PRs
# without "Allow edits by maintainers", since Mergify can't update
# them. Merge those only after approval and the checks below pass.
- or:
- head-repo-full-name=python-wheel-build/fromager
- "-files~=^\\.github/workflows/"
- or:
- and:
# Unit tests
- check-success=unit (3.12, 1.75, ubuntu-latest)
- check-success=unit (3.13, 1.75, ubuntu-latest)
- check-success=unit (3.14, 1.75, ubuntu-latest)
- check-success=unit (3.14, 1.75, macos-latest)

# checks (see check.yaml)
- check-success=pre-commit
- check-success=pkglint
- check-success=readthedocs

# E2E test suites (consolidated from individual tests)
# Python 3.12 - Ubuntu only (macOS excluded)
- check-success=e2e (3.12, 1.75, ci_bootstrap_parallel_suite, ubuntu-latest)
- check-success=e2e (3.12, 1.75, ci_bootstrap_suite, ubuntu-latest)
- check-success=e2e (3.12, 1.75, ci_build_suite, ubuntu-latest)
- check-success=e2e (3.12, 1.75, ci_config_suite, ubuntu-latest)
- check-success=e2e (3.12, 1.75, ci_specialized_suite, ubuntu-latest)
- check-success=e2e (3.12, 1.75, ci_workflow_suite, ubuntu-latest)
# Python 3.13 - Ubuntu only (macOS excluded)
- check-success=e2e (3.13, 1.75, ci_bootstrap_parallel_suite, ubuntu-latest)
- check-success=e2e (3.13, 1.75, ci_bootstrap_suite, ubuntu-latest)
- check-success=e2e (3.13, 1.75, ci_build_suite, ubuntu-latest)
- check-success=e2e (3.13, 1.75, ci_config_suite, ubuntu-latest)
- check-success=e2e (3.13, 1.75, ci_specialized_suite, ubuntu-latest)
- check-success=e2e (3.13, 1.75, ci_workflow_suite, ubuntu-latest)
# Python 3.14 - Ubuntu only (macOS excluded)
- check-success=e2e (3.14, 1.75, ci_bootstrap_parallel_suite, ubuntu-latest)
- check-success=e2e (3.14, 1.75, ci_bootstrap_suite, ubuntu-latest)
- check-success=e2e (3.14, 1.75, ci_build_suite, ubuntu-latest)
- check-success=e2e (3.14, 1.75, ci_config_suite, ubuntu-latest)
- check-success=e2e (3.14, 1.75, ci_specialized_suite, ubuntu-latest)
- check-success=e2e (3.14, 1.75, ci_workflow_suite, ubuntu-latest)

# Docs-only PRs: test.yaml skips these paths (paths-ignore), so unit
# and e2e checks never run. Keep this in sync with paths-ignore.
# True when every changed file is under docs/, a top-level *.md or
# *.rst file, or LICENSE.
- and:
- "-files~=^(?!docs/)(?![^/]+\\.(md|rst)$)(?!LICENSE$)"
- check-success=pre-commit
- check-success=pkglint
- check-success=readthedocs

pull_request_rules:
- name: Add CI label
conditions:
Expand All @@ -24,51 +93,11 @@ pull_request_rules:
add:
- mergify
- name: Automatic merge on approval
conditions:
- and:
- "-draft"

# Unit tests
- check-success=unit (3.12, 1.75, ubuntu-latest)
- check-success=unit (3.13, 1.75, ubuntu-latest)
- check-success=unit (3.14, 1.75, ubuntu-latest)
- check-success=unit (3.14, 1.75, macos-latest)

# checks (see check.yaml)
- check-success=pre-commit
- check-success=pkglint
- check-success=readthedocs

# E2E test suites (consolidated from individual tests)
# Python 3.12 - Ubuntu only (macOS excluded)
- check-success=e2e (3.12, 1.75, ci_bootstrap_parallel_suite, ubuntu-latest)
- check-success=e2e (3.12, 1.75, ci_bootstrap_suite, ubuntu-latest)
- check-success=e2e (3.12, 1.75, ci_build_suite, ubuntu-latest)
- check-success=e2e (3.12, 1.75, ci_config_suite, ubuntu-latest)
- check-success=e2e (3.12, 1.75, ci_specialized_suite, ubuntu-latest)
- check-success=e2e (3.12, 1.75, ci_workflow_suite, ubuntu-latest)
# Python 3.13 - Ubuntu only (macOS excluded)
- check-success=e2e (3.13, 1.75, ci_bootstrap_parallel_suite, ubuntu-latest)
- check-success=e2e (3.13, 1.75, ci_bootstrap_suite, ubuntu-latest)
- check-success=e2e (3.13, 1.75, ci_build_suite, ubuntu-latest)
- check-success=e2e (3.13, 1.75, ci_config_suite, ubuntu-latest)
- check-success=e2e (3.13, 1.75, ci_specialized_suite, ubuntu-latest)
- check-success=e2e (3.13, 1.75, ci_workflow_suite, ubuntu-latest)
# Python 3.14 - Ubuntu only (macOS excluded)
- check-success=e2e (3.14, 1.75, ci_bootstrap_parallel_suite, ubuntu-latest)
- check-success=e2e (3.14, 1.75, ci_bootstrap_suite, ubuntu-latest)
- check-success=e2e (3.14, 1.75, ci_build_suite, ubuntu-latest)
- check-success=e2e (3.14, 1.75, ci_config_suite, ubuntu-latest)
- check-success=e2e (3.14, 1.75, ci_specialized_suite, ubuntu-latest)
- check-success=e2e (3.14, 1.75, ci_workflow_suite, ubuntu-latest)

# At least 1 reviewer from maintainers
- and:
- "#approved-reviews-by>=1"

# Approval and CI requirements are in queue_rules above.
conditions: []
actions:
merge:
method: merge
queue:
name: default

- name: Ping author on conflicts
conditions:
Expand Down
101 changes: 87 additions & 14 deletions e2e/mergify_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,100 @@
import pathlib
import re
import sys
import typing

import yaml
from packaging.version import Version

# Parse the mergify settings to find the rules that are in place.
mergify_settings_file = pathlib.Path(".mergify.yml")
mergify_settings = yaml.safe_load(mergify_settings_file.read_text(encoding="utf8"))
# Matches 'check-success=e2e (3.12, 1.75, ci_build_suite, ubuntu-latest)',
# with or without spaces around '=', and captures the part in parentheses.
E2E_CHECK = re.compile(r"^check-success\s*=\s*e2e\s*(\(.*\))$")
# The docs-only group is the one that limits which files changed.
DOCS_ONLY_MARKER = re.compile(r"^-files\s*~=")


def e2e_job(condition: str) -> str | None:
"""Return the e2e job parameters for an e2e check condition, else None."""
match = E2E_CHECK.match(condition.strip())
return match.group(1) if match else None


def iter_conditions(conditions: list[typing.Any]) -> typing.Iterator[str]:
"""Yield every string condition, descending into and/or/not groups."""
for rule in conditions:
if isinstance(rule, str):
yield rule
elif isinstance(rule, dict):
for nested in rule.values():
yield from iter_conditions(nested)


def find_ci_checks(conditions: list[typing.Any]) -> list[str]:
"""Return the checks of the full CI group in the queue conditions.

The queue conditions must have one ``or`` with two ``and`` groups: a
docs-only group (it has a ``-files~=`` condition) and the full CI group.
E2e checks must only appear in the full CI group, as plain strings.
"""
candidates: list[tuple[list[str], list[typing.Any]]] = []
for rule in conditions:
if not (isinstance(rule, dict) and list(rule) == ["or"]):
continue
groups = rule["or"]
if len(groups) != 2 or not all(
isinstance(g, dict) and list(g) == ["and"] for g in groups
):
continue
docs = [
g["and"]
for g in groups
if any(
isinstance(c, str) and DOCS_ONLY_MARKER.match(c.strip())
for c in g["and"]
)
]
if len(docs) == 1:
ci = [g["and"] for g in groups if g["and"] is not docs[0]]
candidates.append((ci[0], docs[0]))
if len(candidates) != 1:
raise ValueError(
f"expected one 'or' with a full CI group and a docs-only group in "
f"{mergify_settings_file}, found {len(candidates)}"
)
ci_checks, docs_checks = candidates[0]
if not all(isinstance(c, str) for c in ci_checks):
raise ValueError(
f"the CI group in {mergify_settings_file} must only contain plain checks"
)
if any(e2e_job(c) for c in iter_conditions(docs_checks)):
raise ValueError(
f"the docs-only group in {mergify_settings_file} must not require e2e checks"
)
total = sum(1 for c in iter_conditions(conditions) if e2e_job(c))
found = sum(1 for c in ci_checks if e2e_job(c))
if total != found:
raise ValueError(
f"e2e checks found outside the CI group in {mergify_settings_file}"
)
return ci_checks


queue_rule = next(
item for item in mergify_settings["queue_rules"] if item["name"] == "default"
)
if "merge_conditions" in queue_rule:
raise ValueError(
f"{mergify_settings_file}: keep checks in queue_conditions only, "
"so Mergify checks PRs in place"
)
existing_jobs = set()
for item in mergify_settings["pull_request_rules"]:
if item["name"] == "Automatic merge on approval":
conditions = item["conditions"][0]["and"]
# Look for 'check-success=e2e (something, something, something, something)'
for rule in conditions:
if not isinstance(rule, str):
continue
if not rule.startswith("check-success=e2e"):
continue
parameters = rule.partition(" ")[-1]
existing_jobs.add(parameters)
if not existing_jobs:
raise ValueError(f"Could not find e2e jobs in {mergify_settings_file}")
for rule in find_ci_checks(queue_rule["queue_conditions"]):
job = e2e_job(rule)
if job:
existing_jobs.add(job)
print("existing jobs:\n ", "\n ".join(str(j) for j in sorted(existing_jobs)), sep="")

# Parse the github actions file to find the test jobs that are defined.
Expand Down Expand Up @@ -116,7 +189,7 @@
if RC:
print(f"\njobs list to paste into {mergify_settings_file}:\n")
for job_name in sorted(expected_jobs):
print(f" - check-success=e2e {job_name}")
print(f" - check-success=e2e {job_name}")
print()

sys.exit(RC)
Loading