Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
ci: start Xvfb for browser tests; fonts: add retries/timeouts for dow…
…nload_google_fonts.py
  • Loading branch information
Harry-GNS committed Sep 26, 2025
commit ed2deda536cc66c0349c799dc70f25f02dc82f86
8 changes: 8 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ jobs:
working_directory: ~/plotly.js
steps:
- run: sudo apt-get update
- browser-tools/start-xvfb
- browser-tools/install-browser-tools:
install-firefox: false
install-geckodriver: false
Expand Down Expand Up @@ -79,6 +80,7 @@ jobs:
working_directory: ~/plotly.js
steps:
- run: sudo apt-get update
- browser-tools/start-xvfb
- browser-tools/install-browser-tools:
install-firefox: false
install-geckodriver: false
Expand All @@ -101,6 +103,7 @@ jobs:
working_directory: ~/plotly.js
steps:
- run: sudo apt-get update
- browser-tools/start-xvfb
- browser-tools/install-browser-tools:
install-firefox: false
install-geckodriver: false
Expand All @@ -123,6 +126,7 @@ jobs:
working_directory: ~/plotly.js
steps:
- run: sudo apt-get update
- browser-tools/start-xvfb
- browser-tools/install-browser-tools:
install-firefox: false
install-geckodriver: false
Expand All @@ -144,6 +148,7 @@ jobs:
parallelism: 8
working_directory: ~/plotly.js
steps:
- browser-tools/start-xvfb
- browser-tools/install-browser-tools: &browser-versions
install-firefox: false
install-geckodriver: false
Expand All @@ -164,6 +169,7 @@ jobs:
working_directory: ~/plotly.js
steps:
- run: sudo apt-get update
- browser-tools/start-xvfb
- browser-tools/install-browser-tools:
install-firefox: false
install-geckodriver: false
Expand All @@ -185,6 +191,7 @@ jobs:
working_directory: ~/plotly.js
steps:
- run: sudo apt-get update
- browser-tools/start-xvfb
- browser-tools/install-browser-tools:
install-firefox: false
install-geckodriver: false
Expand All @@ -205,6 +212,7 @@ jobs:
TZ: "America/Anchorage"
working_directory: ~/plotly.js
steps:
- browser-tools/start-xvfb
- browser-tools/install-browser-tools:
install-chrome: false
install-chromedriver: false
Expand Down
59 changes: 46 additions & 13 deletions .circleci/download_google_fonts.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import os
import time

import requests

dir_out = ".circleci/fonts/truetype/googleFonts/"


def download(repo, family, types, overwrite=True):
def download(repo, family, types, overwrite=True, retries=4, timeout=20):
session = requests.Session()
for t in types:
name = family + t + ".ttf"
url = repo + name + "?raw=true"
Expand All @@ -14,18 +16,49 @@ def download(repo, family, types, overwrite=True):
if os.path.exists(out_file) and not overwrite:
print(" => Already exists: ", out_file)
continue
req = requests.get(url, allow_redirects=False)
if req.status_code != 200:
# If we get a redirect, print an error so that we know to update the URL
if req.status_code == 302 or req.status_code == 301:
new_url = req.headers.get("Location")
print(f" => Redirected -- please update URL to: {new_url}")
raise RuntimeError(f"""
Download failed.
Status code: {req.status_code}
Message: {req.reason}
""")
open(out_file, "wb").write(req.content)

attempt = 0
backoff = 2
last_err = None
# follow up to 2 redirects manually to keep logs readable
max_redirects = 2
while attempt <= retries:
try:
cur_url = url
redirects = 0
while True:
req = session.get(cur_url, allow_redirects=False, timeout=timeout)
if req.status_code in (301, 302) and redirects < max_redirects:
new_url = req.headers.get("Location")
print(f" => Redirected to: {new_url}")
cur_url = new_url
redirects += 1
continue
break

if req.status_code == 200:
os.makedirs(os.path.dirname(out_file), exist_ok=True)
with open(out_file, "wb") as f:
f.write(req.content)
print(" => Saved:", out_file)
last_err = None
break
else:
print(f" => HTTP {req.status_code}: {req.reason}")
last_err = RuntimeError(f"HTTP {req.status_code}: {req.reason}")
except requests.exceptions.RequestException as e:
last_err = e
print(f" => Network error: {e}")

attempt += 1
if attempt <= retries:
print(f" => Retrying in {backoff}s (attempt {attempt}/{retries})...")
time.sleep(backoff)
backoff *= 2

if last_err is not None:
# Don't hard-fail the entire job; log and move on.
print(f" => Giving up on {name}: {last_err}")


download(
Expand Down