Skip to content

Commit 5bb4129

Browse files
committed
Add download of beta_chrome on pinned browsers
1 parent 3ecda45 commit 5bb4129

File tree

2 files changed

+168
-76
lines changed

2 files changed

+168
-76
lines changed

common/repositories.bzl

Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,6 @@ js_library(
218218
)
219219
""",
220220
)
221-
222221
http_archive(
223222
name = "mac_chrome",
224223
url = "https://storage.googleapis.com/chrome-for-testing-public/136.0.7103.49/mac-x64/chrome-mac-x64.zip",
@@ -240,7 +239,6 @@ js_library(
240239
)
241240
""",
242241
)
243-
244242
http_archive(
245243
name = "linux_chromedriver",
246244
url = "https://storage.googleapis.com/chrome-for-testing-public/136.0.7103.49/linux64/chromedriver-linux64.zip",
@@ -270,6 +268,84 @@ package(default_visibility = ["//visibility:public"])
270268
271269
exports_files(["chromedriver"])
272270
271+
js_library(
272+
name = "chromedriver-js",
273+
data = ["chromedriver"],
274+
)
275+
""",
276+
)
277+
278+
http_archive(
279+
name = "linux_beta_chrome",
280+
url = "https://storage.googleapis.com/chrome-for-testing-public/137.0.7151.6/linux64/chrome-linux64.zip",
281+
sha256 = "1c304daed9edf8d4b5b57645e6cccf227bcc7664595b369879f89ca34d2509ac",
282+
build_file_content = """
283+
load("@aspect_rules_js//js:defs.bzl", "js_library")
284+
package(default_visibility = ["//visibility:public"])
285+
286+
filegroup(
287+
name = "files",
288+
srcs = glob(["**/*"]),
289+
)
290+
291+
exports_files(["chrome-linux64/chrome"])
292+
293+
js_library(
294+
name = "chrome-js",
295+
data = [":files"],
296+
)
297+
""",
298+
)
299+
http_archive(
300+
name = "mac_beta_chrome",
301+
url = "https://storage.googleapis.com/chrome-for-testing-public/137.0.7151.6/mac-x64/chrome-mac-x64.zip",
302+
sha256 = "c6f3a04ea911682abcce470310433efb75ef4063ba9f02df0a22df89344947cb",
303+
strip_prefix = "chrome-mac-x64",
304+
patch_cmds = [
305+
"mv 'Google Chrome for Testing.app' Chrome.app",
306+
"mv 'Chrome.app/Contents/MacOS/Google Chrome for Testing' Chrome.app/Contents/MacOS/Chrome",
307+
],
308+
build_file_content = """
309+
load("@aspect_rules_js//js:defs.bzl", "js_library")
310+
package(default_visibility = ["//visibility:public"])
311+
312+
exports_files(["Chrome.app"])
313+
314+
js_library(
315+
name = "chrome-js",
316+
data = glob(["Chrome.app/**/*"]),
317+
)
318+
""",
319+
)
320+
http_archive(
321+
name = "linux_beta_chromedriver",
322+
url = "https://storage.googleapis.com/chrome-for-testing-public/137.0.7151.6/linux64/chromedriver-linux64.zip",
323+
sha256 = "0d5ba6533e60b44b39f41b4313696b41bb7b466f29aa00cb82df030392559854",
324+
strip_prefix = "chromedriver-linux64",
325+
build_file_content = """
326+
load("@aspect_rules_js//js:defs.bzl", "js_library")
327+
package(default_visibility = ["//visibility:public"])
328+
329+
exports_files(["chromedriver"])
330+
331+
js_library(
332+
name = "chromedriver-js",
333+
data = ["chromedriver"],
334+
)
335+
""",
336+
)
337+
338+
http_archive(
339+
name = "mac_beta_chromedriver",
340+
url = "https://storage.googleapis.com/chrome-for-testing-public/137.0.7151.6/mac-x64/chromedriver-mac-x64.zip",
341+
sha256 = "d01e48e534b48ab1f6401642720eec95773b069ad8a3042969d1fd708a4fb6c2",
342+
strip_prefix = "chromedriver-mac-x64",
343+
build_file_content = """
344+
load("@aspect_rules_js//js:defs.bzl", "js_library")
345+
package(default_visibility = ["//visibility:public"])
346+
347+
exports_files(["chromedriver"])
348+
273349
js_library(
274350
name = "chromedriver-js",
275351
data = ["chromedriver"],

scripts/pinned_browsers.py

Lines changed: 90 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -26,99 +26,115 @@ def calculate_hash(url):
2626
return h.hexdigest()
2727

2828

29-
def get_chrome_milestone():
30-
parser = argparse.ArgumentParser()
31-
parser.add_argument('--chrome_channel', default='Stable', help='Set the Chrome channel')
32-
args = parser.parse_args()
33-
channel = args.chrome_channel
34-
35-
r = http.request(
36-
"GET", f"https://chromiumdash.appspot.com/fetch_releases?channel={channel}&num=1&platform=Mac,Linux"
37-
)
38-
all_versions = json.loads(r.data)
39-
# use the same milestone for all chrome releases, so pick the lowest
40-
milestone = min([version["milestone"] for version in all_versions if version["milestone"]])
41-
r = http.request(
42-
"GET", "https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json"
43-
)
44-
versions = json.loads(r.data)["versions"]
29+
#!/usr/bin/env python
30+
31+
import argparse
32+
import hashlib
33+
import json
34+
import os
35+
import sys
36+
from pathlib import Path
37+
38+
import urllib3
39+
from packaging.version import parse
40+
41+
http = urllib3.PoolManager()
4542

46-
return sorted(
47-
filter(lambda v: v["version"].split(".")[0] == str(milestone), versions), key=lambda v: parse(v["version"])
48-
)[-1]
43+
44+
def calculate_hash(url):
45+
print("Calculate hash for %s" % url, file=sys.stderr)
46+
h = hashlib.sha256()
47+
r = http.request("GET", url, preload_content=False)
48+
for b in iter(lambda: r.read(4096), b""):
49+
h.update(b)
50+
return h.hexdigest()
4951

5052

51-
def chromedriver(selected_version):
53+
def get_chrome_versions():
54+
channels = ['Stable', 'Beta']
55+
versions = {}
56+
for channel in channels:
57+
r = http.request(
58+
"GET", f"https://chromiumdash.appspot.com/fetch_releases?channel={channel}&num=1&platform=Mac,Linux"
59+
)
60+
all_versions = json.loads(r.data)
61+
milestone = min([version["milestone"] for version in all_versions if version["milestone"]])
62+
r = http.request(
63+
"GET", "https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json"
64+
)
65+
all_known_versions = json.loads(r.data)["versions"]
66+
selected_version = sorted(
67+
filter(lambda v: v["version"].split(".")[0] == str(milestone), all_known_versions),
68+
key=lambda v: parse(v["version"])
69+
)[-1]
70+
versions[channel] = selected_version
71+
return versions
72+
73+
74+
def chromedriver(selected_version, workspace_name=""):
5275
content = ""
5376

5477
drivers = selected_version["downloads"]["chromedriver"]
5578

5679
linux = [d["url"] for d in drivers if d["platform"] == "linux64"][0]
5780
sha = calculate_hash(linux)
5881

59-
content = (
60-
content
61-
+ """ http_archive(
62-
name = "linux_chromedriver",
63-
url = "%s",
64-
sha256 = "%s",
65-
strip_prefix = "chromedriver-linux64",
82+
content += f""" http_archive(
83+
name = \"linux_{workspace_name}chromedriver\",
84+
url = \"{linux}\",
85+
sha256 = \"{sha}\",
86+
strip_prefix = \"chromedriver-linux64\",
6687
build_file_content = \"\"\"
67-
load("@aspect_rules_js//js:defs.bzl", "js_library")
68-
package(default_visibility = ["//visibility:public"])
88+
load(\"@aspect_rules_js//js:defs.bzl\", \"js_library\")
89+
package(default_visibility = [\"//visibility:public\"])
6990
70-
exports_files(["chromedriver"])
91+
exports_files([\"chromedriver\"])
7192
7293
js_library(
73-
name = "chromedriver-js",
74-
data = ["chromedriver"],
94+
name = \"chromedriver-js\",
95+
data = [\"chromedriver\"],
7596
)
7697
\"\"\",
7798
)
7899
"""
79-
% (linux, sha)
80-
)
81100

82101
mac = [d["url"] for d in drivers if d["platform"] == "mac-x64"][0]
83102
sha = calculate_hash(mac)
84-
content = (
85-
content
86-
+ """
103+
content += f"""
87104
http_archive(
88-
name = "mac_chromedriver",
89-
url = "%s",
90-
sha256 = "%s",
91-
strip_prefix = "chromedriver-mac-x64",
105+
name = \"mac_{workspace_name}chromedriver\",
106+
url = \"{mac}\",
107+
sha256 = \"{sha}\",
108+
strip_prefix = \"chromedriver-mac-x64\",
92109
build_file_content = \"\"\"
93-
load("@aspect_rules_js//js:defs.bzl", "js_library")
94-
package(default_visibility = ["//visibility:public"])
110+
load(\"@aspect_rules_js//js:defs.bzl\", \"js_library\")
111+
package(default_visibility = [\"//visibility:public\"])
95112
96-
exports_files(["chromedriver"])
113+
exports_files([\"chromedriver\"])
97114
98115
js_library(
99-
name = "chromedriver-js",
100-
data = ["chromedriver"],
116+
name = \"chromedriver-js\",
117+
data = [\"chromedriver\"],
101118
)
102119
\"\"\",
103120
)
104121
"""
105-
% (mac, sha)
106-
)
107122

108123
return content
109124

125+
def chrome(selected_version, workspace_name=""):
126+
print(f"Calculating hash for Chrome ({workspace_name or 'stable'}) version {selected_version['version']}", file=sys.stderr)
110127

111-
def chrome(selected_version):
112128
chrome_downloads = selected_version["downloads"]["chrome"]
113129

114130
linux = [d["url"] for d in chrome_downloads if d["platform"] == "linux64"][0]
115131
sha = calculate_hash(linux)
116132

117-
content = """
133+
content = f"""
118134
http_archive(
119-
name = "linux_chrome",
120-
url = "%s",
121-
sha256 = "%s",
135+
name = "linux_{workspace_name}chrome",
136+
url = "{linux}",
137+
sha256 = "{sha}",
122138
build_file_content = \"\"\"
123139
load("@aspect_rules_js//js:defs.bzl", "js_library")
124140
package(default_visibility = ["//visibility:public"])
@@ -136,19 +152,15 @@ def chrome(selected_version):
136152
)
137153
\"\"\",
138154
)
139-
140-
""" % (
141-
linux,
142-
sha,
143-
)
155+
"""
144156

145157
mac = [d["url"] for d in chrome_downloads if d["platform"] == "mac-x64"][0]
146158
sha = calculate_hash(mac)
147159

148-
content += """ http_archive(
149-
name = "mac_chrome",
150-
url = "%s",
151-
sha256 = "%s",
160+
content += f""" http_archive(
161+
name = "mac_{workspace_name}chrome",
162+
url = "{mac}",
163+
sha256 = "{sha}",
152164
strip_prefix = "chrome-mac-x64",
153165
patch_cmds = [
154166
"mv 'Google Chrome for Testing.app' Chrome.app",
@@ -166,11 +178,7 @@ def chrome(selected_version):
166178
)
167179
\"\"\",
168180
)
169-
170-
""" % (
171-
mac,
172-
sha,
173-
)
181+
"""
174182

175183
return content
176184

@@ -496,13 +504,21 @@ def pin_browsers():
496504
local_drivers(name = "local_drivers")
497505
498506
"""
499-
content = content + firefox()
500-
content = content + geckodriver()
501-
content = content + edge()
502-
content = content + edgedriver()
503-
chrome_milestone = get_chrome_milestone()
504-
content = content + chrome(chrome_milestone)
505-
content = content + chromedriver(chrome_milestone)
507+
content += firefox()
508+
content += geckodriver()
509+
content += edge()
510+
content += edgedriver()
511+
512+
chrome_versions = get_chrome_versions()
513+
chrome_stable = chrome_versions['Stable']
514+
content += chrome(chrome_stable)
515+
content += chromedriver(chrome_stable)
516+
517+
chrome_beta = chrome_versions['Beta']
518+
if chrome_stable["version"] != chrome_beta["version"]:
519+
content += chrome(chrome_beta, workspace_name="beta_")
520+
content += chromedriver(chrome_beta, workspace_name="beta_")
521+
506522
content += """
507523
def _pin_browsers_extension_impl(_ctx):
508524
pin_browsers()

0 commit comments

Comments
 (0)