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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. buildResultUrl = "http://{}/viewLog.html?buildId={}&tab=buildResultsDiv&buildTypeId={}".format(args.teamcityUrl, args.buildId, args.buildTypeId)
  13. def createTableRow(*columns):
  14. html = "<tr>"
  15. for column in columns:
  16. html += "<td>" + column + "</td>"
  17. return html + "</tr>"
  18. def getHtmlList(array):
  19. html = "<ul>"
  20. for item in array:
  21. html += "<li>" + item + "</li>"
  22. return html + "</ul>"
  23. def getBuildStatusHtml():
  24. build_steps_request_string = "http://{}/app/rest/problemOccurrences?locator=build:{}".format(args.teamcityUrl, args.buildId)
  25. build_steps_request = requests.get(build_steps_request_string, auth=(args.teamcityUser, args.teamcityPassword), headers={'Accept':'application/json'})
  26. if build_steps_request.status_code != 200:
  27. return createTableRow(traffic_light.format(color="black"), "Build status: unable to retrieve status of build")
  28. else:
  29. build_steps_json = build_steps_request.json()
  30. if build_steps_json["count"] == 0:
  31. return createTableRow(traffic_light.format(color="green"), "Build status: all build steps successful")
  32. else:
  33. return createTableRow(traffic_light.format(color="red"), "Build status: there are failing build steps, <a href={}>check the build report</a>".format(buildResultUrl))
  34. def getTestStatusHtml():
  35. test_failures_request_string = "http://{}/app/rest/testOccurrences?locator=build:{},status:FAILURE".format(args.teamcityUrl, args.buildId)
  36. test_failures_request = requests.get(test_failures_request_string, auth=(args.teamcityUser, args.teamcityPassword), headers={'Accept':'application/json'})
  37. if test_failures_request.status_code != 200:
  38. return createTableRow(traffic_light.format(color="black"), "Test status: unable to retrieve status of tests")
  39. else:
  40. test_failures_json = test_failures_request.json()
  41. # nowadays the responds doesn't contain count keyword when the build is successful
  42. # while count word can be found when build fails
  43. if "count" not in test_failures_json:
  44. return createTableRow(traffic_light.format(color="green"), "Test status: all tests passing")
  45. else:
  46. 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))
  47. def getApiDiffHtml():
  48. apidiff_html = "Check API diff"
  49. modules = [
  50. "client", "client-compiler",
  51. "compatibility-client",
  52. "compatibility-server",
  53. "compatibility-server-gae",
  54. "compatibility-shared",
  55. "liferay-integration",
  56. "osgi-integration",
  57. "server", "shared"
  58. ]
  59. 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))
  60. return apidiff_html + getHtmlList(link_list)
  61. def getDirs(url):
  62. page = requests.get(url)
  63. files = re.findall('<a href=.*>(.*)</a>', page.text)
  64. dirs = filter(lambda x: x.endswith('/'), files)
  65. return list(map(lambda x: x.replace('/', ''), dirs))
  66. def dirTree(url):
  67. dirs = getDirs(url)
  68. result = []
  69. for d in dirs:
  70. result.append(d)
  71. subDirs = list(map(lambda x: d + '/' + x, dirTree(url + '/' + d)))
  72. result.extend(subDirs)
  73. return result
  74. def getAllowedArtifactPaths(allowedArtifacts):
  75. result = []
  76. for artifact in allowedArtifacts:
  77. parts = artifact.split('/', 1)
  78. result.append(parts[0])
  79. if len(parts) > 1:
  80. subart = getAllowedArtifactPaths([ parts[1] ])
  81. subArtifacts = list(map(lambda x: parts[0] + '/' + x, subart))
  82. result.extend(subArtifacts)
  83. return result
  84. def checkStagingContents(url, allowedArtifacts):
  85. dirs = dirTree(url)
  86. allowedDirs = getAllowedArtifactPaths(allowedArtifacts)
  87. return set(dirs) == set(allowedDirs)
  88. def getStagingContentsHtml(repoUrl, allowedArtifacts):
  89. if checkStagingContents(repoUrl, allowedArtifacts):
  90. return createTableRow(traffic_light.format(color="green"), "Expected artifacts found in the staging repository. <a href=\"{}\">Link to the repository.</a>".format(repoUrl))
  91. else:
  92. return createTableRow(traffic_light.format(color="red"), "Extraneous or missing artifacts in the staging repository. <a href=\"{}\">Link to the repository.</a>".format(repoUrl))
  93. def completeArtifactName(artifactId, version):
  94. return 'com/vaadin/' + artifactId + '/' + version
  95. def completeArtifactNames(artifactIds, version):
  96. return list(map(lambda x: completeArtifactName(x, version), artifactIds))
  97. 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)
  98. content = "<html><head></head><body><table>"
  99. traffic_light = "<svg width=\"20px\" height=\"20px\" style=\"padding-right:5px\"><circle cx=\"10\" cy=\"10\" r=\"10\" fill=\"{color}\"/></svg>"
  100. # Build step status
  101. content += getBuildStatusHtml()
  102. # Test failures
  103. content += getTestStatusHtml()
  104. # Missing @since tags
  105. try:
  106. p1 = subprocess.Popen(['find', '.', '-name', '*.java'], stdout=subprocess.PIPE)
  107. p2 = subprocess.Popen(['xargs', 'egrep', '-n', '@since ?$'], stdin=p1.stdout, stdout=subprocess.PIPE)
  108. missing = subprocess.check_output(['egrep', '-v', '/(testbench|test|tests|target)/'], stdin=p2.stdout)
  109. content += createTableRow(traffic_light.format(color="red"), "Empty @since:<br><pre>%s</pre>" % (missing))
  110. except subprocess.CalledProcessError as e:
  111. if e.returncode == 1:
  112. content += createTableRow(traffic_light.format(color="green"), "No empty @since")
  113. else:
  114. raise e
  115. # check staging repositories don't contain extra artifacts
  116. content += getStagingContentsHtml(args.stagingRepoUrl, allowedArtifacts)
  117. content += createTableRow("", "<h2>Manual checks before publishing</h2>")
  118. content += createTableRow("", "If changing between branches or phases (stable, maintenance, alpha, beta, rc), check the phase change checklist")
  119. # link to release notes
  120. content += createTableRow("", "<a href=\"http://{}/repository/download/{}/{}:id/release-notes/release-notes.html\">Check release notes</a>".format(args.teamcityUrl, args.buildTypeId, args.buildId))
  121. # link to api diff
  122. content += createTableRow("", getApiDiffHtml())
  123. # check that GitHub issues are in the correct status
  124. 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>")
  125. 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))
  126. content += createTableRow("", "<h2>Preparations before publishing</h2>")
  127. # link to build dependencies tab to initiate publish step
  128. 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))
  129. content += "</table></body></html>"
  130. f = open("result/report.html", 'w')
  131. f.write(content)