From 1e9f8ff077b07e72d019bd6ddfba4ea03e26bbff Mon Sep 17 00:00:00 2001 From: Michael Jerger Date: Fri, 5 May 2023 11:57:36 +0200 Subject: [PATCH] merge release & ReleaseContext --- doc/architecture/Domain.md | 22 ++++++-- src/main/python/ddadevops/__init__.py | 2 +- src/main/python/ddadevops/domain/__init__.py | 2 +- .../python/ddadevops/domain/devops_factory.py | 5 +- src/main/python/ddadevops/domain/release.py | 56 ++++--------------- .../infrastructure/release_mixin/repo.py | 17 +++--- src/test/python/domain/test_common.py | 1 - src/test/python/domain/test_release.py | 3 +- .../release_mixin/mock_infrastructure.py | 6 +- src/test/python/test_release_mixin.py | 2 +- 10 files changed, 45 insertions(+), 71 deletions(-) diff --git a/doc/architecture/Domain.md b/doc/architecture/Domain.md index ce9f80b..484433f 100644 --- a/doc/architecture/Domain.md +++ b/doc/architecture/Domain.md @@ -35,19 +35,29 @@ classDiagram class Release { release_main_branch - release_config_file - } - class ReleaseContext { - release_type - release_version release_current_branch + release_type + } + + class BuildFile { + filename + file_type + content + } + + class Version { + get_version_string(release_type: ReleaseType) + create_release_version(release_type: ReleaseType): + create_bump_version(release_type: ReleaseType): } Devops *-- "0..1" Image: spcialized_builds Devops *-- "0..1" C4k: spcialized_builds Devops *-- "0..1" Release: mixins + Release *-- "0..1" BuildFile: primary_release_file + Release *-- "0..n" BuildFile: secondary_release_files + BuildFile *-- "1" Version C4k *-- DnsRecord - Release *-- "0..1" ReleaseContext ``` diff --git a/src/main/python/ddadevops/__init__.py b/src/main/python/ddadevops/__init__.py index 30ae280..37bb5b1 100644 --- a/src/main/python/ddadevops/__init__.py +++ b/src/main/python/ddadevops/__init__.py @@ -20,6 +20,6 @@ from .devops_build import DevopsBuild, create_devops_build_config, get_devops_bu from .credential import gopass_password_from_path, gopass_field_from_path from .release_mixin import ReleaseMixin -from .domain import Validateable, DnsRecord, Devops, Image, Release, ReleaseContext +from .domain import Validateable, DnsRecord, Devops, Image, Release __version__ = "${version}" diff --git a/src/main/python/ddadevops/domain/__init__.py b/src/main/python/ddadevops/domain/__init__.py index 8121e0d..93fe834 100644 --- a/src/main/python/ddadevops/domain/__init__.py +++ b/src/main/python/ddadevops/domain/__init__.py @@ -2,4 +2,4 @@ from .common import Validateable, DnsRecord, Devops, BuildType, MixinType from .devops_factory import DevopsFactory from .image import Image from .c4k import C4k -from .release import Release, ReleaseContext, ReleaseType, Version, EnvironmentKeys +from .release import Release, ReleaseType, Version, EnvironmentKeys diff --git a/src/main/python/ddadevops/domain/devops_factory.py b/src/main/python/ddadevops/domain/devops_factory.py index caac032..7e2a3bb 100644 --- a/src/main/python/ddadevops/domain/devops_factory.py +++ b/src/main/python/ddadevops/domain/devops_factory.py @@ -4,7 +4,7 @@ from typing import List from .common import Devops, BuildType, MixinType from .image import Image from .c4k import C4k -from .release import Release, ReleaseContext +from .release import Release class DevopsFactory: @@ -23,8 +23,7 @@ class DevopsFactory: mixins = {} if MixinType.RELEASE in mixin_types: - release_context = ReleaseContext(input) - mixins[MixinType.RELEASE] = Release(input, release_context=release_context) + mixins[MixinType.RELEASE] = Release(input) 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 b10a085..b87cc62 100644 --- a/src/main/python/ddadevops/domain/release.py +++ b/src/main/python/ddadevops/domain/release.py @@ -8,12 +8,10 @@ from .common import ( class ReleaseType(Enum): - MAJOR = 0 - MINOR = 1 - PATCH = 2 - SNAPSHOT = 3 - BUMP = None - NONE = 15 + MAJOR = 3 + MINOR = 2 + PATCH = 1 + NONE = None class EnvironmentKeys(Enum): @@ -66,14 +64,13 @@ class Version(Validateable): return bump_version -class ReleaseContext(Validateable): - def __init__( - self, - input: dict, - ): - self.release_type = ReleaseType[input.get("release_type", "SNAPSHOT")] - self.release_current_version = input.get("release_current_version") +class Release(Validateable): + def __init__(self, input: dict): + 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_current_version = input.get("release_current_version") + self.release_config_file = input.get("release_config_file", "project.clj") self.version = self.__version_from_str__() # TODO: mv version parsing to version @@ -96,12 +93,10 @@ class ReleaseContext(Validateable): result += self.__validate_is_not_empty__("release_type") result += self.__validate_is_not_empty__("release_current_version") 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_config_file") if self.version: result += self.version.validate() - return result - - def validate_branch(self, main_branch: str): - result = [] if ( self.release_type is not None and self.release_type != ReleaseType.NONE @@ -109,30 +104,3 @@ class ReleaseContext(Validateable): ): result.append(f"Releases are allowed only on {main_branch}") return result - - -class Release(Validateable): - def __init__( - self, - input: dict, - release_context: ReleaseContext, - ): - self.release_main_branch = input.get("release_main_branch", "main") - self.release_config_file = input.get("release_config_file", "project.clj") - self.release_context = release_context - - def release_version(self): - return self.release_context.release_version() - - def bump_version(self): - return self.release_context.bump_version() - - def validate(self): - result = [] - result += self.__validate_is_not_empty__("release_main_branch") - result += self.__validate_is_not_empty__("release_config_file") - result += self.__validate_is_not_empty__("release_context") - if self.release_context is not None: - result += self.release_context.validate() - result += self.release_context.validate_branch(self.release_main_branch) - return result diff --git a/src/main/python/ddadevops/infrastructure/release_mixin/repo.py b/src/main/python/ddadevops/infrastructure/release_mixin/repo.py index 588118a..2557042 100644 --- a/src/main/python/ddadevops/infrastructure/release_mixin/repo.py +++ b/src/main/python/ddadevops/infrastructure/release_mixin/repo.py @@ -1,6 +1,5 @@ from src.main.python.ddadevops.domain import ( - ReleaseContext, Version, ReleaseType, EnvironmentKeys, @@ -116,11 +115,11 @@ class ReleaseContextRepository: self.version_repository = version_repository self.release_type_repository = release_type_repository - def get_release(self, main_branch: str) -> ReleaseContext: - result = ReleaseContext( - self.release_type_repository.get_release_type(), - self.version_repository.get_version(), - main_branch, - ) - result.throw_if_invalid() - return result + # def get_release(self, main_branch: str) -> ReleaseContext: + # result = ReleaseContext( + # self.release_type_repository.get_release_type(), + # self.version_repository.get_version(), + # main_branch, + # ) + # result.throw_if_invalid() + # return result diff --git a/src/test/python/domain/test_common.py b/src/test/python/domain/test_common.py index 9b4e21f..ef4769f 100644 --- a/src/test/python/domain/test_common.py +++ b/src/test/python/domain/test_common.py @@ -10,7 +10,6 @@ from src.main.python.ddadevops.domain import ( Version, ReleaseType, Release, - ReleaseContext, ) from src.main.python.ddadevops.domain.image import Image from .test_helper import build_devops diff --git a/src/test/python/domain/test_release.py b/src/test/python/domain/test_release.py index b81d29a..673ada0 100644 --- a/src/test/python/domain/test_release.py +++ b/src/test/python/domain/test_release.py @@ -11,7 +11,6 @@ from src.main.python.ddadevops.domain import ( Version, ReleaseType, Release, - ReleaseContext, ) from src.main.python.ddadevops.domain.image import Image from .test_helper import build_devops, devops_config @@ -50,7 +49,7 @@ def test_version(tmp_path: Path): def test_release_context(tmp_path): - sut = ReleaseContext( + sut = Release( devops_config( { "release_type": "MINOR", diff --git a/src/test/python/release_mixin/mock_infrastructure.py b/src/test/python/release_mixin/mock_infrastructure.py index 81b09b5..74bd1a5 100644 --- a/src/test/python/release_mixin/mock_infrastructure.py +++ b/src/test/python/release_mixin/mock_infrastructure.py @@ -1,6 +1,6 @@ from pathlib import Path -from src.main.python.ddadevops.domain import ReleaseType, Version, ReleaseContext +from src.main.python.ddadevops.domain import ReleaseType, Version from .mock_infrastructure_api import MockGitApi @@ -38,6 +38,6 @@ class MockReleaseRepository(): self.main_branch = main_branch self.get_release_count = 0 - def get_release(self) -> ReleaseContext: + def get_release(self) -> : self.get_release_count += 1 - return ReleaseContext(self.release_type_repository.get_release_type(), self.version_repository.get_version(), self.main_branch) + return Release(self.release_type_repository.get_release_type(), self.version_repository.get_version(), self.main_branch) diff --git a/src/test/python/test_release_mixin.py b/src/test/python/test_release_mixin.py index 2e13ea6..ed5c417 100644 --- a/src/test/python/test_release_mixin.py +++ b/src/test/python/test_release_mixin.py @@ -7,7 +7,7 @@ from src.main.python.ddadevops.infrastructure.release_mixin import ( GitApi, EnvironmentApi, ) -from src.main.python.ddadevops.domain import Devops, ReleaseContext, Release +from src.main.python.ddadevops.domain import Devops, Release from .resource_helper import ResourceHelper from .domain.test_helper import devops_config