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.

BuildDemos.py 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #coding=UTF-8
  2. # See BuildArchetypes for details on environment
  3. # BuildDemos needs git in PATH and depends on gitpython library
  4. # gitpython can be installed with python installer script "pip":
  5. # pip install gitpython
  6. #
  7. # Deployment dependency: requests
  8. # pip install requests
  9. # Deploy depends on .deployUrl and .deployCredentials files in home folder
  10. import sys, os, pickle
  11. from os.path import join, isfile
  12. from fnmatch import fnmatch
  13. from xml.etree.ElementTree import ElementTree
  14. # Validated demos. name -> git url
  15. demos = {
  16. "dashboard" : "https://github.com/vaadin/dashboard-demo.git",
  17. "addressbook" : "https://github.com/vaadin/addressbook.git",
  18. "framework8-demo" : "https://github.com/vaadin/framework8-demo",
  19. "sampler" : "demos/sampler"
  20. # "my-demo" : ("my_demo_url_or_path", "my-demo-dev-branch")
  21. }
  22. # List of built archetypes
  23. archetypes = [
  24. "vaadin-archetype-widget",
  25. "vaadin-archetype-application",
  26. "vaadin-archetype-application-example",
  27. "vaadin-archetype-application-multimodule"
  28. ]
  29. status_dump = {"messages": []}
  30. def dump_status(error_occurred):
  31. status_dump["error"] = error_occurred
  32. pickle.dump(status_dump, open("result/demo_validation_status.pickle", "wb"))
  33. def log_status(log_string):
  34. status_dump["messages"].append(log_string)
  35. print(log_string)
  36. sys.stdout.flush()
  37. def checkout(folder, url, repoBranch = "master"):
  38. Repo.clone_from(url, join(resultPath, folder), branch = repoBranch)
  39. if __name__ == "__main__":
  40. # Do imports.
  41. try:
  42. from git import Repo
  43. except:
  44. log_status("BuildDemos depends on gitpython. Install it with `pip install gitpython`")
  45. dump_status(True)
  46. sys.exit(1)
  47. from BuildHelpers import mavenValidate, copyWarFiles, getLogFile, removeDir, getArgs, resultPath, parser, dockerWrap, generateArchetype
  48. from DeployHelpers import deployWar
  49. # Add command line agrument for ignoring failing demos
  50. parser.add_argument("--ignore", type=str, help="Ignored demos", default="")
  51. # Control to skip demos and archetypes
  52. parser.add_argument("--skipDemos", action="store_true", help="Skip building demos")
  53. parser.add_argument("--skipArchetypes", action="store_true", help="Skip building archetypes")
  54. args = getArgs()
  55. demosFailed = False
  56. ignoredDemos = args.ignore.split(",")
  57. wars = []
  58. if not args.skipDemos:
  59. for demo in demos:
  60. print("Validating demo %s" % (demo))
  61. try:
  62. repo = demos[demo]
  63. if (isinstance(repo, tuple)):
  64. checkout(demo, repo[0], repo[1])
  65. else:
  66. checkout(demo, repo)
  67. mavenValidate(demo, logFile=getLogFile(demo))
  68. wars.extend(copyWarFiles(demo))
  69. log_status("%s demo validation succeeded!" % (demo))
  70. except Exception as e:
  71. log_status("%s demo validation failed: %s" % (demo, e))
  72. if demo not in ignoredDemos:
  73. demosFailed = True
  74. except EnvironmentError as e:
  75. log_status("%s demo validation failed: %s" % (demo, e))
  76. if demo not in ignoredDemos:
  77. demosFailed = True
  78. try:
  79. removeDir(demo)
  80. except:
  81. pass
  82. log_status("")
  83. if not args.skipArchetypes:
  84. for archetype in archetypes:
  85. artifactId = "test-%s-%s" % (archetype, args.version.replace(".", "-"))
  86. try:
  87. log = getLogFile(archetype)
  88. generateArchetype(archetype, artifactId, args.pluginRepo, log)
  89. mavenValidate(artifactId, logFile=log)
  90. wars.extend(copyWarFiles(artifactId, name=archetype))
  91. log_status("%s validation succeeded!" % (archetype))
  92. except Exception as e:
  93. print("Archetype %s build failed:" % (archetype), e)
  94. if archetype not in ignoredDemos:
  95. demosFailed = True
  96. try:
  97. removeDir(artifactId)
  98. except:
  99. pass
  100. log_status("")
  101. if args.deploy_mode:
  102. for war in wars:
  103. try:
  104. deployWar(war)
  105. except Exception as e:
  106. log_status("War %s failed to deploy: %s" % (war, e))
  107. demosFailed = True
  108. else:
  109. dockerWrap(args.version)
  110. if demosFailed:
  111. dump_status(True)
  112. sys.exit(1)
  113. dump_status(False)