You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

73 lines
2.1 KiB

  1. import json
  2. import os
  3. import re
  4. import shlex
  5. import subprocess
  6. import sys
  7. import urllib.request
  8. def get_files_list(pr_number, repo="frappe/frappe"):
  9. req = urllib.request.Request(f"https://api.github.com/repos/{repo}/pulls/{pr_number}/files")
  10. res = urllib.request.urlopen(req)
  11. dump = json.loads(res.read().decode('utf8'))
  12. return [change["filename"] for change in dump]
  13. def get_output(command, shell=True):
  14. print(command)
  15. command = shlex.split(command)
  16. return subprocess.check_output(command, shell=shell, encoding="utf8").strip()
  17. def is_py(file):
  18. return file.endswith("py")
  19. def is_ci(file):
  20. return ".github" in file
  21. def is_frontend_code(file):
  22. return file.lower().endswith((".css", ".scss", ".less", ".sass", ".styl", ".js", ".ts", ".vue"))
  23. def is_docs(file):
  24. regex = re.compile(r'\.(md|png|jpg|jpeg|csv)$|^.github|LICENSE')
  25. return bool(regex.search(file))
  26. if __name__ == "__main__":
  27. files_list = sys.argv[1:]
  28. build_type = os.environ.get("TYPE")
  29. pr_number = os.environ.get("PR_NUMBER")
  30. repo = os.environ.get("REPO_NAME")
  31. # this is a push build, run all builds
  32. if not pr_number:
  33. os.system('echo "::set-output name=build::strawberry"')
  34. sys.exit(0)
  35. files_list = files_list or get_files_list(pr_number=pr_number, repo=repo)
  36. if not files_list:
  37. print("No files' changes detected. Build is shutting")
  38. sys.exit(0)
  39. ci_files_changed = any(f for f in files_list if is_ci(f))
  40. only_docs_changed = len(list(filter(is_docs, files_list))) == len(files_list)
  41. only_frontend_code_changed = len(list(filter(is_frontend_code, files_list))) == len(files_list)
  42. only_py_changed = len(list(filter(is_py, files_list))) == len(files_list)
  43. if ci_files_changed:
  44. print("CI related files were updated, running all build processes.")
  45. elif only_docs_changed:
  46. print("Only docs were updated, stopping build process.")
  47. sys.exit(0)
  48. elif only_frontend_code_changed and build_type == "server":
  49. print("Only Frontend code was updated; Stopping Python build process.")
  50. sys.exit(0)
  51. elif only_py_changed and build_type == "ui":
  52. print("Only Python code was updated, stopping Cypress build process.")
  53. sys.exit(0)
  54. os.system('echo "::set-output name=build::strawberry"')