check-bazel-team-owner.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. """Used to check bazel output for team's test owner tags
  2. The bazel output looks like
  3. <?xml version="1.1" encoding="UTF-8" standalone="no"?>
  4. <query version="2">
  5. <rule class="cc_test"
  6. location="/Users/simonmo/Desktop/ray/ray/streaming/BUILD.bazel:312:8"
  7. name="//streaming:streaming_util_tests"
  8. >
  9. <string name="name" value="streaming_util_tests"/>
  10. <list name="tags">
  11. <string value="team:ant-group"/>
  12. </list>
  13. <list name="deps">
  14. ...
  15. """
  16. import sys
  17. import xml.etree.ElementTree as ET
  18. def perform_check(raw_xml_string: str):
  19. tree = ET.fromstring(raw_xml_string)
  20. owners = {}
  21. missing_owners = []
  22. for rule in tree.findall("rule"):
  23. test_name = rule.attrib["name"]
  24. tags = [child.attrib["value"] for child in rule.find("list").getchildren()]
  25. team_owner = [t for t in tags if t.startswith("team")]
  26. if len(team_owner) == 0:
  27. missing_owners.append(test_name)
  28. owners[test_name] = team_owner
  29. if len(missing_owners):
  30. raise Exception(
  31. f"Cannot find owner for tests {missing_owners}, please add "
  32. "`team:*` to the tags."
  33. )
  34. print(owners)
  35. if __name__ == "__main__":
  36. raw_xml_string = sys.stdin.read()
  37. perform_check(raw_xml_string)