11#!/usr/bin/env python
22
3+ import argparse
34import hashlib
45import json
56import os
@@ -25,7 +26,14 @@ def calculate_hash(url):
2526 return h .hexdigest ()
2627
2728
28- def get_chrome_info_for_channel (channel ):
29+ def get_chrome_milestone ():
30+ parser = argparse .ArgumentParser ()
31+ parser .add_argument (
32+ "--chrome_channel" , default = "Stable" , help = "Set the Chrome channel"
33+ )
34+ args = parser .parse_args ()
35+ channel = args .chrome_channel
36+
2937 r = http .request (
3038 "GET" ,
3139 f"https://chromiumdash.appspot.com/fetch_releases?channel={ channel } &num=1&platform=Mac,Linux" ,
@@ -47,18 +55,20 @@ def get_chrome_info_for_channel(channel):
4755 )[- 1 ]
4856
4957
50- def chromedriver (selected_version , workspace_prefix = "" ):
58+ def chromedriver (selected_version ):
5159 content = ""
5260
5361 drivers = selected_version ["downloads" ]["chromedriver" ]
5462
55- url = [d ["url" ] for d in drivers if d ["platform" ] == "linux64" ][0 ]
56- sha = calculate_hash (url )
63+ linux = [d ["url" ] for d in drivers if d ["platform" ] == "linux64" ][0 ]
64+ sha = calculate_hash (linux )
5765
58- content += f""" http_archive(
59- name = "linux_{ workspace_prefix } chromedriver",
60- url = "{ url } ",
61- sha256 = "{ sha } ",
66+ content = (
67+ content
68+ + """ http_archive(
69+ name = "linux_chromedriver",
70+ url = "%s",
71+ sha256 = "%s",
6272 strip_prefix = "chromedriver-linux64",
6373 build_file_content = \" \" \"
6474load("@aspect_rules_js//js:defs.bzl", "js_library")
@@ -73,15 +83,18 @@ def chromedriver(selected_version, workspace_prefix=""):
7383\" \" \" ,
7484 )
7585"""
86+ % (linux , sha )
87+ )
7688
77- url = [d ["url" ] for d in drivers if d ["platform" ] == "mac-x64" ][0 ]
78- sha = calculate_hash (url )
79-
80- content += f"""
89+ mac = [d ["url" ] for d in drivers if d ["platform" ] == "mac-x64" ][0 ]
90+ sha = calculate_hash (mac )
91+ content = (
92+ content
93+ + """
8194 http_archive(
82- name = "mac_ { workspace_prefix } chromedriver ",
83- url = "{ url } ",
84- sha256 = "{ sha } ",
95+ name = "mac_chromedriver ",
96+ url = "%s ",
97+ sha256 = "%s ",
8598 strip_prefix = "chromedriver-mac-x64",
8699 build_file_content = \" \" \"
87100load("@aspect_rules_js//js:defs.bzl", "js_library")
@@ -96,22 +109,23 @@ def chromedriver(selected_version, workspace_prefix=""):
96109\" \" \" ,
97110 )
98111"""
112+ % (mac , sha )
113+ )
99114
100115 return content
101116
102117
103- def chrome (selected_version , workspace_prefix = "" ):
104- content = ""
118+ def chrome (selected_version ):
105119 chrome_downloads = selected_version ["downloads" ]["chrome" ]
106120
107- url = [d ["url" ] for d in chrome_downloads if d ["platform" ] == "linux64" ][0 ]
108- sha = calculate_hash (url )
121+ linux = [d ["url" ] for d in chrome_downloads if d ["platform" ] == "linux64" ][0 ]
122+ sha = calculate_hash (linux )
109123
110- content += f """
124+ content = """
111125 http_archive(
112- name = "linux_ { workspace_prefix } chrome ",
113- url = "{ url } ",
114- sha256 = "{ sha } ",
126+ name = "linux_chrome ",
127+ url = "%s ",
128+ sha256 = "%s ",
115129 build_file_content = \" \" \"
116130load("@aspect_rules_js//js:defs.bzl", "js_library")
117131package(default_visibility = ["//visibility:public"])
@@ -129,15 +143,19 @@ def chrome(selected_version, workspace_prefix=""):
129143)
130144\" \" \" ,
131145 )
132- """
133146
134- url = [d ["url" ] for d in chrome_downloads if d ["platform" ] == "mac-x64" ][0 ]
135- sha = calculate_hash (url ) # Calculate SHA for Mac chrome
147+ """ % (
148+ linux ,
149+ sha ,
150+ )
151+
152+ mac = [d ["url" ] for d in chrome_downloads if d ["platform" ] == "mac-x64" ][0 ]
153+ sha = calculate_hash (mac )
136154
137- content += f """ http_archive(
138- name = "mac_ { workspace_prefix } chrome ",
139- url = "{ url } ",
140- sha256 = "{ sha } ",
155+ content += """ http_archive(
156+ name = "mac_chrome ",
157+ url = "%s ",
158+ sha256 = "%s ",
141159 strip_prefix = "chrome-mac-x64",
142160 patch_cmds = [
143161 "mv 'Google Chrome for Testing.app' Chrome.app",
@@ -155,7 +173,11 @@ def chrome(selected_version, workspace_prefix=""):
155173)
156174\" \" \" ,
157175 )
158- """
176+
177+ """ % (
178+ mac ,
179+ sha ,
180+ )
159181
160182 return content
161183
@@ -500,17 +522,9 @@ def pin_browsers():
500522 content = content + geckodriver ()
501523 content = content + edge ()
502524 content = content + edgedriver ()
503-
504- # Stable Chrome
505- stable_chrome_info = get_chrome_info_for_channel (channel = "Stable" )
506- content = content + chrome (stable_chrome_info , workspace_prefix = "" )
507- content = content + chromedriver (stable_chrome_info , workspace_prefix = "" )
508-
509- # Beta Chrome
510- beta_chrome_info = get_chrome_info_for_channel (channel = "Beta" )
511- content = content + chrome (beta_chrome_info , workspace_prefix = "beta_" )
512- content = content + chromedriver (beta_chrome_info , workspace_prefix = "beta_" )
513-
525+ chrome_milestone = get_chrome_milestone ()
526+ content = content + chrome (chrome_milestone )
527+ content = content + chromedriver (chrome_milestone )
514528 content += """
515529def _pin_browsers_extension_impl(_ctx):
516530 pin_browsers()
0 commit comments