Skip to content

Commit

Permalink
Merge pull request adobe#64 from bluesliverx/main
Browse files Browse the repository at this point in the history
Allow a string for the build
  • Loading branch information
bluesliverx authored Aug 28, 2023
2 parents 0f88cd6 + f522212 commit a7ffb7c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
10 changes: 7 additions & 3 deletions buildrunner/validation/config_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,21 @@ class StepPushDict(BaseModel):

class Step(BaseModel):
""" Step model """
build: Optional[StepBuild]
build: Optional[Union[StepBuild, str]]
push: Optional[Union[StepPushDict, List[Union[str, StepPushDict]], str]]

def is_multi_platform(self):
"""
Check if the step is a multi-platform build step
"""
return self.build is not None and \
return isinstance(self.build, StepBuild) and \
self.build.platforms is not None


class Config(BaseModel):
""" Top level config model """
version: Optional[float]
steps: Optional[Dict[str, Step]]
steps: Optional[Dict[str, Optional[Step]]]

# Note this is pydantic version 1.10 syntax
@validator('steps')
Expand Down Expand Up @@ -127,6 +127,8 @@ def validate_multi_platform_build(mp_push_tags: Set[str]):

has_multi_platform_build = False
for step in values.values():
if not step:
continue
has_multi_platform_build = has_multi_platform_build or step.is_multi_platform()

if has_multi_platform_build:
Expand All @@ -135,6 +137,8 @@ def validate_multi_platform_build(mp_push_tags: Set[str]):

# Validate that all tags are unique across all multi-platform step
for step_name, step in values.items():
if not step:
continue

# Check that there are no single platform tags that match multi-platform tags
if not step.is_multi_platform():
Expand Down
23 changes: 21 additions & 2 deletions tests/test_config_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,23 @@ def test_platforms_invalid():
}
}
result = validate_config(**config)
assert len(result.errors) == 1
assert len(result.errors) == 2
assert len(result.warnings) == 0


def test_build_is_path():
config = {
'steps': {
'build-is-path': {
'build': '.',
},
}
}
result = validate_config(**config)
assert len(result.errors) == 0
assert len(result.warnings) == 0


def test_valid_platforms():
config = {
'steps': {
Expand Down Expand Up @@ -143,6 +157,7 @@ def test_duplicate_mp_tags_dictionary_invalid():
assert len(result.errors) == 1
assert len(result.warnings) == 0


def test_duplicate_mp_tags_strings_invalid():
# Invalid to have duplicate multi-platform tag
# Testing with both string format, one inferred 'latest' the other explicit 'latest'
Expand Down Expand Up @@ -200,6 +215,7 @@ def test_duplicate_mp_tags_strings_invalid():
assert len(result.errors) == 1
assert len(result.warnings) == 0


def test_duplicate_mp_tags_strings_valid():
# Same string format but different MP tags
config = {
Expand Down Expand Up @@ -228,6 +244,7 @@ def test_duplicate_mp_tags_strings_valid():
assert len(result.errors) == 0
assert len(result.warnings) == 0


def test_duplicate_mp_tags_platform_platforms_invalid():
# Invalid to have duplicate multi-platform tag and single platform tag
config = {
Expand All @@ -253,6 +270,7 @@ def test_duplicate_mp_tags_platform_platforms_invalid():
assert len(result.errors) == 1
assert len(result.warnings) == 0


def test_valid_config():
# Sample valid config, but not exhaustive
config = {
Expand Down Expand Up @@ -310,6 +328,7 @@ def test_valid_config():
assert len(result.errors) == 0
assert len(result.warnings) == 0


def test_multiple_errors():
# Multiple errors
# Invalid to have version as a string
Expand Down Expand Up @@ -337,4 +356,4 @@ def test_multiple_errors():
}
result = validate_config(**config)
assert len(result.errors) == 2
assert len(result.warnings) == 0
assert len(result.warnings) == 0

0 comments on commit a7ffb7c

Please sign in to comment.