Skip to content
46 changes: 26 additions & 20 deletions scripts/pinned_browsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,32 @@ def calculate_hash(url):
print(f"Calculate hash for {url}", file=sys.stderr)
h = hashlib.sha256()
r = http.request("GET", url, preload_content=False)
for b in iter(lambda: r.read(4096), b""):
h.update(b)
try:
if r.status != 200:
raise ValueError(f"Download unavailable (HTTP {r.status}): {url}")
for b in iter(lambda: r.read(4096), b""):
h.update(b)
finally:
r.release_conn()
return h.hexdigest()
Comment thread
qodo-code-review[bot] marked this conversation as resolved.
Comment thread
titusfortner marked this conversation as resolved.
Comment thread
titusfortner marked this conversation as resolved.


def get_chrome_info_for_channel(channel):
r = http.request(
"GET",
f"https://chromiumdash.appspot.com/fetch_releases?channel={channel}&num=1&platform=Mac,Linux",
)
all_versions = json.loads(r.data)
# use the same milestone for all chrome releases, so pick the lowest
milestones = [version["milestone"] for version in all_versions if version["milestone"]]
if not milestones:
raise ValueError(f"No Chrome versions with milestones found for channel '{channel}'")
milestone = min(milestones)
r = http.request(
"GET",
"https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json",
)
versions = json.loads(r.data)["versions"]
def latest_for_channel(channel):
"""Newest Chrome-for-Testing version entry (version + downloads) for a channel.

Uses Chrome-for-Testing's channel designation, which tracks the latest milestone and is
unaffected by N-1 security respins.
"""
url = "https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions.json"
r = http.request("GET", url)
if r.status != 200:
raise ValueError(f"Fetch failed (HTTP {r.status}): {url}")
milestone = json.loads(r.data)["channels"][channel]["version"].split(".")[0]
url = "https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json"
r = http.request("GET", url)
if r.status != 200:
raise ValueError(f"Fetch failed (HTTP {r.status}): {url}")
versions = json.loads(r.data)["versions"]
return sorted(
filter(lambda v: v["version"].split(".")[0] == str(milestone), versions),
key=lambda v: parse(v["version"]),
Expand All @@ -51,6 +55,8 @@ def get_chrome_info_for_channel(channel):
def chromedriver(selected_version, workspace_prefix=""):
content = ""

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

url = next((d["url"] for d in drivers if d["platform"] == "linux64"), None)
Expand Down Expand Up @@ -551,12 +557,12 @@ def pin_browsers():
content = content + edge_and_edgedriver()

# Stable Chrome
stable_chrome_info = get_chrome_info_for_channel(channel="Stable")
stable_chrome_info = latest_for_channel("Stable")
content = content + chrome(stable_chrome_info, workspace_prefix="")
content = content + chromedriver(stable_chrome_info, workspace_prefix="")

# Beta Chrome
beta_chrome_info = get_chrome_info_for_channel(channel="Beta")
beta_chrome_info = latest_for_channel("Beta")
content = content + chrome(beta_chrome_info, workspace_prefix="beta_")
content = content + chromedriver(beta_chrome_info, workspace_prefix="beta_")

Expand Down
52 changes: 27 additions & 25 deletions scripts/update_cdp.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,22 @@
root_dir = Path(os.path.realpath(__file__)).parent.parent


def get_chrome_milestone():
"""Get the Chrome milestone from the channel.
def latest_for_channel(channel):
"""Newest Chrome-for-Testing version entry for a channel.

This is the same method from pinned_browser. Use --chrome_channel=Beta if
using early stable release.
Uses Chrome-for-Testing's channel designation, which tracks the latest milestone and is
unaffected by N-1 security respins.
"""
Comment thread
titusfortner marked this conversation as resolved.
Outdated
parser = argparse.ArgumentParser()
parser.add_argument("--chrome_channel", default="Stable", help="Set the Chrome channel")
args = parser.parse_args()
channel = args.chrome_channel

r = http.request(
"GET",
f"https://chromiumdash.appspot.com/fetch_releases?channel={channel}&num=1&platform=Mac,Linux",
)
all_versions = json.loads(r.data)
# use the same milestone for all Chrome releases, so pick the lowest
milestones = [version["milestone"] for version in all_versions if version["milestone"]]
if not milestones:
raise ValueError(f"No Chrome versions with milestones found for channel '{channel}'")
milestone = min(milestones)
r = http.request(
"GET",
"https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json",
)
url = "https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions.json"
r = http.request("GET", url)
if r.status != 200:
raise ValueError(f"Fetch failed (HTTP {r.status}): {url}")
milestone = json.loads(r.data)["channels"][channel]["version"].split(".")[0]
url = "https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json"
r = http.request("GET", url)
if r.status != 200:
raise ValueError(f"Fetch failed (HTTP {r.status}): {url}")
versions = json.loads(r.data)["versions"]

return sorted(
filter(lambda v: v["version"].split(".")[0] == str(milestone), versions),
key=lambda v: parse(v["version"]),
Expand All @@ -49,6 +38,8 @@ def get_chrome_milestone():

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

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


if __name__ == "__main__":
chrome_milestone = get_chrome_milestone()
parser = argparse.ArgumentParser()
parser.add_argument(
"--chrome_channel",
default="Stable",
choices=["Stable", "Beta", "Dev", "Canary"],
help="Set the Chrome channel (use Beta for early stable)",
)
Comment thread
titusfortner marked this conversation as resolved.
Outdated
args = parser.parse_args()

chrome_milestone = latest_for_channel(args.chrome_channel)
Comment thread
titusfortner marked this conversation as resolved.
Outdated
add_pdls(chrome_milestone)
update_java(chrome_milestone)
update_dotnet(chrome_milestone)
Expand Down
Loading