Matrix Docker Ansible eploy
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 

71 строка
2.6 KiB

  1. #!/usr/bin/env python3
  2. """Keeps the Molecule patch-automerge rule in step with the roles that have a scenario.
  3. .github/renovate.json automerges patch bumps for roles listed by file name, on the grounds that
  4. the bump runs that role's Molecule scenario before merging. That reasoning only holds while the
  5. role actually has one.
  6. The dangerous direction is a role keeping automerge after losing its scenario: bumps would then
  7. merge with nothing exercising them. The harmless direction - a role gaining a scenario without
  8. being added - only means a missed opportunity, but it is reported too, since it is usually an
  9. oversight rather than a decision.
  10. """
  11. import json
  12. import pathlib
  13. import sys
  14. REPO = pathlib.Path(__file__).resolve().parent.parent
  15. RENOVATE = REPO / ".github" / "renovate.json"
  16. MARKER = "bin/check-molecule-automerge-list.py"
  17. def main() -> int:
  18. with_scenario = {
  19. p.parts[-4] for p in (REPO / "roles" / "custom").glob("*/molecule/default/molecule.yml")
  20. }
  21. config = json.loads(RENOVATE.read_text())
  22. rules = [r for r in config.get("packageRules", []) if MARKER in r.get("description", "")]
  23. if len(rules) != 1:
  24. print(f"Expected exactly one rule mentioning {MARKER}, found {len(rules)}.", file=sys.stderr)
  25. return 1
  26. listed = set()
  27. for name in rules[0].get("matchFileNames", []):
  28. parts = pathlib.PurePosixPath(name).parts
  29. if parts[:2] == ("roles", "custom") and parts[3:] == ("defaults", "main.yml"):
  30. listed.add(parts[2])
  31. else:
  32. print(f"Unexpected entry in the automerge rule: {name}", file=sys.stderr)
  33. return 1
  34. automerged_without_scenario = sorted(listed - with_scenario)
  35. scenario_without_automerge = sorted(with_scenario - listed)
  36. if automerged_without_scenario:
  37. print(
  38. "These roles automerge patch bumps but have no Molecule scenario, so nothing would\n"
  39. "exercise the bump before it merges. Remove them from the rule in\n"
  40. ".github/renovate.json, or give them a scenario:",
  41. file=sys.stderr,
  42. )
  43. for role in automerged_without_scenario:
  44. print(f" {role}", file=sys.stderr)
  45. if scenario_without_automerge:
  46. print(
  47. "These roles have a Molecule scenario but are not in the automerge rule in\n"
  48. ".github/renovate.json, so their patch bumps still need a button press:",
  49. file=sys.stderr,
  50. )
  51. for role in scenario_without_automerge:
  52. print(f" {role}", file=sys.stderr)
  53. return 1 if (automerged_without_scenario or scenario_without_automerge) else 0
  54. if __name__ == "__main__":
  55. sys.exit(main())