Skip to content

Commit 0fa35a5

Browse files
committed
[build] Resolve Chrome milestone from Chrome-for-Testing channel version
1 parent 740b692 commit 0fa35a5

2 files changed

Lines changed: 43 additions & 43 deletions

File tree

scripts/pinned_browsers.py

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,29 @@ def calculate_hash(url):
2020
print(f"Calculate hash for {url}", file=sys.stderr)
2121
h = hashlib.sha256()
2222
r = http.request("GET", url, preload_content=False)
23+
if r.status != 200:
24+
raise ValueError(f"Download unavailable (HTTP {r.status}): {url}")
2325
for b in iter(lambda: r.read(4096), b""):
2426
h.update(b)
2527
return h.hexdigest()
2628

2729

28-
def get_chrome_info_for_channel(channel):
29-
r = http.request(
30-
"GET",
31-
f"https://chromiumdash.appspot.com/fetch_releases?channel={channel}&num=1&platform=Mac,Linux",
32-
)
33-
all_versions = json.loads(r.data)
34-
# use the same milestone for all chrome releases, so pick the lowest
35-
milestones = [version["milestone"] for version in all_versions if version["milestone"]]
36-
if not milestones:
37-
raise ValueError(f"No Chrome versions with milestones found for channel '{channel}'")
38-
milestone = min(milestones)
39-
r = http.request(
40-
"GET",
41-
"https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json",
42-
)
43-
versions = json.loads(r.data)["versions"]
30+
def latest_for_channel(channel):
31+
"""Newest Chrome-for-Testing version entry (version + downloads) for a channel.
4432
33+
Uses Chrome-for-Testing's channel designation, which tracks the latest milestone and is
34+
unaffected by N-1 security respins.
35+
"""
36+
url = "https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions.json"
37+
r = http.request("GET", url)
38+
if r.status != 200:
39+
raise ValueError(f"Fetch failed (HTTP {r.status}): {url}")
40+
milestone = json.loads(r.data)["channels"][channel]["version"].split(".")[0]
41+
url = "https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json"
42+
r = http.request("GET", url)
43+
if r.status != 200:
44+
raise ValueError(f"Fetch failed (HTTP {r.status}): {url}")
45+
versions = json.loads(r.data)["versions"]
4546
return sorted(
4647
filter(lambda v: v["version"].split(".")[0] == str(milestone), versions),
4748
key=lambda v: parse(v["version"]),
@@ -51,6 +52,8 @@ def get_chrome_info_for_channel(channel):
5152
def chromedriver(selected_version, workspace_prefix=""):
5253
content = ""
5354

55+
if "chromedriver" not in selected_version["downloads"]:
56+
raise ValueError(f"No chromedriver published for Chrome {selected_version['version']}")
5457
drivers = selected_version["downloads"]["chromedriver"]
5558

5659
url = next((d["url"] for d in drivers if d["platform"] == "linux64"), None)
@@ -551,12 +554,12 @@ def pin_browsers():
551554
content = content + edge_and_edgedriver()
552555

553556
# Stable Chrome
554-
stable_chrome_info = get_chrome_info_for_channel(channel="Stable")
557+
stable_chrome_info = latest_for_channel("Stable")
555558
content = content + chrome(stable_chrome_info, workspace_prefix="")
556559
content = content + chromedriver(stable_chrome_info, workspace_prefix="")
557560

558561
# Beta Chrome
559-
beta_chrome_info = get_chrome_info_for_channel(channel="Beta")
562+
beta_chrome_info = latest_for_channel("Beta")
560563
content = content + chrome(beta_chrome_info, workspace_prefix="beta_")
561564
content = content + chromedriver(beta_chrome_info, workspace_prefix="beta_")
562565

scripts/update_cdp.py

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,22 @@
1414
root_dir = Path(os.path.realpath(__file__)).parent.parent
1515

1616

17-
def get_chrome_milestone():
18-
"""Get the Chrome milestone from the channel.
17+
def latest_for_channel(channel):
18+
"""Newest Chrome-for-Testing version entry for a channel.
1919
20-
This is the same method from pinned_browser. Use --chrome_channel=Beta if
21-
using early stable release.
20+
Uses Chrome-for-Testing's channel designation, which tracks the latest milestone and is
21+
unaffected by N-1 security respins.
2222
"""
23-
parser = argparse.ArgumentParser()
24-
parser.add_argument("--chrome_channel", default="Stable", help="Set the Chrome channel")
25-
args = parser.parse_args()
26-
channel = args.chrome_channel
27-
28-
r = http.request(
29-
"GET",
30-
f"https://chromiumdash.appspot.com/fetch_releases?channel={channel}&num=1&platform=Mac,Linux",
31-
)
32-
all_versions = json.loads(r.data)
33-
# use the same milestone for all Chrome releases, so pick the lowest
34-
milestones = [version["milestone"] for version in all_versions if version["milestone"]]
35-
if not milestones:
36-
raise ValueError(f"No Chrome versions with milestones found for channel '{channel}'")
37-
milestone = min(milestones)
38-
r = http.request(
39-
"GET",
40-
"https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json",
41-
)
23+
url = "https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions.json"
24+
r = http.request("GET", url)
25+
if r.status != 200:
26+
raise ValueError(f"Fetch failed (HTTP {r.status}): {url}")
27+
milestone = json.loads(r.data)["channels"][channel]["version"].split(".")[0]
28+
url = "https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json"
29+
r = http.request("GET", url)
30+
if r.status != 200:
31+
raise ValueError(f"Fetch failed (HTTP {r.status}): {url}")
4232
versions = json.loads(r.data)["versions"]
43-
4433
return sorted(
4534
filter(lambda v: v["version"].split(".")[0] == str(milestone), versions),
4635
key=lambda v: parse(v["version"]),
@@ -49,6 +38,8 @@ def get_chrome_milestone():
4938

5039
def fetch_and_save(url, file_path):
5140
response = http.request("GET", url)
41+
if response.status != 200:
42+
raise ValueError(f"Fetch failed (HTTP {response.status}): {url}")
5243
with open(file_path, "wb") as file:
5344
file.write(response.data)
5445

@@ -79,6 +70,8 @@ def flatten_browser_pdl(file_path, chrome_version):
7970
for domain_file in includes:
8071
url = base_url + domain_file
8172
response = http.request("GET", url)
73+
if response.status != 200:
74+
raise ValueError(f"Fetch failed (HTTP {response.status}): {url}")
8275
concatenated += response.data.decode("utf-8") + "\n"
8376
# Overwrite the file with version block + concatenated domains
8477
with open(file_path, "w") as file:
@@ -213,7 +206,11 @@ def update_js(chrome_milestone):
213206

214207

215208
if __name__ == "__main__":
216-
chrome_milestone = get_chrome_milestone()
209+
parser = argparse.ArgumentParser()
210+
parser.add_argument("--chrome_channel", default="Stable", help="Set the Chrome channel (use Beta for early stable)")
211+
args = parser.parse_args()
212+
213+
chrome_milestone = latest_for_channel(args.chrome_channel)
217214
add_pdls(chrome_milestone)
218215
update_java(chrome_milestone)
219216
update_dotnet(chrome_milestone)

0 commit comments

Comments
 (0)