您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

79 行
2.4 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. os.system('echo "::set-output name=build-server::strawberry"')
  35. sys.exit(0)
  36. files_list = files_list or get_files_list(pr_number=pr_number, repo=repo)
  37. if not files_list:
  38. print("No files' changes detected. Build is shutting")
  39. sys.exit(0)
  40. ci_files_changed = any(f for f in files_list if is_ci(f))
  41. only_docs_changed = len(list(filter(is_docs, files_list))) == len(files_list)
  42. only_frontend_code_changed = len(list(filter(is_frontend_code, files_list))) == len(files_list)
  43. updated_py_file_count = len(list(filter(is_py, files_list)))
  44. only_py_changed = updated_py_file_count == len(files_list)
  45. if ci_files_changed:
  46. print("CI related files were updated, running all build processes.")
  47. elif only_docs_changed:
  48. print("Only docs were updated, stopping build process.")
  49. sys.exit(0)
  50. elif only_frontend_code_changed and build_type == "server":
  51. print("Only Frontend code was updated; Stopping Python build process.")
  52. sys.exit(0)
  53. elif build_type == "ui":
  54. if only_py_changed:
  55. print("Only Python code was updated, stopping Cypress build process.")
  56. sys.exit(0)
  57. elif updated_py_file_count > 0:
  58. # both frontend and backend code were updated
  59. os.system('echo "::set-output name=build-server::strawberry"')
  60. os.system('echo "::set-output name=build::strawberry"')