diff --git a/doc/architecture/Domain.md b/doc/architecture/Domain.md index 3c9014b..e99055d 100644 --- a/doc/architecture/Domain.md +++ b/doc/architecture/Domain.md @@ -34,9 +34,9 @@ classDiagram } class Release { + release_type release_main_branch release_current_branch - release_type version } diff --git a/src/main/python/ddadevops/domain/devops_factory.py b/src/main/python/ddadevops/domain/devops_factory.py index 7e2a3bb..d60bd1b 100644 --- a/src/main/python/ddadevops/domain/devops_factory.py +++ b/src/main/python/ddadevops/domain/devops_factory.py @@ -5,6 +5,7 @@ from .common import Devops, BuildType, MixinType from .image import Image from .c4k import C4k from .release import Release +from .version import Version class DevopsFactory: @@ -23,7 +24,8 @@ class DevopsFactory: mixins = {} if MixinType.RELEASE in mixin_types: - mixins[MixinType.RELEASE] = Release(input) + version = Version.from_str(input["version"]) + mixins[MixinType.RELEASE] = Release(input, version) devops = Devops(input, specialized_builds=specialized_builds, mixins=mixins) diff --git a/src/main/python/ddadevops/domain/release.py b/src/main/python/ddadevops/domain/release.py index 0051452..7aaf162 100644 --- a/src/main/python/ddadevops/domain/release.py +++ b/src/main/python/ddadevops/domain/release.py @@ -16,33 +16,26 @@ class EnvironmentKeys(Enum): class Release(Validateable): - def __init__(self, input: dict): + def __init__(self, input: dict, version: Version): self.release_type = ReleaseType[input.get("release_type", "NONE")] self.release_main_branch = input.get("release_main_branch", "main") self.release_current_branch = input.get("release_current_branch") - self.release_config_file = input.get("release_config_file", "project.clj") - self.release_current_version = Version.from_str(input.get("release_current_version")) + self.release_config_file = input.get("release_config_file", "./project.clj") + self.version = version - - def release_version(self) -> Version: - return self.version.create_release_version(self.release_type) - - def bump_version(self) -> Version: - return self.release_version().create_bump_version() - def validate(self): result = [] result += self.__validate_is_not_empty__("release_type") - result += self.__validate_is_not_empty__("release_current_branch") result += self.__validate_is_not_empty__("release_main_branch") + result += self.__validate_is_not_empty__("release_current_branch") result += self.__validate_is_not_empty__("release_config_file") - result += self.__validate_is_not_empty__("release_current_version") - if self.release_current_version: - result += self.release_current_version.validate() + result += self.__validate_is_not_empty__("version") + if self.version: + result += self.version.validate() if ( self.release_type is not None and self.release_type != ReleaseType.NONE and self.release_main_branch != self.release_current_branch ): - result.append(f"Releases are allowed only on {main_branch}") + result.append(f"Releases are allowed only on {self.release_main_branch}") return result diff --git a/src/test/python/domain/test_devops_factory.py b/src/test/python/domain/test_devops_factory.py index ab4e414..e1da188 100644 --- a/src/test/python/domain/test_devops_factory.py +++ b/src/test/python/domain/test_devops_factory.py @@ -52,11 +52,11 @@ def test_devops_factory(): "project_root_path": "../../..", "build_types": [], "mixin_types": ["RELEASE"], - "release_main_branch": "main", - "release_config_file": "project.clj", + "version": "1.0.0", "release_type": "NONE", - "release_current_version": "1.0.0", + "release_main_branch": "main", "release_current_branch": "my_feature", + "release_config_file": "project.clj", } ) assert sut is not None diff --git a/src/test/python/domain/test_helper.py b/src/test/python/domain/test_helper.py index 391f729..381c489 100644 --- a/src/test/python/domain/test_helper.py +++ b/src/test/python/domain/test_helper.py @@ -18,11 +18,11 @@ def devops_config(overrides: dict) -> dict: "c4k_grafana_cloud_password": "password", "c4k_grafana_cloud_url": "https://prometheus-prod-01-eu-west-0.grafana.net/api/prom/push", "c4k_auth": {}, - "release_main_branch": "main", - "release_config_file": "project.clj", + "version": "1.0.0", "release_type": "NONE", - "release_current_version": "1.0.0", + "release_main_branch": "main", "release_current_branch": "my_feature", + "release_config_file": "./project.clj", } input = default.copy() input.update(overrides) diff --git a/src/test/python/domain/test_release.py b/src/test/python/domain/test_release.py index af2f3d7..6c80915 100644 --- a/src/test/python/domain/test_release.py +++ b/src/test/python/domain/test_release.py @@ -15,27 +15,26 @@ from src.main.python.ddadevops.domain import ( from src.main.python.ddadevops.domain.image import Image from .test_helper import build_devops, devops_config -def test_release_context(tmp_path): + +def test_sould_validate_release(): sut = Release( devops_config( { "release_type": "MINOR", - "release_current_version": "1.2.3", "release_current_branch": "main", } - ) + ), + Version.from_str("1.3.1-SNAPSHOT"), ) - assert sut.release_version().get_version_string() == "1.3.0" - assert sut.bump_version().get_version_string() == "1.3.1-SNAPSHOT" - - -def test_release(tmp_path): - sut = build_devops( - { - "release_type": "MINOR", - "release_current_version": "1.2.3", - "release_current_branch": "main", - } - ) - assert sut.mixins[MixinType.RELEASE] assert sut.is_valid() + + sut = Release( + devops_config( + { + "release_type": "MINOR", + "release_current_branch": "some-feature-branch", + } + ), + Version.from_str("1.3.1-SNAPSHOT"), + ) + assert not sut.is_valid()