feat: run the PR checks with one command

This commit is contained in:
Abdessamad Derraz committed 2026-11-06 14:55:03 +01:00
1 parent af6936055b
commit f4b45c641d
6 files changed
+196 -22

No files matched your search

+66 -1
View File
@@ -65,7 +65,7 @@ class BeforeOpeningAPullRequest(unittest.TestCase):
text = (REPO_ROOT / "CONTRIBUTING.md").read_text(encoding="utf-8")
section = text.split("## Before opening a PR", 1)[1].split("\n## ", 1)[0]
block = _re.search(r"```bash\n(.*?)```", section, _re.S).group(1)
block = "".join(_re.findall(r"```bash\n(.*?)```", section, _re.S))
for command in ("validate_pr.py --changed", "validate_schemas.py --source-only",
"unittest discover"):
self.assertIn(command, block)
@@ -217,3 +217,68 @@ class TheGuideRebuildsWhenItsPinsMove(unittest.TestCase):
(REPO_ROOT / ".github" / "workflows" / "deploy-site.yml").read_text(encoding="utf-8"))
paths = deploy[True]["push"]["paths"]
self.assertIn(".github/workflows/validate.yml", paths)
class OneCommandRunsTheChecks(unittest.TestCase):
"""A contributor copied ten commands by hand before a pull request, and
skipping one (refresh_data_dirs) failed the pack tests with no hint."""
CHECK = re.compile(r"(?:xargs -0 |run: |^\s*)((?:python3?\.?8? -m unittest|python scripts/\w+\.py"
r"|vermin|npm (?:ci|run build)))")
def test_every_check_ci_runs_is_a_step(self):
import pr_checks
workflow = (REPO_ROOT / ".github" / "workflows" / "validate.yml").read_text(encoding="utf-8")
ran = {m.group(1) for line in workflow.splitlines()
if not line.strip().startswith("#") for m in [self.CHECK.search(line)] if m}
self.assertGreaterEqual(len(ran), 10)
steps = [step.command for step in pr_checks.STEPS]
for check in sorted(ran):
with self.subTest(check=check):
self.assertTrue(any(command.startswith(check) for command in steps))
def test_steps_keep_ci_order(self):
import pr_checks
workflow = (REPO_ROOT / ".github" / "workflows" / "validate.yml").read_text(encoding="utf-8")
order = [workflow.index(key) for key in (
"refresh_data_dirs.py", "run: python scripts/generate_site.py",
"npm run build --prefix website", "python -m unittest discover",
"validate_site.py")]
self.assertEqual(order, sorted(order))
commands = [step.command for step in pr_checks.STEPS]
positions = [next(i for i, c in enumerate(commands) if key in c) for key in (
"refresh_data_dirs.py", "generate_site.py", "npm run build",
"unittest discover", "validate_site.py")]
self.assertEqual(positions, sorted(positions))
def test_the_guide_gives_the_runner_and_what_it_runs(self):
import pr_checks
text = generate_readme.generate_contributing()
section = text.split("## Before opening a PR", 1)[1].split("\n## ", 1)[0]
self.assertIn("python scripts/pr_checks.py\n", section)
for step in pr_checks.STEPS:
with self.subTest(step=step.command):
self.assertIn(step.command, section)
def test_a_missing_tool_is_reported_and_a_failure_does_not_stop_the_run(self):
import contextlib
import io
import pr_checks
steps = (
pr_checks.Step("python -c raise(SystemExit(3))", "fails"),
pr_checks.Step("no-such-tool-here --x", "absent", needs="no-such-tool-here",
provider="nothing"),
pr_checks.Step("python -c pass", "passes"),
)
out = io.StringIO()
with contextlib.redirect_stdout(out):
code = pr_checks.run(steps)
self.assertEqual(code, 1)
self.assertIn("FAILED python -c raise(SystemExit(3)) (exit 3)", out.getvalue())
self.assertIn("NOT RUN no-such-tool-here --x", out.getvalue())
self.assertIn("1/3 checks passed", out.getvalue())