Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mitigate rate limit issues #16

Merged
merged 3 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions src/versions.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"crazyflie-release-version": "2024.10.1",
"crazyflie-firmware-version": "2024.10.1",
"crazyflie-release-version": "2024.10.2",
"crazyflie-firmware-version": "2024.10.2",
"crazyflie2-nrf-firmware-version": "2024.10",
"lighthouse-fpga-version": "V6",
"aideck-esp-firmware-version": "2023.06",
Expand Down
34 changes: 22 additions & 12 deletions tools/build/package
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,22 @@ def _read_manifest(path, platform, versions):
return data


def _add_token(request: urllib.request.Request) -> urllib.request.Request:
if 'GITHUB_TOKEN' in os.environ:
GITHUB_TOKEN = os.environ['GITHUB_TOKEN']
request.add_unredirected_header(key="Authorization", val=f"Bearer {GITHUB_TOKEN}")
else:
print('Calling REST API without authorization.'
'This is not recommended, please set the GITHUB_TOKEN environment variable')
return request


def _download_artifact(uri) -> io.BytesIO:
# Add auth headers if the github token is available, on the build servers it is, but when running locally it is not.
# Some operations do not require authentication but we do it anyway to avoid API call rate problems
request = urllib.request.Request(url=uri)
request.add_unredirected_header(key="Accept", val="application/vnd.github+json")
if 'GITHUB_TOKEN' in os.environ:
GITHUB_TOKEN = os.environ['GITHUB_TOKEN']
request.add_unredirected_header(key="Authorization", val=f"Bearer {GITHUB_TOKEN}")
print(' Downloading with authorization')
else:
print(' Downloading without authorization')
request = _add_token(request)
with urllib.request.urlopen(request) as response:
data = response.read()
assert (data)
Expand All @@ -71,16 +76,21 @@ def _download_latest(path, repository: str, branch: str, fw_platform: str) -> st
does not have platforms, for instance deck firmware.
"""

run_url = f'https://api.github.com/repos/bitcraze/{repository}/actions/runs?branch={branch};pages=1'
_run_info, _ = urllib.request.urlretrieve(run_url)
run_info = json.load(open(_run_info, 'r'))
run_url = f'https://api.github.com/repos/bitcraze/{repository}/actions/runs?branch={branch}&per_page=1'
request = urllib.request.Request(url=run_url)
request.add_unredirected_header(key="Accept", val="application/vnd.github+json")
request = _add_token(request)
with urllib.request.urlopen(request) as response:
run_info = json.load(response)
if len(run_info['workflow_runs']) == 0:
raise Exception(f'No builds found for branch {branch} in {repository}')

artifacts_url = run_info['workflow_runs'][0]['artifacts_url']

_artifacts, _ = urllib.request.urlretrieve(artifacts_url)
artifacts = json.load(open(_artifacts, 'r'))
request = urllib.request.Request(url=artifacts_url)
request.add_unredirected_header(key="Accept", val="application/vnd.github+json")
request = _add_token(request)
with urllib.request.urlopen(request) as response:
artifacts = json.load(response)

# Repos with platforms names artifacts: tag-21k1j2h3k1j2h3k1j2h3LongHash
# Repos without platforms just uses: 9s9asd9as9das9da9sdLongHash
Expand Down
Loading