11#!/usr/bin/env python 
22
3- import  argparse 
43import  hashlib 
54import  json 
65import  os 
@@ -26,14 +25,7 @@ def calculate_hash(url):
2625    return  h .hexdigest ()
2726
2827
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- 
28+ def  get_chrome_info_for_channel (channel ):
3729    r  =  http .request (
3830        "GET" ,
3931        f"https://chromiumdash.appspot.com/fetch_releases?channel={ channel }  ,
@@ -55,20 +47,18 @@ def get_chrome_milestone():
5547    )[- 1 ]
5648
5749
58- def  chromedriver (selected_version ):
50+ def  chromedriver (selected_version ,  workspace_prefix = "" ):
5951    content  =  "" 
6052
6153    drivers  =  selected_version ["downloads" ]["chromedriver" ]
6254
63-     linux  =  [d ["url" ] for  d  in  drivers  if  d ["platform" ] ==  "linux64" ][0 ]
64-     sha  =  calculate_hash (linux )
55+     url  =  [d ["url" ] for  d  in  drivers  if  d ["platform" ] ==  "linux64" ][0 ]
56+     sha  =  calculate_hash (url )
6557
66-     content  =  (
67-         content 
68-         +  """    http_archive( 
69-         name = "linux_chromedriver", 
70-         url = "%s", 
71-         sha256 = "%s", 
58+     content  +=  f"""    http_archive( 
59+         name = "linux_{ workspace_prefix }  
60+         url = "{ url }  
61+         sha256 = "{ sha }  
7262        strip_prefix = "chromedriver-linux64", 
7363        build_file_content = \" \" \"  
7464load("@aspect_rules_js//js:defs.bzl", "js_library") 
@@ -83,18 +73,15 @@ def chromedriver(selected_version):
8373\" \" \" ,
8474    ) 
8575""" 
86-         %  (linux , sha )
87-     )
8876
89-     mac  =  [d ["url" ] for  d  in  drivers  if  d ["platform" ] ==  "mac-x64" ][0 ]
90-     sha  =  calculate_hash (mac )
91-     content  =  (
92-         content 
93-         +  """ 
77+     url  =  [d ["url" ] for  d  in  drivers  if  d ["platform" ] ==  "mac-x64" ][0 ]
78+     sha  =  calculate_hash (url )
79+ 
80+     content  +=  f""" 
9481    http_archive( 
95-         name = "mac_chromedriver ", 
96-         url = "%s ", 
97-         sha256 = "%s ", 
82+         name = "mac_ { workspace_prefix } chromedriver ", 
83+         url = "{ url }  
84+         sha256 = "{ sha }  
9885        strip_prefix = "chromedriver-mac-x64", 
9986        build_file_content = \" \" \"  
10087load("@aspect_rules_js//js:defs.bzl", "js_library") 
@@ -109,23 +96,22 @@ def chromedriver(selected_version):
10996\" \" \" ,
11097    ) 
11198""" 
112-         %  (mac , sha )
113-     )
11499
115100    return  content 
116101
117102
118- def  chrome (selected_version ):
103+ def  chrome (selected_version , workspace_prefix = "" ):
104+     content  =  "" 
119105    chrome_downloads  =  selected_version ["downloads" ]["chrome" ]
120106
121-     linux  =  [d ["url" ] for  d  in  chrome_downloads  if  d ["platform" ] ==  "linux64" ][0 ]
122-     sha  =  calculate_hash (linux )
107+     url  =  [d ["url" ] for  d  in  chrome_downloads  if  d ["platform" ] ==  "linux64" ][0 ]
108+     sha  =  calculate_hash (url )
123109
124-     content  =   """ 
110+     content  +=   f """
125111    http_archive( 
126-         name = "linux_chrome ", 
127-         url = "%s ", 
128-         sha256 = "%s ", 
112+         name = "linux_ { workspace_prefix } chrome ", 
113+         url = "{ url }  
114+         sha256 = "{ sha }  
129115        build_file_content = \" \" \"  
130116load("@aspect_rules_js//js:defs.bzl", "js_library") 
131117package(default_visibility = ["//visibility:public"]) 
@@ -143,19 +129,15 @@ def chrome(selected_version):
143129) 
144130\" \" \" ,
145131    ) 
132+ """ 
146133
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 )
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 
154136
155-     content  +=  """    http_archive( 
156-         name = "mac_chrome ", 
157-         url = "%s ", 
158-         sha256 = "%s ", 
137+     content  +=  f """    http_archive(
138+         name = "mac_ { workspace_prefix } chrome ", 
139+         url = "{ url }  
140+         sha256 = "{ sha }  
159141        strip_prefix = "chrome-mac-x64", 
160142        patch_cmds = [ 
161143            "mv 'Google Chrome for Testing.app' Chrome.app", 
@@ -173,11 +155,7 @@ def chrome(selected_version):
173155) 
174156\" \" \" ,
175157    ) 
176- 
177- """  %  (
178-         mac ,
179-         sha ,
180-     )
158+ """ 
181159
182160    return  content 
183161
@@ -522,9 +500,17 @@ def pin_browsers():
522500    content  =  content  +  geckodriver ()
523501    content  =  content  +  edge ()
524502    content  =  content  +  edgedriver ()
525-     chrome_milestone  =  get_chrome_milestone ()
526-     content  =  content  +  chrome (chrome_milestone )
527-     content  =  content  +  chromedriver (chrome_milestone )
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+ 
528514    content  +=  """ 
529515def _pin_browsers_extension_impl(_ctx): 
530516    pin_browsers() 
0 commit comments