Skip to content
Merged
Changes from all commits
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
23 changes: 22 additions & 1 deletion scripts/build_benchmark_dashboard.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env python3

from __future__ import annotations

import argparse
import io
import json
Expand Down Expand Up @@ -39,14 +41,33 @@ def github_request(url: str, token: str | None) -> dict:
return json.load(response)


class NoRedirectHandler(urllib.request.HTTPRedirectHandler):
def redirect_request(self, req, fp, code, msg, headers, newurl):
return None


def download_artifact(url: str, token: str | None) -> bytes:
request = urllib.request.Request(url)
request.add_header("Accept", "application/vnd.github+json")
request.add_header("X-GitHub-Api-Version", "2022-11-28")
if token:
request.add_header("Authorization", f"Bearer {token}")

with urllib.request.urlopen(request) as response:
opener = urllib.request.build_opener(NoRedirectHandler)
try:
with opener.open(request) as response:
return response.read()
except urllib.error.HTTPError as error:
if error.code not in {301, 302, 303, 307, 308}:
raise
redirect_url = error.headers.get("Location")
if not redirect_url:
raise

# GitHub artifact downloads redirect to a signed object-storage URL.
# Sending the GitHub Authorization header there makes the storage request
# fail with 401, so follow the signed URL without GitHub API headers.
with urllib.request.urlopen(redirect_url) as response:
return response.read()


Expand Down
Loading