| """Step class for uploading fuchsia-specific CIPD artifacts.""" |
| |
| from __future__ import absolute_import |
| import os |
| |
| from slave import base_step |
| from slave.step import cipd_upload_step |
| |
| class FuchsiaCIPDUploadStep(base_step.BaseStep): |
| """Generates all required CIPDUploadSteps for a fuchsia build.""" |
| |
| def __init__(self, recipe_steps, file_name, yaml_dir, refs=None, tags=None, |
| pkg_vars=None, **kwargs): |
| super().__init__(name='fuchsia_cipd_upload', **kwargs) |
| self.recipe_steps = recipe_steps |
| self.file_name = file_name |
| self.yaml_dir = yaml_dir |
| |
| # Assert that required CIPD kwargs have been passed in. These |
| # will be forworded to CIPDUploadStep. |
| assert refs is not None |
| assert tags is not None |
| assert pkg_vars is not None |
| self.cipd_kwargs = ( |
| kwargs | { 'refs': refs, 'tags': tags, 'pkg_vars': pkg_vars } |
| ) |
| |
| def run(self): |
| # Assume that there is only one instance of this step in |
| # |self._recipe_steps|. |
| current_step_index = next( |
| (i for i, step in enumerate(self.recipe_steps) |
| if isinstance(step, FuchsiaCIPDUploadStep)), -1) |
| if current_step_index == -1: |
| raise RuntimeError( |
| 'Could not find FuchsiaCIPDUploadStep class in recipe') |
| |
| contents = [] |
| with open(self.file_name) as f: |
| contents = f.readlines() |
| |
| # The file locations stored in CIPD_UPLOADS_FILE_NAME are relative |
| # to chromium root and prefixed with "//". We strip the "//" prefix |
| # so that the remaining relative path can be easily joined. |
| for artifact in [line.strip().lstrip('/') for line in contents]: |
| artifact_yaml = os.path.basename(artifact) |
| cipd_far_def = os.path.join(self.yaml_dir, artifact) |
| step = cipd_upload_step.CIPDUploadStep( |
| cipd_far_def, |
| step_name='Upload .far CIPD Package: ' + artifact_yaml + '.', |
| verification_timeout='10m0s', |
| **self.cipd_kwargs) |
| # Add the step after the current step, FuchsiaCIPDUploadStep. |
| self.recipe_steps.insert(current_step_index + 1, step) |
| return True |