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 9.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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("frameworkRepoUrl", type=str, help="URL to the framework staging repository")
  12. parser.add_argument("archetypeRepoUrl", type=str, help="URL to the archetype staging repository")
  13. parser.add_argument("pluginRepoUrl", type=str, help="URL to the plugin staging repository")
  14. args = parser.parse_args()
  15. buildResultUrl = "http://{}/viewLog.html?buildId={}&tab=buildResultsDiv&buildTypeId={}".format(args.teamcityUrl, args.buildId, args.buildTypeId)
  16. def createTableRow(*columns):
  17. html = "<tr>"
  18. for column in columns:
  19. html += "<td>" + column + "</td>"
  20. return html + "</tr>"
  21. def getHtmlList(array):
  22. html = "<ul>"
  23. for item in array:
  24. html += "<li>" + item + "</li>"
  25. return html + "</ul>"
  26. def getBuildStatusHtml():
  27. build_steps_request_string = "http://{}/app/rest/problemOccurrences?locator=build:{}".format(args.teamcityUrl, args.buildId)
  28. build_steps_request = requests.get(build_steps_request_string, auth=(args.teamcityUser, args.teamcityPassword), headers={'Accept':'application/json'})
  29. if build_steps_request.status_code != 200:
  30. return createTableRow(traffic_light.format(color="black"), "Build status: unable to retrieve status of build")
  31. else:
  32. build_steps_json = build_steps_request.json()
  33. if build_steps_json["count"] == 0:
  34. return createTableRow(traffic_light.format(color="green"), "Build status: all build steps successful")
  35. else:
  36. return createTableRow(traffic_light.format(color="red"), "Build status: there are failing build steps, <a href={}>check the build report</a>".format(buildResultUrl))
  37. def getTestStatusHtml():
  38. test_failures_request_string = "http://{}/app/rest/testOccurrences?locator=build:{},status:FAILURE".format(args.teamcityUrl, args.buildId)
  39. test_failures_request = requests.get(test_failures_request_string, auth=(args.teamcityUser, args.teamcityPassword), headers={'Accept':'application/json'})
  40. if test_failures_request.status_code != 200:
  41. return createTableRow(traffic_light.format(color="black"), "Test status: unable to retrieve status of tests")
  42. else:
  43. test_failures_json = test_failures_request.json()
  44. if test_failures_json["count"] == 0:
  45. return createTableRow(traffic_light.format(color="green"), "Test status: all tests passing")
  46. else:
  47. 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))
  48. def getDemoValidationStatusHtml():
  49. status = pickle.load(open("result/demo_validation_status.pickle", "rb"))
  50. if status["error"]:
  51. return createTableRow(traffic_light.format(color="red"), getHtmlList(status["messages"]))
  52. else:
  53. return createTableRow(traffic_light.format(color="green"), getHtmlList(status["messages"]))
  54. def getDemoLinksHtml():
  55. demos_html = "Try demos"
  56. link_list = list(map(lambda demo: "<a href='{url}/{demoName}-{version}'>{demoName}</a>".format(url=args.deployUrl, demoName=demo, version=args.version), demos))
  57. return demos_html + getHtmlList(link_list)
  58. def getApiDiffHtml():
  59. apidiff_html = "Check API diff"
  60. modules = [
  61. "client", "client-compiler",
  62. "compatibility-client",
  63. "compatibility-server",
  64. "compatibility-shared",
  65. "server", "shared"
  66. ]
  67. 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))
  68. return apidiff_html + getHtmlList(link_list)
  69. def getDirs(url):
  70. page = requests.get(url)
  71. files = re.findall('<a href=.*>(.*)</a>', page.text)
  72. dirs = filter(lambda x: x.endswith('/'), files)
  73. return list(map(lambda x: x.replace('/', ''), dirs))
  74. def dirTree(url):
  75. dirs = getDirs(url)
  76. result = []
  77. for d in dirs:
  78. result.append(d)
  79. subDirs = list(map(lambda x: d + '/' + x, dirTree(url + '/' + d)))
  80. result.extend(subDirs)
  81. return result
  82. def getAllowedArtifactPaths(allowedArtifacts):
  83. result = []
  84. for artifact in allowedArtifacts:
  85. parts = artifact.split('/', 1)
  86. result.append(parts[0])
  87. if len(parts) > 1:
  88. subart = getAllowedArtifactPaths([ parts[1] ])
  89. subArtifacts = list(map(lambda x: parts[0] + '/' + x, subart))
  90. result.extend(subArtifacts)
  91. return result
  92. def checkStagingContents(url, allowedArtifacts):
  93. dirs = dirTree(url)
  94. allowedDirs = getAllowedArtifactPaths(allowedArtifacts)
  95. return set(dirs) == set(allowedDirs)
  96. def getStagingContentsHtml(repoUrl, allowedArtifacts, name):
  97. if checkStagingContents(repoUrl, allowedArtifacts):
  98. return createTableRow(traffic_light.format(color="green"), "No extra artifacts found in the {} staging repository. <a href=\"{}\">Link to the repository.</a>".format(name, repoUrl))
  99. else:
  100. return createTableRow(traffic_light.format(color="red"), "Extra artifacts found in the {} staging repository. <a href=\"{}\">Link to the repository.</a>".format(name, repoUrl))
  101. def completeArtifactName(artifactId, version):
  102. return 'com/vaadin/' + artifactId + '/' + version
  103. def completeArtifactNames(artifactIds, version):
  104. return list(map(lambda x: completeArtifactName(x, version), artifactIds))
  105. allowedPluginArtifacts = completeArtifactNames([ 'vaadin-maven-plugin' ], args.version)
  106. allowedArchetypeArtifacts = completeArtifactNames([ 'vaadin-archetype-application', 'vaadin-archetype-application-multimodule', 'vaadin-archetype-application-example', 'vaadin-archetype-widget', 'vaadin-archetype-liferay-portlet' ], args.version)
  107. allowedFrameworkArtifacts = completeArtifactNames([ 'vaadin-root', 'vaadin-bom', 'vaadin-shared', 'vaadin-server', 'vaadin-client', 'vaadin-client-compiler', 'vaadin-client-compiled', 'vaadin-push', 'vaadin-themes', 'vaadin-widgets', 'vaadin-compatibility-shared', 'vaadin-compatibility-server', 'vaadin-compatibility-client', 'vaadin-compatibility-client-compiled', 'vaadin-compatibility-themes' ], args.version)
  108. content = "<html><head></head><body><table>"
  109. traffic_light = "<svg width=\"20px\" height=\"20px\" style=\"padding-right:5px\"><circle cx=\"10\" cy=\"10\" r=\"10\" fill=\"{color}\"/></svg>"
  110. # Build step status
  111. content += getBuildStatusHtml()
  112. # Test failures
  113. content += getTestStatusHtml()
  114. # Missing @since tags
  115. try:
  116. p1 = subprocess.Popen(['find', '.', '-name', '*.java'], stdout=subprocess.PIPE)
  117. p2 = subprocess.Popen(['xargs', 'egrep', '-n', '@since ?$'], stdin=p1.stdout, stdout=subprocess.PIPE)
  118. missing = subprocess.check_output(['egrep', '-v', '/(testbench|test|tests|target)/'], stdin=p2.stdout)
  119. content += createTableRow(traffic_light.format(color="red"), "Empty @since:<br><pre>%s</pre>" % (missing))
  120. except subprocess.CalledProcessError as e:
  121. if e.returncode == 1:
  122. content += createTableRow(traffic_light.format(color="green"), "No empty @since")
  123. else:
  124. raise e
  125. # check staging repositories don't contain extra artifacts
  126. content += getStagingContentsHtml(args.frameworkRepoUrl, allowedFrameworkArtifacts, "framework")
  127. content += getStagingContentsHtml(args.archetypeRepoUrl, allowedArchetypeArtifacts, "archetype")
  128. content += getStagingContentsHtml(args.pluginRepoUrl, allowedPluginArtifacts, "plugin")
  129. content += createTableRow("", "<h2>Manual checks before publishing</h2>")
  130. # try demos
  131. content += createTableRow("", getDemoLinksHtml())
  132. # link to release notes
  133. content += createTableRow("", "<a href=\"http://{}/repository/download/{}/{}:id/release-notes/release-notes.html\">Check release notes</a>".format(args.teamcityUrl, args.buildTypeId, args.buildId))
  134. # link to api diff
  135. content += createTableRow("", getApiDiffHtml())
  136. # check that trac tickets are in the correct status
  137. content += createTableRow("", "<a href=\"https://dev.vaadin.com/query?status=closed&status=pending-release&component=Core+Framework&resolution=fixed&group=milestone&col=id&col=summary&col=component&col=status&col=type&col=priority&col=milestone&order=priority\">Check that trac tickets have correct status</a>")
  138. # pending release tickets without milestone
  139. content += createTableRow("", "<a href=\"https://dev.vaadin.com/query?status=pending-release&milestone=\">Pending-release tickets without milestone</a>")
  140. content += createTableRow("", "<h2>Preparations before publishing</h2>")
  141. # close trac milestone
  142. content += createTableRow("", "<a href=\"https://dev.vaadin.com/milestone/Vaadin {version}\">Close Trac Milestone (deselect \"retarget tickets\")</a>".format(version=args.version))
  143. # verify pending release tickets still have milestone
  144. content += createTableRow("", "<a href=\"https://dev.vaadin.com/query?status=pending-release&component=Core+Framework&resolution=fixed&col=id&col=summary&col=component&col=milestone&col=status&col=type\">Verify pending release tickets still have milestone {version}</a>".format(version=args.version))
  145. # link to build dependencies tab to initiate publish step
  146. 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))
  147. content += "</table></body></html>"
  148. f = open("result/report.html", 'w')
  149. f.write(content)