roll_wpt.py 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. #!/usr/bin/env python3
  2. # Copyright 2022 The Chromium Authors. All rights reserved.
  3. # Use of this source code is governed by a BSD-style license that can be
  4. # found in the LICENSE file.
  5. """Pulls the latest revisions of the wpt tooling."""
  6. import os
  7. import shutil
  8. import subprocess
  9. import sys
  10. import time
  11. BUG_QUERY_URLS = ["https://bugs.chromium.org/p/chromium/issues/list?"
  12. "q=component%3ABlink%3EInfra%3EEcosystem%20%22WPT%20Tooling%20Roll%22&can=2",
  13. "https://bugs.chromium.org/p/chromium/issues/list?"
  14. "q=component%3ABlink%3EInfra%3EEcosystem%20%22WPT%20JS%20Roll%22&can=2"]
  15. def main():
  16. current_branch = subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD'])
  17. current_branch = current_branch.rstrip().decode('utf-8')
  18. print("Roll wpt on branch: %s" % current_branch)
  19. print("Are there outstanding bugs at %s (Y/n)?" % BUG_QUERY_URLS[0],
  20. end='', flush=True)
  21. yesno = sys.stdin.readline().strip()
  22. if yesno not in ['N', 'n']:
  23. return 1
  24. remote_head = subprocess.check_output(['git',
  25. 'ls-remote',
  26. 'https://github.com/web-platform-tests/wpt',
  27. 'refs/heads/master'])
  28. remote_head = remote_head.rstrip().decode('utf-8').split()
  29. remote_head = remote_head[0]
  30. print("Roll to remote head: %s" % remote_head)
  31. pattern = "s/^Version: .*$/Version: %s/g" % remote_head
  32. path_to_wpt_tools_dir = os.path.abspath(os.path.dirname(__file__))
  33. path_to_readme = os.path.join(path_to_wpt_tools_dir, "README.chromium")
  34. # Update Version in //third_party/wpt_tools/README.chromium
  35. # This program only works on linux for now, as sed has slightly
  36. # different format on mac
  37. print("Update commit hash code for %s" % path_to_readme)
  38. subprocess.check_call(["sed", "-i", pattern, path_to_readme])
  39. path_to_checkout = os.path.join(path_to_wpt_tools_dir, "checkout.sh")
  40. print("Call %s\n" % path_to_checkout)
  41. subprocess.check_output([path_to_checkout, remote_head])
  42. change_files = subprocess.check_output(['git',
  43. 'diff',
  44. 'HEAD',
  45. '--no-renames',
  46. '--name-only'])
  47. change_files = change_files.decode('utf-8').strip()
  48. if change_files == '':
  49. print("No tooling changes to roll!")
  50. return 0
  51. subprocess.check_call(['git', 'add', path_to_wpt_tools_dir])
  52. wpt_try_bots = ["linux-wpt-identity-fyi-rel",
  53. "linux-wpt-input-fyi-rel",
  54. "android-weblayer-pie-x86-wpt-smoketest",
  55. "linux-blink-rel"]
  56. upstream_url = "https://github.com/web-platform-tests/wpt"
  57. message = "Roll wpt tooling\n\nThis rolls wpt to latest commit at\n%s.\n" % upstream_url
  58. message += "REMOTE-WPT-HEAD: %s\n\n" % remote_head
  59. message += "Cq-Include-Trybots: luci.chromium.try:%s\n" % ','.join(wpt_try_bots)
  60. subprocess.check_call(['git', 'commit', '-m', message])
  61. subprocess.check_call(['git',
  62. 'cl',
  63. 'upload',
  64. '--cq-dry-run',
  65. '--bypass-hooks',
  66. '-f'])
  67. output = subprocess.check_output(['git', 'cl', 'issue']).decode('utf-8')
  68. issue_number = output.strip().split()[2]
  69. print("\nCL uploaded to https://chromium-review.googlesource.com/%s" % issue_number)
  70. print("Please monitor the results on WPT try bots.")
  71. print("One common failure is that some dependency is not satisfied.")
  72. print("Please consider update WPTIncludeList in such case.")
  73. print("\n\nNow roll wpt javascript")
  74. print("Are there outstanding bugs at %s (Y/n)?" % BUG_QUERY_URLS[1],
  75. end='', flush=True)
  76. yesno = sys.stdin.readline().strip()
  77. if yesno not in ['N', 'n']:
  78. return 1
  79. javascript_branch = "%s-%d" % (current_branch, int(time.time()))
  80. print("Roll wpt javascript on branch: %s" % javascript_branch)
  81. subprocess.check_call(['git', 'new-branch', javascript_branch])
  82. files_to_roll = ["testharness.js", "testdriver.js", "testdriver-actions.js", "check-layout-th.js"]
  83. chromium_src_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir))
  84. source_dir = os.path.join(chromium_src_dir,
  85. "third_party",
  86. "blink",
  87. "web_tests",
  88. "external",
  89. "wpt",
  90. "resources")
  91. dst_dir = os.path.join(chromium_src_dir,
  92. "third_party",
  93. "blink",
  94. "web_tests",
  95. "resources")
  96. for f in files_to_roll:
  97. shutil.copy(os.path.join(source_dir, f),
  98. os.path.join(dst_dir, f))
  99. change_files = subprocess.check_output(['git',
  100. 'diff',
  101. 'HEAD',
  102. '--no-renames',
  103. '--name-only'])
  104. change_files = change_files.decode('utf-8').strip()
  105. if change_files == '':
  106. print("No javascript changes to roll!")
  107. else:
  108. for f in files_to_roll:
  109. subprocess.check_call(['git', 'add', os.path.join(dst_dir, f)])
  110. message = ("Roll wpt javascript\n\nThis rolls wpt javascript to latest commit at\n"
  111. "%s.\n" % upstream_url)
  112. subprocess.check_call(['git', 'commit', '-m', message])
  113. subprocess.check_call(['git',
  114. 'cl',
  115. 'upload',
  116. '--cq-dry-run',
  117. '--bypass-hooks',
  118. '-f'])
  119. output = subprocess.check_output(['git', 'cl', 'issue']).decode('utf-8')
  120. issue_number = output.strip().split()[2]
  121. print("\nCL uploaded to https://chromium-review.googlesource.com/%s" % issue_number)
  122. print("Deleting branch %s.\nCurrent branch is %s." % (javascript_branch, current_branch))
  123. subprocess.check_call(['git', 'checkout', current_branch])
  124. subprocess.check_call(['git', 'branch', '-D', javascript_branch])
  125. return 0
  126. if __name__ == '__main__':
  127. sys.exit(main())