get_maintainers.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/usr/bin/env python
  2. # @file: toolset/github_actions/get_maintainers.py
  3. # @author: Elwyn Cruz (ecruz-te)
  4. #
  5. # @description: This script is only for use within Github Actions. It is meant
  6. # to get a list of maintainers to ping for a PR whenever their framework
  7. # is updated.
  8. import os
  9. import json
  10. import re
  11. import subprocess
  12. diff_target = os.getenv("TARGET_BRANCH_NAME")
  13. def fw_found_in_changes(test, changes_output):
  14. return re.search(
  15. r"frameworks/" + re.escape(test) + "/",
  16. changes_output, re.M)
  17. def clean_output(output):
  18. return os.linesep.join([s for s in output.splitlines() if s])
  19. curr_branch = "HEAD"
  20. # Also fetch master to compare against
  21. subprocess.check_output(['bash', '-c', 'git fetch origin {0}:{0}'
  22. .format(diff_target)])
  23. changes = clean_output(
  24. subprocess.check_output([
  25. 'bash', '-c',
  26. 'git --no-pager diff --name-only {0} $(git merge-base {0} {1})'
  27. .format(curr_branch, diff_target)
  28. ], text=True))
  29. def get_frameworks(test_lang):
  30. dir = "frameworks/" + test_lang + "/"
  31. return [test_lang + "/" + x for x in [x for x in os.listdir(dir) if os.path.isdir(dir + x)]]
  32. test_dirs = []
  33. for frameworks in map(get_frameworks, os.listdir("frameworks")):
  34. for framework in frameworks:
  35. test_dirs.append(framework)
  36. affected_frameworks = [fw for fw in test_dirs if fw_found_in_changes(fw, changes)]
  37. maintained_frameworks = {}
  38. for framework in affected_frameworks:
  39. _, name = framework.split("/")
  40. try:
  41. with open("frameworks/" + framework + "/benchmark_config.json", "r") as framework_config:
  42. config = json.load(framework_config)
  43. except FileNotFoundError:
  44. continue
  45. framework_maintainers = config.get("maintainers", None)
  46. if framework_maintainers is not None:
  47. maintained_frameworks[name] = framework_maintainers
  48. if maintained_frameworks:
  49. print("The following frameworks were updated, pinging maintainers:")
  50. for framework, maintainers in maintained_frameworks.items():
  51. print("`%s`: @%s" % (framework, ", @".join(maintainers)))
  52. exit(0)