Skip to content

Commit

Permalink
Add remaining config attributes, minus global config
Browse files Browse the repository at this point in the history
  • Loading branch information
Shane Brown committed Sep 11, 2023
1 parent 8657fd4 commit ee9c2bf
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 13 deletions.
6 changes: 3 additions & 3 deletions buildrunner/validation/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion buildrunner/validation/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 12 additions & 9 deletions buildrunner/validation/step.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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]
Expand All @@ -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]
Expand Down Expand Up @@ -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]]
Expand All @@ -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):
"""
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

import yaml
from buildrunner.validation.config import validate_config, Errors


Expand Down Expand Up @@ -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

0 comments on commit ee9c2bf

Please sign in to comment.