Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 
 

57 rader
1.7 KiB

  1. # if the script ends with exit code 0, then no tests are run further, else all tests are run
  2. import os
  3. import re
  4. import shlex
  5. import subprocess
  6. import sys
  7. def get_output(command, shell=True):
  8. print(command)
  9. command = shlex.split(command)
  10. return subprocess.check_output(command, shell=shell, encoding="utf8").strip()
  11. def is_py(file):
  12. return file.endswith("py")
  13. def is_js(file):
  14. return file.endswith("js")
  15. def is_docs(file):
  16. regex = re.compile('\.(md|png|jpg|jpeg)$|^.github|LICENSE')
  17. return bool(regex.search(file))
  18. if __name__ == "__main__":
  19. build_type = os.environ.get("TYPE")
  20. before = os.environ.get("BEFORE")
  21. after = os.environ.get("AFTER")
  22. commit_range = before + '...' + after
  23. print("Build Type: {}".format(build_type))
  24. print("Commit Range: {}".format(commit_range))
  25. try:
  26. files_changed = get_output("git diff --name-only {}".format(commit_range), shell=False)
  27. except Exception:
  28. sys.exit(2)
  29. if "fatal" not in files_changed:
  30. files_list = files_changed.split()
  31. only_docs_changed = len(list(filter(is_docs, files_list))) == len(files_list)
  32. only_js_changed = len(list(filter(is_js, files_list))) == len(files_list)
  33. only_py_changed = len(list(filter(is_py, files_list))) == len(files_list)
  34. if only_docs_changed:
  35. print("Only docs were updated, stopping build process.")
  36. sys.exit(0)
  37. if only_js_changed and build_type == "server":
  38. print("Only JavaScript code was updated; Stopping Python build process.")
  39. sys.exit(0)
  40. if only_py_changed and build_type == "ui":
  41. print("Only Python code was updated, stopping Cypress build process.")
  42. sys.exit(0)
  43. sys.exit(2)