|
13 | 13 | import os |
14 | 14 | import subprocess |
15 | 15 | import sys |
16 | | -import shutil |
| 16 | +import urllib.request |
17 | 17 |
|
18 | 18 |
|
19 | 19 | def node_path(options): |
@@ -56,6 +56,7 @@ def node_path(options): |
56 | 56 | class ReferenceMode(enum.Enum): |
57 | 57 | Tot = 'tot' |
58 | 58 | WorkingTree = 'working-tree' |
| 59 | + CfT = 'CfT' |
59 | 60 |
|
60 | 61 | def __str__(self): |
61 | 62 | return self.value |
@@ -94,6 +95,26 @@ def update(options): |
94 | 95 | subprocess.check_call(['gclient', 'sync'], cwd=options.chromium_dir) |
95 | 96 |
|
96 | 97 |
|
| 98 | +def checkout_chromium_commit_position(options, target_position): |
| 99 | + target_position = int(target_position) |
| 100 | + |
| 101 | + grep_pattern = f'Cr-Commit-Position: .*@{{#{target_position}}}' |
| 102 | + cmd = [ |
| 103 | + 'git', 'log', 'origin/main', f'--grep={grep_pattern}', '-1', |
| 104 | + '--format=%H' |
| 105 | + ] |
| 106 | + commit_hash = subprocess.check_output(cmd, |
| 107 | + cwd=options.chromium_dir, |
| 108 | + text=True).strip() |
| 109 | + |
| 110 | + if not commit_hash: |
| 111 | + raise RuntimeError( |
| 112 | + f'Could not find commit for position {target_position}') |
| 113 | + |
| 114 | + subprocess.check_call(['git', 'checkout', commit_hash], |
| 115 | + cwd=options.chromium_dir) |
| 116 | + |
| 117 | + |
97 | 118 | def sync_node(options): |
98 | 119 | """Node is managed as a standard GCS deps so we run gclient sync but without hooks""" |
99 | 120 | subprocess.check_call(['gclient', 'sync', '--nohooks'], |
@@ -222,6 +243,45 @@ def update_deps_revision(options): |
222 | 243 | }, f) |
223 | 244 |
|
224 | 245 |
|
| 246 | +def get_json(url): |
| 247 | + with urllib.request.urlopen(url) as response: |
| 248 | + return json.loads(response.read().decode('utf-8')) |
| 249 | + |
| 250 | + |
| 251 | +def version_tuple(version): |
| 252 | + return tuple(map(int, version.split('.'))) |
| 253 | + |
| 254 | + |
| 255 | +def updateCfT(options): |
| 256 | + """ |
| 257 | + Update the Chrome for testing dependency. |
| 258 | + """ |
| 259 | + print('Updating Chrome for Testing...') |
| 260 | + json_data = get_json( |
| 261 | + "https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions.json" |
| 262 | + ) |
| 263 | + canary_channel = json_data['channels']['Canary'] |
| 264 | + new_version = canary_channel['version'] |
| 265 | + commit_position = canary_channel['revision'] |
| 266 | + |
| 267 | + current_version = subprocess.check_output( |
| 268 | + ['gclient', 'getdep', '--var=chrome'], |
| 269 | + cwd=options.devtools_dir, |
| 270 | + text=True).strip() |
| 271 | + |
| 272 | + if current_version and (version_tuple(current_version) |
| 273 | + < version_tuple(new_version)): |
| 274 | + print( |
| 275 | + f'Updating Chrome for Testing: {current_version} -> {new_version}') |
| 276 | + subprocess.check_call( |
| 277 | + ['gclient', 'setdep', f'--var=chrome={new_version}'], |
| 278 | + cwd=options.devtools_dir) |
| 279 | + else: |
| 280 | + print(f'Chrome for Testing is up to date: {current_version}') |
| 281 | + |
| 282 | + return commit_position |
| 283 | + |
| 284 | + |
225 | 285 | def update_readme_revision(options): |
226 | 286 | print('updating README.chromium revision') |
227 | 287 | readme_path = os.path.join(options.devtools_dir, 'front_end', |
@@ -254,6 +314,9 @@ def update_readme_revision(options): |
254 | 314 | OPTIONS = parse_options(sys.argv[1:]) |
255 | 315 | if OPTIONS.ref == ReferenceMode.Tot: |
256 | 316 | update(OPTIONS) |
| 317 | + if OPTIONS.ref == ReferenceMode.CfT: |
| 318 | + commit_position = updateCfT(OPTIONS) |
| 319 | + checkout_chromium_commit_position(OPTIONS, commit_position) |
257 | 320 | elif OPTIONS.update_node: |
258 | 321 | sync_node(OPTIONS) |
259 | 322 | copy_files(OPTIONS) |
|
0 commit comments