From ee9c2bfd6478baf5d3584a0e399738e6d1ce8bb4 Mon Sep 17 00:00:00 2001 From: Shane Brown Date: Mon, 11 Sep 2023 14:50:01 -0600 Subject: [PATCH] Add remaining config attributes, minus global config --- buildrunner/validation/config.py | 6 +-- buildrunner/validation/errors.py | 2 +- buildrunner/validation/step.py | 21 ++++---- .../__init__.py | 0 .../test_validation_artifacts.py | 0 .../test_validation_config.py | 0 .../test_validation_run.py | 0 .../test_validation_step.py | 54 +++++++++++++++++++ 8 files changed, 70 insertions(+), 13 deletions(-) rename tests/{validation => test_validation}/__init__.py (100%) rename tests/{validation => test_validation}/test_validation_artifacts.py (100%) rename tests/{validation => test_validation}/test_validation_config.py (100%) rename tests/{validation => test_validation}/test_validation_run.py (100%) rename tests/{validation => test_validation}/test_validation_step.py (84%) diff --git a/buildrunner/validation/config.py b/buildrunner/validation/config.py index ac9c6bc4..c4f734e2 100644 --- a/buildrunner/validation/config.py +++ b/buildrunner/validation/config.py @@ -12,7 +12,7 @@ from pydantic import BaseModel, validator, ValidationError from buildrunner.validation.errors import Errors, _add_validation_errors -from buildrunner.validation.step import Step, StepPushDict +from buildrunner.validation.step import Step, StepPushCommitDict class Config(BaseModel): @@ -31,7 +31,7 @@ def validate_steps(cls, values) -> None: ValueError | pydantic.ValidationError : If the config file is invalid """ - def validate_push(push: Union[StepPushDict, List[Union[str, StepPushDict]], str], + def validate_push(push: Union[StepPushCommitDict, List[Union[str, StepPushCommitDict]], str], mp_push_tags: Set[str], step_name: str, update_mp_push_tags: bool = True): @@ -56,7 +56,7 @@ def validate_push(push: Union[StepPushDict, List[Union[str, StepPushDict]], str] if ":" not in name: name = f'{name}:latest' - if isinstance(push, StepPushDict): + if isinstance(push, StepPushCommitDict): names = [f"{push.repository}:{tag}" for tag in push.tags] if names is not None: diff --git a/buildrunner/validation/errors.py b/buildrunner/validation/errors.py index 214864ea..4c9bd62e 100644 --- a/buildrunner/validation/errors.py +++ b/buildrunner/validation/errors.py @@ -41,7 +41,7 @@ def _add_validation_errors(exc: ValidationError) -> Errors: for error in exc.errors(): loc = [str(item) for item in error["loc"]] if error["type"] == "value_error.extra": - errors.add(field='.'.join(loc), message=f'not a valid field, please check the spelling and documentation') + errors.add(field='.'.join(loc), message='not a valid field, please check the spelling and documentation') else: errors.add(field='.'.join(loc), message=f'{error["msg"]} ({error["type"]})') return errors diff --git a/buildrunner/validation/step.py b/buildrunner/validation/step.py index 6595302a..3621492c 100644 --- a/buildrunner/validation/step.py +++ b/buildrunner/validation/step.py @@ -13,14 +13,11 @@ from pydantic import BaseModel, Field -class StepCommit(BaseModel): - """ Step commit model""" - pass - - class StepPypiPush(BaseModel): """ Step pypi push model""" - pass + repository: str + username: str + password: str class Artifact(BaseModel): @@ -49,6 +46,9 @@ class TypeTypes(Enum): # pylint: disable=invalid-name tar = 'tar' zip = 'zip' + # Valid attributes for PyPI repository + python_wheel = 'python-wheel' + python_sdist = 'python-sdist' format: Optional[FormatTypes] type: Optional[TypeTypes] @@ -60,10 +60,11 @@ class StepRun(BaseModel, extra='forbid'): """ Run model within a step """ class ProvisionerTypes(Enum): + """ Provisioner types """ + # pylint: disable=invalid-name shell: str = 'shell' salt: str = 'salt' - xfail: Optional[bool] services: Optional[dict[str, str]] image: Optional[str] @@ -122,7 +123,7 @@ class StepBuild(BaseModel, extra='forbid'): platforms: Optional[List[str]] -class StepPushDict(BaseModel, extra='forbid'): +class StepPushCommitDict(BaseModel, extra='forbid'): """ Push model within a step """ repository: str tags: Optional[List[str]] @@ -131,10 +132,12 @@ class StepPushDict(BaseModel, extra='forbid'): class Step(BaseModel, extra='forbid'): """ Step model """ build: Optional[Union[StepBuild, str]] - push: Optional[Union[StepPushDict, List[Union[str, StepPushDict]], str]] + push: Optional[Union[StepPushCommitDict, List[Union[str, StepPushCommitDict]], str]] + commit: Optional[Union[StepPushCommitDict, List[Union[str, StepPushCommitDict]], str]] remote: Optional[StepRemote] run: Optional[StepRun] depends: Optional[list[str]] + pypi_push: Optional[Union[StepPypiPush, str]] = Field(alias='pypi-push') def is_multi_platform(self): """ diff --git a/tests/validation/__init__.py b/tests/test_validation/__init__.py similarity index 100% rename from tests/validation/__init__.py rename to tests/test_validation/__init__.py diff --git a/tests/validation/test_validation_artifacts.py b/tests/test_validation/test_validation_artifacts.py similarity index 100% rename from tests/validation/test_validation_artifacts.py rename to tests/test_validation/test_validation_artifacts.py diff --git a/tests/validation/test_validation_config.py b/tests/test_validation/test_validation_config.py similarity index 100% rename from tests/validation/test_validation_config.py rename to tests/test_validation/test_validation_config.py diff --git a/tests/validation/test_validation_run.py b/tests/test_validation/test_validation_run.py similarity index 100% rename from tests/validation/test_validation_run.py rename to tests/test_validation/test_validation_run.py diff --git a/tests/validation/test_validation_step.py b/tests/test_validation/test_validation_step.py similarity index 84% rename from tests/validation/test_validation_step.py rename to tests/test_validation/test_validation_step.py index 1419a02d..39f80879 100644 --- a/tests/validation/test_validation_step.py +++ b/tests/test_validation/test_validation_step.py @@ -1,4 +1,5 @@ +import yaml from buildrunner.validation.config import validate_config, Errors @@ -269,3 +270,56 @@ def test_step_remote_missing_cmd(): errors = validate_config(**config) assert isinstance(errors, Errors) assert errors.count() == 1 + + +def test_commit(): + config_yaml = """ + steps: + step1: + build: + path: . + dockerfile: Dockerfile + pull: false + commit: + repository: mytest-reg/image1 + tags: + - latest + step2: + build: + path: . + dockerfile: Dockerfile + pull: false + commit: mytest-reg/image1 + """ + config = yaml.load(config_yaml, Loader=yaml.Loader) + errors = validate_config(**config) + assert errors is None + + +def test_pypi_push(): + config_yaml = """ + steps: + pypi: + run: + image: python:2 + cmds: + - python setup.py sdist + artifacts: + "dist/*.tar.gz": { type: 'python-sdist' } + pypi-push: artifactory-releng + pypi: + run: + image: python:2 + cmds: + - python -m build + artifacts: + "dist/*.tar.gz": { type: 'python-sdist' } + "dist/*.whl": { type: 'python-wheel' } + pypi-push: + repository: https://artifactory.example.com/artifactory/api/pypi/pypi-myownrepo + username: myuser + password: mypass + """ + config = yaml.load(config_yaml, Loader=yaml.Loader) + errors = validate_config(**config) + assert errors is None