Skip to content

Commit

Permalink
Use curl to download github artifacts during bloat report (#32666)
Browse files Browse the repository at this point in the history
* Use CURL to download artifact data. ghapi does not seem to work, however the documented curl way does

* Switch back to github_token

* Restyle

* Remove unused item
  • Loading branch information
andy31415 authored Mar 21, 2024
1 parent 84913af commit 6b82061
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/bloat_check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ jobs:
--github-limit-artifacts 500 \
--github-limit-comments 20 \
--github-repository project-chip/connectedhomeip \
--github-api-token "${{ secrets.BLOAT_REPORT }}"
--github-api-token "${{ secrets.GITHUB_TOKEN }}"
27 changes: 26 additions & 1 deletion scripts/tools/memory/memdf/util/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import itertools
import logging
import os
import subprocess
from typing import Iterable, Mapping, Optional

import dateutil # type: ignore
Expand Down Expand Up @@ -173,7 +174,31 @@ def download_artifact(self, artifact_id: int):
logging.debug('Downloading artifact %d', artifact_id)
try:
assert self.ghapi
return self.ghapi.actions.download_artifact(artifact_id, 'zip')

# It seems like github artifact download is at least partially broken
# (see https://github.com/project-chip/connectedhomeip/issues/32656)
#
# This makes `self.ghapi.actions.download_artifact` not work
#
# Oddly enough downloading via CURL seems ok
owner = self.config['github.owner']
repo = self.config['github.repo']
token = self.config['github.token']

download_url = f"https://api.github.com/repos/{owner}/{repo}/actions/artifacts/{artifact_id}/zip"

# Follow https://docs.github.com/en/rest/actions/artifacts?apiVersion=2022-11-28#download-an-artifact
return subprocess.check_output(
[
'curl',
'-L',
'-H', 'Accept: application/vnd.github+json',
'-H', f'Authorization: Bearer {token}',
'-H', 'X-GitHub-Api-Version: 2022-11-28',
'--output', '-',
download_url
]
)
except Exception as e:
logging.error('Failed to download artifact %d: %s', artifact_id, e)
return None
Expand Down

0 comments on commit 6b82061

Please sign in to comment.