|
1 | 1 | import functools |
| 2 | +import json |
2 | 3 | import shlex |
3 | 4 | import subprocess |
| 5 | +import tomllib |
4 | 6 | from collections.abc import Callable |
5 | 7 | from pathlib import Path |
6 | 8 |
|
@@ -327,3 +329,60 @@ def test_catalog_info(tmp_path: Path): |
327 | 329 | "owner": "group:default/daq", |
328 | 330 | }, |
329 | 331 | } |
| 332 | + |
| 333 | + |
| 334 | +@pytest.mark.parametrize( |
| 335 | + "override", |
| 336 | + [ |
| 337 | + {}, |
| 338 | + {"docker": True}, |
| 339 | + {"docker": True, "docker_debug": True}, |
| 340 | + {"pypi": True}, |
| 341 | + {"docs_type": "sphinx"}, |
| 342 | + ], |
| 343 | +) |
| 344 | +def test_renovate_actions_match_what_is_shipped(override: dict, tmp_path: Path): |
| 345 | + # Generate a project with the given answers |
| 346 | + answers = { |
| 347 | + "docker": False, |
| 348 | + "docker_debug": False, |
| 349 | + "pypi": False, |
| 350 | + "docs_type": "README", |
| 351 | + } |
| 352 | + answers.update(override) |
| 353 | + copy_project(tmp_path, **answers) |
| 354 | + # Find the GitHub actions ignored by renovate |
| 355 | + renovate_config_path = tmp_path / "renovate.json" |
| 356 | + renovate_config = json.loads(renovate_config_path.read_text()) |
| 357 | + config_github_actions = set(renovate_config["packageRules"][1]["matchPackageNames"]) |
| 358 | + # Find the GitHub actions actually used in the workflows |
| 359 | + used_github_actions = set[str]() |
| 360 | + for workflow_file in (tmp_path / ".github" / "workflows").glob("*.yml"): |
| 361 | + workflow = yaml.safe_load(workflow_file.read_text()) |
| 362 | + for job in workflow.get("jobs", {}).values(): |
| 363 | + for step in job.get("steps", []): |
| 364 | + action = step.get("uses") |
| 365 | + if action: |
| 366 | + used_github_actions.add(action.split("@")[0]) |
| 367 | + # Check they match |
| 368 | + assert used_github_actions == config_github_actions |
| 369 | + |
| 370 | + |
| 371 | +def test_python_versions_match(tmp_path: Path): |
| 372 | + copy_project(tmp_path) |
| 373 | + # Grab the python versions from ci.yml |
| 374 | + ci_yaml = tmp_path / ".github" / "workflows" / "ci.yml" |
| 375 | + workflow = yaml.safe_load(ci_yaml.read_text()) |
| 376 | + python_versions = workflow["jobs"]["test"]["strategy"]["matrix"]["python-version"] |
| 377 | + # Check .python-version is the first of these |
| 378 | + python_version_file = tmp_path / ".python-version" |
| 379 | + min_version = python_version_file.read_text().strip() |
| 380 | + assert python_versions[0] == min_version |
| 381 | + # Check pyproject.toml has correct requires-python and classifiers |
| 382 | + pyproject_toml = tomllib.loads((tmp_path / "pyproject.toml").read_text()) |
| 383 | + assert pyproject_toml["project"]["requires-python"] == f">={min_version}" |
| 384 | + for version in python_versions: |
| 385 | + assert ( |
| 386 | + f"Programming Language :: Python :: {version}" |
| 387 | + in pyproject_toml["project"]["classifiers"] |
| 388 | + ) |
0 commit comments