run.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/usr/bin/python3
  2. import subprocess
  3. import os
  4. import argparse
  5. from glob import glob
  6. from whatchanged import directory_check_types, CheckType
  7. def main():
  8. parser = argparse.ArgumentParser()
  9. parser.add_argument(
  10. "--branch", default="origin/main", help="branch to compare current head against"
  11. )
  12. parser.add_argument(
  13. "--render", action="store_true", help="Check rendering of families only"
  14. )
  15. parser.add_argument("--pr-number", help="PR to output fontbakery report to")
  16. parser.add_argument(
  17. "--pr-url-body", default="https://www.github.com/google/fonts/pull/%s"
  18. )
  19. args = parser.parse_args()
  20. profile_test_file = os.path.join(os.path.dirname(__file__), "test_profiles.py")
  21. for directory, check_type in directory_check_types(args.branch):
  22. out = os.path.join("out", os.path.basename(directory))
  23. fonts = glob(os.path.join(directory, "*.ttf"))
  24. qa_cmd_prefix = ["gftools", "qa", "-f"] + fonts + ["-o", out]
  25. if args.pr_number:
  26. if not args.pr_url_body.endswith("/"):
  27. args.pr_url_body += "/"
  28. url = "%s%s" % (args.pr_url_body, args.pr_number)
  29. qa_cmd_prefix += ["--out-url", url]
  30. if args.render and check_type == CheckType.NEW_FAMILY:
  31. print(f"Rendering new family: {directory}")
  32. subprocess.run(qa_cmd_prefix + ["-gfb", "--render", "--imgs"])
  33. elif args.render and check_type == CheckType.MODIFIED_FAMILY:
  34. print(f"Rendering modified family: {directory}")
  35. subprocess.run(qa_cmd_prefix + ["-gfb", "--render", "--imgs"])
  36. # we only want args.render to do the above two conditions
  37. elif args.render:
  38. continue
  39. elif check_type == CheckType.NEW_FAMILY:
  40. print(f"Checking new family: {directory}")
  41. subprocess.run(
  42. qa_cmd_prefix + ["--fontbakery", "--interpolations"], check=True
  43. )
  44. elif check_type == CheckType.MODIFIED_FAMILY:
  45. print(f"Checking modified family: {directory}")
  46. subprocess.run(
  47. qa_cmd_prefix
  48. + ["-gfb", "--fontbakery", "--diffenator", "--interpolations"],
  49. check=True,
  50. )
  51. elif check_type == CheckType.MODIFIED_FAMILY_METADATA:
  52. print(f"Checking modified family metadata: {directory}")
  53. subprocess.run(qa_cmd_prefix + ["--fontbakery", "-o", out], check=True)
  54. elif check_type == CheckType.DESIGNER:
  55. print(f"Checking designer profile: {directory}")
  56. subprocess.run(["pytest", profile_test_file, directory])
  57. else:
  58. print(f"Skipping directory {directory}")
  59. if __name__ == "__main__":
  60. main()