1010import urllib3
1111from packaging .version import parse
1212
13+ # Find the current stable versions of each browser we
14+ # support and the sha256 of these. That's useful for
15+ # updating `//common:repositories.bzl`
16+
1317http = urllib3 .PoolManager ()
1418
1519
@@ -32,19 +36,23 @@ def get_chrome_milestone(channel=None):
3236 "GET" , f"https://chromiumdash.appspot.com/fetch_releases?channel={ channel } &num=1&platform=Mac,Linux"
3337 )
3438 all_versions = json .loads (r .data )
39+ # use the same milestone for all chrome releases, so pick the lowest
3540 milestone = min ([version ["milestone" ] for version in all_versions if version ["milestone" ]])
3641 r = http .request (
3742 "GET" , "https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json"
3843 )
3944 versions = json .loads (r .data )["versions" ]
45+
4046 return sorted (
4147 filter (lambda v : v ["version" ].split ("." )[0 ] == str (milestone ), versions ), key = lambda v : parse (v ["version" ])
4248 )[- 1 ]
4349
4450
4551def chromedriver (selected_version , workspace_prefix = "" ):
4652 content = ""
53+
4754 drivers = selected_version ["downloads" ]["chromedriver" ]
55+
4856 linux = [d ["url" ] for d in drivers if d ["platform" ] == "linux64" ][0 ]
4957 sha = calculate_hash (linux )
5058 content = content + """ http_archive(
@@ -91,8 +99,10 @@ def chromedriver(selected_version, workspace_prefix=""):
9199
92100def chrome (selected_version , workspace_prefix = "" ):
93101 chrome_downloads = selected_version ["downloads" ]["chrome" ]
102+
94103 linux = [d ["url" ] for d in chrome_downloads if d ["platform" ] == "linux64" ][0 ]
95104 sha = calculate_hash (linux )
105+
96106 content = """
97107 http_archive(
98108 name = "linux_%schrome",
@@ -163,11 +173,13 @@ def edge():
163173 content = ""
164174 r = http .request ("GET" , "https://edgeupdates.microsoft.com/api/products" )
165175 all_data = case_insensitive_json_loads (r .data )
176+
166177 linux = None
167178 linux_hash = None
168179 mac = None
169180 mac_hash = None
170181 version = None
182+
171183 for data in all_data :
172184 if not "Stable" == data .get ("product" ):
173185 continue
@@ -183,6 +195,7 @@ def edge():
183195 if "deb" == artifact ["artifactname" ]:
184196 linux = artifact ["location" ]
185197 linux_hash = artifact ["hash" ]
198+
186199 if mac and mac_hash :
187200 content += """
188201 pkg_archive(
@@ -238,7 +251,9 @@ def edgedriver():
238251 major_version = stable_version .split ('.' )[0 ]
239252 r = http .request ("GET" , f"https://msedgedriver.azureedge.net/LATEST_RELEASE_{ major_version } _LINUX" )
240253 linux_version = r .data .decode ("utf-16" ).strip ()
254+
241255 content = ""
256+
242257 linux = "https://msedgedriver.azureedge.net/%s/edgedriver_linux64.zip" % linux_version
243258 sha = calculate_hash (linux )
244259 content = content + """
@@ -286,6 +301,7 @@ def edgedriver():
286301
287302def geckodriver ():
288303 content = ""
304+
289305 r = http .request ("GET" , "https://api.github.com/repos/mozilla/geckodriver/releases/latest" )
290306 for a in json .loads (r .data )["assets" ]:
291307 if a ["name" ].endswith ("-linux64.tar.gz" ):
@@ -334,10 +350,12 @@ def geckodriver():
334350
335351def firefox ():
336352 firefox_versions = json .loads (firefox_version_data ())
353+
337354 latest_firefox = firefox_versions ["LATEST_FIREFOX_VERSION" ]
338355 sha_linux = calculate_hash (firefox_linux (latest_firefox ))
339356 sha_mac = calculate_hash (firefox_mac (latest_firefox ))
340357 content = print_firefox (latest_firefox , "" , sha_linux , sha_mac )
358+
341359 beta_firefox = firefox_versions ["LATEST_FIREFOX_RELEASED_DEVEL_VERSION" ]
342360 if latest_firefox != beta_firefox :
343361 sha_linux = calculate_hash (firefox_linux (beta_firefox ))
0 commit comments