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.

GenerateBuildTestAndStagingReport.py 8.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. from BuildDemos import demos
  2. import argparse, requests, json, subprocess, re, pickle
  3. parser = argparse.ArgumentParser()
  4. parser.add_argument("version", type=str, help="Vaadin version that was just built")
  5. parser.add_argument("deployUrl", type=str, help="Base url of the deployment server")
  6. parser.add_argument("teamcityUser", type=str, help="Teamcity username to use")
  7. parser.add_argument("teamcityPassword", type=str, help="Password for given teamcity username")
  8. parser.add_argument("teamcityUrl", type=str, help="Address to the teamcity server")
  9. parser.add_argument("buildTypeId", type=str, help="The ID of this build step")
  10. parser.add_argument("buildId", type=str, help="ID of the build to generate this report for")
  11. parser.add_argument("stagingRepoUrl", type=str, help="URL to the staging repository")
  12. args = parser.parse_args()
  13. buildResultUrl = "http://{}/viewLog.html?buildId={}&tab=buildResultsDiv&buildTypeId={}".format(args.teamcityUrl, args.buildId, args.buildTypeId)
  14. def createTableRow(*columns):
  15. html = "<tr>"
  16. for column in columns:
  17. html += "<td>" + column + "</td>"
  18. return html + "</tr>"
  19. def getHtmlList(array):
  20. html = "<ul>"
  21. for item in array:
  22. html += "<li>" + item + "</li>"
  23. return html + "</ul>"
  24. def getBuildStatusHtml():
  25. build_steps_request_string = "http://{}/app/rest/problemOccurrences?locator=build:{}".format(args.teamcityUrl, args.buildId)
  26. build_steps_request = requests.get(build_steps_request_string, auth=(args.teamcityUser, args.teamcityPassword), headers={'Accept':'application/json'})
  27. if build_steps_request.status_code != 200:
  28. return createTableRow(traffic_light.format(color="black"), "Build status: unable to retrieve status of build")
  29. else:
  30. build_steps_json = build_steps_request.json()
  31. if build_steps_json["count"] == 0:
  32. return createTableRow(traffic_light.format(color="green"), "Build status: all build steps successful")
  33. else:
  34. return createTableRow(traffic_light.format(color="red"), "Build status: there are failing build steps, <a href={}>check the build report</a>".format(buildResultUrl))
  35. def getTestStatusHtml():
  36. test_failures_request_string = "http://{}/app/rest/testOccurrences?locator=build:{},status:FAILURE".format(args.teamcityUrl, args.buildId)
  37. test_failures_request = requests.get(test_failures_request_string, auth=(args.teamcityUser, args.teamcityPassword), headers={'Accept':'application/json'})
  38. if test_failures_request.status_code != 200:
  39. return createTableRow(traffic_light.format(color="black"), "Test status: unable to retrieve status of tests")
  40. else:
  41. test_failures_json = test_failures_request.json()
  42. if test_failures_json["count"] == 0:
  43. return createTableRow(traffic_light.format(color="green"), "Test status: all tests passing")
  44. else:
  45. return createTableRow(traffic_light.format(color="red"), "Test status: there are " + str(test_failures_json["count"]) + " failing tests, <a href={}>check the build report</a>".format(buildResultUrl))
  46. def getDemoValidationStatusHtml():
  47. status = pickle.load(open("result/demo_validation_status.pickle", "rb"))
  48. if status["error"]:
  49. return createTableRow(traffic_light.format(color="red"), getHtmlList(status["messages"]))
  50. else:
  51. return createTableRow(traffic_light.format(color="green"), getHtmlList(status["messages"]))
  52. def getDemoLinksHtml():
  53. demos_html = "Try demos"
  54. link_list = list(map(lambda demo: "<a href='{url}/{demoName}-{version}'>{demoName}</a>".format(url=args.deployUrl, demoName=demo, version=args.version), demos))
  55. return demos_html + getHtmlList(link_list) + "Note that the deployed framework8-demo WARs have a suffix -0..-4."
  56. def getApiDiffHtml():
  57. apidiff_html = "Check API diff"
  58. modules = [
  59. "client", "client-compiler",
  60. "compatibility-client",
  61. "compatibility-server",
  62. "compatibility-shared",
  63. "server", "shared"
  64. ]
  65. link_list = list(map(lambda module: "<a href='http://{}/repository/download/{}/{}:id/apidiff/{}/japicmp.html'>{}</a>".format(args.teamcityUrl, args.buildTypeId, args.buildId, module, module), modules))
  66. return apidiff_html + getHtmlList(link_list)
  67. def getDirs(url):
  68. page = requests.get(url)
  69. files = re.findall('<a href=.*>(.*)</a>', page.text)
  70. dirs = filter(lambda x: x.endswith('/'), files)
  71. return list(map(lambda x: x.replace('/', ''), dirs))
  72. def dirTree(url):
  73. dirs = getDirs(url)
  74. result = []
  75. for d in dirs:
  76. result.append(d)
  77. subDirs = list(map(lambda x: d + '/' + x, dirTree(url + '/' + d)))
  78. result.extend(subDirs)
  79. return result
  80. def getAllowedArtifactPaths(allowedArtifacts):
  81. result = []
  82. for artifact in allowedArtifacts:
  83. parts = artifact.split('/', 1)
  84. result.append(parts[0])
  85. if len(parts) > 1:
  86. subart = getAllowedArtifactPaths([ parts[1] ])
  87. subArtifacts = list(map(lambda x: parts[0] + '/' + x, subart))
  88. result.extend(subArtifacts)
  89. return result
  90. def checkStagingContents(url, allowedArtifacts):
  91. dirs = dirTree(url)
  92. allowedDirs = getAllowedArtifactPaths(allowedArtifacts)
  93. return set(dirs) == set(allowedDirs)
  94. def getStagingContentsHtml(repoUrl, allowedArtifacts):
  95. if checkStagingContents(repoUrl, allowedArtifacts):
  96. return createTableRow(traffic_light.format(color="green"), "Expected artifacts found in the staging repository. <a href=\"{}\">Link to the repository.</a>".format(repoUrl))
  97. else:
  98. return createTableRow(traffic_light.format(color="red"), "Extraneous or missing artifacts in the staging repository. <a href=\"{}\">Link to the repository.</a>".format(repoUrl))
  99. def completeArtifactName(artifactId, version):
  100. return 'com/vaadin/' + artifactId + '/' + version
  101. def completeArtifactNames(artifactIds, version):
  102. return list(map(lambda x: completeArtifactName(x, version), artifactIds))
  103. allowedArtifacts = completeArtifactNames([ 'vaadin-maven-plugin', 'vaadin-archetypes', 'vaadin-archetype-application', 'vaadin-archetype-application-multimodule', 'vaadin-archetype-application-example', 'vaadin-archetype-widget', 'vaadin-archetype-liferay-portlet', 'vaadin-root', 'vaadin-shared', 'vaadin-server', 'vaadin-client', 'vaadin-client-compiler', 'vaadin-client-compiled', 'vaadin-push', 'vaadin-themes', 'vaadin-compatibility-shared', 'vaadin-compatibility-server', 'vaadin-compatibility-client', 'vaadin-compatibility-client-compiled', 'vaadin-compatibility-themes', 'vaadin-testbench-api', 'vaadin-bom' ], args.version)
  104. content = "<html><head></head><body><table>"
  105. traffic_light = "<svg width=\"20px\" height=\"20px\" style=\"padding-right:5px\"><circle cx=\"10\" cy=\"10\" r=\"10\" fill=\"{color}\"/></svg>"
  106. # Build step status
  107. content += getBuildStatusHtml()
  108. # Test failures
  109. content += getTestStatusHtml()
  110. # Missing @since tags
  111. try:
  112. p1 = subprocess.Popen(['find', '.', '-name', '*.java'], stdout=subprocess.PIPE)
  113. p2 = subprocess.Popen(['xargs', 'egrep', '-n', '@since ?$'], stdin=p1.stdout, stdout=subprocess.PIPE)
  114. missing = subprocess.check_output(['egrep', '-v', '/(testbench|test|tests|target)/'], stdin=p2.stdout)
  115. content += createTableRow(traffic_light.format(color="red"), "Empty @since:<br><pre>%s</pre>" % (missing))
  116. except subprocess.CalledProcessError as e:
  117. if e.returncode == 1:
  118. content += createTableRow(traffic_light.format(color="green"), "No empty @since")
  119. else:
  120. raise e
  121. # check staging repositories don't contain extra artifacts
  122. content += getStagingContentsHtml(args.stagingRepoUrl, allowedArtifacts)
  123. content += createTableRow("", "<h2>Manual checks before publishing</h2>")
  124. # try demos
  125. content += createTableRow("", getDemoLinksHtml())
  126. # link to release notes
  127. content += createTableRow("", "<a href=\"http://{}/repository/download/{}/{}:id/release-notes/release-notes.html\">Check release notes</a>".format(args.teamcityUrl, args.buildTypeId, args.buildId))
  128. # link to api diff
  129. content += createTableRow("", getApiDiffHtml())
  130. # check that GitHub issues are in the correct status
  131. content += createTableRow("", "<a href=\"https://github.com/vaadin/framework/issues?q=is%3Aclosed+sort%3Aupdated-desc\">Check that closed GitHub issues have correct milestone</a>")
  132. content += createTableRow("", "<h2>Preparations before publishing</h2>")
  133. # link to build dependencies tab to initiate publish step
  134. content += createTableRow("", "<a href=\"http://{}/viewLog.html?buildId={}&buildTypeId={}&tab=dependencies\"><h2>Start Publish Release from dependencies tab</h2></a>".format(args.teamcityUrl, args.buildId, args.buildTypeId))
  135. content += "</table></body></html>"
  136. f = open("result/report.html", 'w')
  137. f.write(content)