blob: b62fefc200438c87e9c0b6e1330ea7ded169952a [file]
"""Recipe for uploading test source code to CIPD."""
from __future__ import absolute_import
import os
from slave import base_recipe
from slave.step import cipd_upload_step
# _BUILD_CONFIG entries are keyed by build name. Config dicts must include
# 'pkg_project' and 'pkg_def'. If version is supplied and True, then a version
# tag will be added with the format 'version:<build-number>'.
_BUILD_CONFIG = {
'catatester_devicemap_upload': {
'pkg_project': 'continuous-tests',
'pkg_def': 'catatester/devicemap/cipd.yaml',
'refs': ['live', 'staging'],
},
'catatester_puppet_upload': {
'pkg_project': 'continuous-tests',
'pkg_def': 'catatester/puppet_cipd_pkg.yaml',
'refs': ['staging'],
},
'continuous_tests_files_upload': {
'pkg_project': 'continuous-tests',
'pkg_def': 'essential_pkg.yaml',
'refs': ['live', 'staging'],
},
}
def GetValidBuildNames():
return list(_BUILD_CONFIG.keys())
def CreateRecipe(build_name: str, **kwargs):
"""Creates a recipe based on build info stored in _BUILD_CONFIG.
Args:
build_name: The name of the build.
Raises:
ValueError if required info isn't included in config.
"""
build_cfg = _BUILD_CONFIG[build_name]
return CIPDPackageUploadRecipe(
build_cfg['pkg_project'],
build_cfg['pkg_def'],
refs=build_cfg.get('refs'),
include_version=build_cfg.get('version'),
**kwargs)
class CIPDPackageUploadRecipe(base_recipe.BaseRecipe):
"""Uploads the designated test source files to CIPD."""
def __init__(self, pkg_project, pkg_def, refs=None, tags=None,
include_version=False, **kwargs):
"""Constructor.
Args:
pkg_project: The project containing the pkg_def file.
pkg_def: The relative path to the pkg_def file, from the project root.
refs: A list of refs to be assigned to the uploaded cipd package.
tags: A dict of tags to be assigned to the uploaded cipd package.
"""
base_recipe.BaseRecipe.__init__(self, **kwargs)
self._pkg_project = pkg_project
self._pkg_def = pkg_def
self._refs = refs
self._tags = tags or {}
if include_version:
self._tags['version'] = self.build_number
def get_steps(self):
return [
cipd_upload_step.CIPDUploadStep(
os.path.join(self._pkg_project, self._pkg_def),
refs=self._refs,
tags=self._tags,
**self._step_kwargs)]