| # Copyright 2019 The Fuchsia Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can |
| # found in the LICENSE file. |
| |
| from recipe_engine import recipe_api |
| |
| |
| class ArtifactsApi(recipe_api.RecipeApi): |
| """API for interacting with build and test artifacts""" |
| |
| def __init__(self, *args, **kwargs): |
| super(ArtifactsApi, self).__init__(*args, **kwargs) |
| # A GCS bucket (str) to which a package repository may be uploaded. |
| self.gcs_bucket = None |
| # A unique identifier (str) giving a namespace in the GCS bucket under |
| # which a package repository may be uploaded. |
| self.uuid = None |
| |
| def package_repo_url(self, host=None): |
| """Returns the URL (str) of an uploaded package repository. |
| |
| This assumes that we have already upload()ed to this bucket. |
| |
| Args: |
| host (str|None): The hosting address of the package repository; if |
| unprovided, the default GCS URL will be constructed. |
| """ |
| assert self.gcs_bucket and self.uuid |
| path = '%s/%s/repository' % (self.gcs_bucket, self.uuid) |
| if host: |
| return 'http://%s/%s' % (host, path) |
| return 'gs://%s' % path |
| |
| def package_blob_url(self, host=None): |
| """Returns the URL (str) of the blobs of an uploaded package repository. |
| |
| Args: |
| host (str|None): The hosting address of the package repository; if |
| unprovided, the default GCS URL will be constructed. |
| """ |
| assert self.gcs_bucket |
| path = '%s/blobs' % self.gcs_bucket |
| if host: |
| return 'http://%s/%s' % (host, path) |
| return 'gs://%s' % path |
| |
| def upload(self, step_name, build): |
| """Uploads built and assembled artifacts. |
| |
| This includes package metadata, blobs and keys. |
| TODO(fxbug.dev/37264): This will eventually include most other uploads |
| (e.g., debug binaries). |
| |
| Args: |
| step_name (str): The name of the step. |
| build (api.build.FuchsiaBuildResults): the results of a build. |
| """ |
| assert self.gcs_bucket and self.uuid |
| self.m.step( |
| step_name, [ |
| build.tool('artifactory'), |
| 'up', |
| '-bucket', self.gcs_bucket, |
| '-uuid', self.uuid, |
| build.fuchsia_build_dir, |
| ], |
| infra_step=True |
| ) # yapf: disable |