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.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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("teamcityUser", type=str, help="Teamcity username to use")
  6. parser.add_argument("teamcityPassword", type=str, help="Password for given teamcity username")
  7. parser.add_argument("teamcityUrl", type=str, help="Address to the teamcity server")
  8. parser.add_argument("buildTypeId", type=str, help="The ID of this build step")
  9. parser.add_argument("buildId", type=str, help="ID of the build to generate this report for")
  10. parser.add_argument("stagingRepoUrl", type=str, help="URL to the staging repository")
  11. args = parser.parse_args()
  12. print("stagingRepoURL" + args.stagingRepoUrl)
  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 getApiDiffHtml():
  47. apidiff_html = "Check API diff"
  48. modules = [
  49. "client", "client-compiler",
  50. "compatibility-client",
  51. "compatibility-server",
  52. "compatibility-server-gae",
  53. "compatibility-shared",
  54. "liferay-integration",
  55. "osgi-integration",
  56. "server", "shared"
  57. ]
  58. 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))
  59. return apidiff_html + getHtmlList(link_list)
  60. def getDirs(url):
  61. page = requests.get(url)
  62. files = re.findall('<a href=.*>(.*)</a>', page.text)
  63. dirs = filter(lambda x: x.endswith('/'), files)
  64. return list(map(lambda x: x.replace('/', ''), dirs))
  65. def dirTree(url):
  66. dirs = getDirs(url)
  67. result = []
  68. for d in dirs:
  69. result.append(d)
  70. subDirs = list(map(lambda x: d + '/' + x, dirTree(url + '/' + d)))
  71. result.extend(subDirs)
  72. return result
  73. def getAllowedArtifactPaths(allowedArtifacts):
  74. result = []
  75. for artifact in allowedArtifacts:
  76. parts = artifact.split('/', 1)
  77. result.append(parts[0])
  78. if len(parts) > 1:
  79. subart = getAllowedArtifactPaths([ parts[1] ])
  80. subArtifacts = list(map(lambda x: parts[0] + '/' + x, subart))
  81. result.extend(subArtifacts)
  82. return result
  83. def checkStagingContents(url, allowedArtifacts):
  84. dirs = dirTree(url)
  85. allowedDirs = getAllowedArtifactPaths(allowedArtifacts)
  86. print(dirs)
  87. print("~~~~~~~~~~~~~")
  88. print(allowedDirs)
  89. return set(dirs) == set(allowedDirs)
  90. def getStagingContentsHtml(repoUrl, allowedArtifacts):
  91. if checkStagingContents(repoUrl, allowedArtifacts):
  92. return createTableRow(traffic_light.format(color="green"), "Expected artifacts found in the staging repository. <a href=\"{}\">Link to the repository.</a>".format(repoUrl))
  93. else:
  94. return createTableRow(traffic_light.format(color="red"), "Extraneous or missing artifacts in the staging repository. <a href=\"{}\">Link to the repository.</a>".format(repoUrl))
  95. def completeArtifactName(artifactId, version):
  96. return 'com/vaadin/' + artifactId + '/' + version
  97. def completeArtifactNames(artifactIds, version):
  98. return list(map(lambda x: completeArtifactName(x, version), artifactIds))
  99. 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-server-gae", 'vaadin-compatibility-client', 'vaadin-compatibility-client-compiled', 'vaadin-compatibility-themes', 'vaadin-liferay-integration', "vaadin-osgi-integration", 'vaadin-testbench-api', 'vaadin-bom' ], args.version)
  100. content = "<html><head></head><body><table>"
  101. traffic_light = "<svg width=\"20px\" height=\"20px\" style=\"padding-right:5px\"><circle cx=\"10\" cy=\"10\" r=\"10\" fill=\"{color}\"/></svg>"
  102. # Build step status
  103. content += getBuildStatusHtml()
  104. # Test failures
  105. content += getTestStatusHtml()
  106. # Missing @since tags
  107. try:
  108. p1 = subprocess.Popen(['find', '.', '-name', '*.java'], stdout=subprocess.PIPE)
  109. p2 = subprocess.Popen(['xargs', 'egrep', '-n', '@since ?$'], stdin=p1.stdout, stdout=subprocess.PIPE)
  110. missing = subprocess.check_output(['egrep', '-v', '/(testbench|test|tests|target)/'], stdin=p2.stdout)
  111. content += createTableRow(traffic_light.format(color="red"), "Empty @since:<br><pre>%s</pre>" % (missing))
  112. except subprocess.CalledProcessError as e:
  113. if e.returncode == 1:
  114. content += createTableRow(traffic_light.format(color="green"), "No empty @since")
  115. else:
  116. raise e
  117. # check staging repositories don't contain extra artifacts
  118. content += getStagingContentsHtml(args.stagingRepoUrl, allowedArtifacts)
  119. content += createTableRow("", "<h2>Manual checks before publishing</h2>")
  120. content += createTableRow("", "If changing between branches or phases (stable, maintenance, alpha, beta, rc), check the phase change checklist")
  121. # link to release notes
  122. content += createTableRow("", "<a href=\"http://{}/repository/download/{}/{}:id/release-notes/release-notes.html\">Check release notes</a>".format(args.teamcityUrl, args.buildTypeId, args.buildId))
  123. # link to api diff
  124. content += createTableRow("", getApiDiffHtml())
  125. # check that GitHub issues are in the correct status
  126. 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>")
  127. content += createTableRow("", "Check demos from docker image:<br><pre>zcat < demo-validation-{version}.tgz |docker load && docker run --rm -p 8080:8080 demo-validation:{version} || docker rmi demo-validation:{version}</pre>".format(version=args.version))
  128. content += createTableRow("", "<h2>Preparations before publishing</h2>")
  129. # link to build dependencies tab to initiate publish step
  130. 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))
  131. content += "</table></body></html>"
  132. f = open("result/report.html", 'w')
  133. f.write(content)