[cifuzz][github_actions] Create methods/functions for uploading without tar

This can be useful for artifacts we want to upload that we know
do not need to be tarred, such as crashes. It's important not
to tar these because they will need to be viewed by users.
This commit is contained in:
Jonathan Metzman 2021-07-23 08:00:35 -07:00
parent 79b1e10270
commit 781749884b
1 changed files with 29 additions and 11 deletions

View File

@ -65,9 +65,7 @@ class GithubActionsFilestore(filestore.BaseFilestore):
with tempfile.TemporaryDirectory() as temp_dir:
archive_path = os.path.join(temp_dir, name + '.tar')
tar_directory(directory, archive_path)
file_paths = [archive_path]
return artifact_client.upload_artifact(name, file_paths, temp_dir)
_raw_upload_directory(name, directory)
def download_corpus(self, name, dst_directory): # pylint: disable=unused-argument,no-self-use
"""Downloads the corpus located at |name| to |dst_directory|."""
@ -82,16 +80,13 @@ class GithubActionsFilestore(filestore.BaseFilestore):
return artifact
def _download_artifact(self, name, dst_directory):
"""Downloads artifact with |name| to |dst_directory|."""
"""Downloads artifact with |name| to |dst_directory|. Returns True on
success."""
name = self._get_artifact_name(name)
artifact = self._find_artifact(name)
if not artifact:
logging.warning('Could not download artifact: %s.', name)
return artifact
download_url = artifact['archive_download_url']
with tempfile.TemporaryDirectory() as temp_dir:
if not http_utils.download_and_unpack_zip(
download_url, temp_dir, headers=self.github_api_http_headers):
if not self._raw_download_artifact(name, temp_dir):
logging.warning('Could not download artifact: %s.', name)
return False
artifact_tarfile_path = os.path.join(temp_dir, name + '.tar')
@ -105,6 +100,17 @@ class GithubActionsFilestore(filestore.BaseFilestore):
artifact_tarfile.extractall(dst_directory)
return True
def _raw_download_artifact(self, name, dst_directory):
"""Downloads the artifact with |name| to |dst_directory|. Returns True on
success. Does not do any untarring or adding prefix to |name|."""
artifact = self._find_artifact(name)
if not artifact:
logging.warning('Could not find artifact: %s.', name)
return False
download_url = artifact['archive_download_url']
return http_utils.download_and_unpack_zip(
download_url, dst_directory, headers=self.github_api_http_headers)
def _list_artifacts(self):
"""Returns a list of artifacts."""
return github_api.list_artifacts(self.config.project_repo_owner,
@ -118,3 +124,15 @@ class GithubActionsFilestore(filestore.BaseFilestore):
def download_coverage(self, name, dst_directory):
"""Downloads the latest project coverage report."""
return self._download_artifact(name, dst_directory)
def _raw_upload_directory(name, directory):
"""Uploads the artifacts located in |directory| to |name|. Does not do any
tarring or adding prefixes to |name|."""
# Get file paths.
artifact_paths = []
for root, _, curr_file_paths in os.walk(directory):
for file_path in curr_file_paths:
artifact_paths.append(os.path.join(root, file_path))
logging.debug('Artifact paths: %s.', artifact_paths)
return artifact_client.upload_artifact(name, artifact_paths, directory)