merge release & ReleaseContext

This commit is contained in:
Michael Jerger 2023-05-05 11:57:36 +02:00
parent df1200de4a
commit 1e9f8ff077
10 changed files with 45 additions and 71 deletions

View file

@ -35,19 +35,29 @@ classDiagram
class Release { class Release {
release_main_branch release_main_branch
release_config_file
}
class ReleaseContext {
release_type
release_version
release_current_branch 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" Image: spcialized_builds
Devops *-- "0..1" C4k: spcialized_builds Devops *-- "0..1" C4k: spcialized_builds
Devops *-- "0..1" Release: mixins Devops *-- "0..1" Release: mixins
Release *-- "0..1" BuildFile: primary_release_file
Release *-- "0..n" BuildFile: secondary_release_files
BuildFile *-- "1" Version
C4k *-- DnsRecord C4k *-- DnsRecord
Release *-- "0..1" ReleaseContext
``` ```

View file

@ -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 .credential import gopass_password_from_path, gopass_field_from_path
from .release_mixin import ReleaseMixin from .release_mixin import ReleaseMixin
from .domain import Validateable, DnsRecord, Devops, Image, Release, ReleaseContext from .domain import Validateable, DnsRecord, Devops, Image, Release
__version__ = "${version}" __version__ = "${version}"

View file

@ -2,4 +2,4 @@ from .common import Validateable, DnsRecord, Devops, BuildType, MixinType
from .devops_factory import DevopsFactory from .devops_factory import DevopsFactory
from .image import Image from .image import Image
from .c4k import C4k from .c4k import C4k
from .release import Release, ReleaseContext, ReleaseType, Version, EnvironmentKeys from .release import Release, ReleaseType, Version, EnvironmentKeys

View file

@ -4,7 +4,7 @@ from typing import List
from .common import Devops, BuildType, MixinType from .common import Devops, BuildType, MixinType
from .image import Image from .image import Image
from .c4k import C4k from .c4k import C4k
from .release import Release, ReleaseContext from .release import Release
class DevopsFactory: class DevopsFactory:
@ -23,8 +23,7 @@ class DevopsFactory:
mixins = {} mixins = {}
if MixinType.RELEASE in mixin_types: if MixinType.RELEASE in mixin_types:
release_context = ReleaseContext(input) mixins[MixinType.RELEASE] = Release(input)
mixins[MixinType.RELEASE] = Release(input, release_context=release_context)
devops = Devops(input, specialized_builds=specialized_builds, mixins=mixins) devops = Devops(input, specialized_builds=specialized_builds, mixins=mixins)

View file

@ -8,12 +8,10 @@ from .common import (
class ReleaseType(Enum): class ReleaseType(Enum):
MAJOR = 0 MAJOR = 3
MINOR = 1 MINOR = 2
PATCH = 2 PATCH = 1
SNAPSHOT = 3 NONE = None
BUMP = None
NONE = 15
class EnvironmentKeys(Enum): class EnvironmentKeys(Enum):
@ -66,14 +64,13 @@ class Version(Validateable):
return bump_version return bump_version
class ReleaseContext(Validateable): class Release(Validateable):
def __init__( def __init__(self, input: dict):
self, self.release_type = ReleaseType[input.get("release_type", "NONE")]
input: dict, self.release_main_branch = input.get("release_main_branch", "main")
):
self.release_type = ReleaseType[input.get("release_type", "SNAPSHOT")]
self.release_current_version = input.get("release_current_version")
self.release_current_branch = input.get("release_current_branch") 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__() self.version = self.__version_from_str__()
# TODO: mv version parsing to version # 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_type")
result += self.__validate_is_not_empty__("release_current_version") 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_current_branch")
result += self.__validate_is_not_empty__("release_main_branch")
result += self.__validate_is_not_empty__("release_config_file")
if self.version: if self.version:
result += self.version.validate() result += self.version.validate()
return result
def validate_branch(self, main_branch: str):
result = []
if ( if (
self.release_type is not None self.release_type is not None
and self.release_type != ReleaseType.NONE and self.release_type != ReleaseType.NONE
@ -109,30 +104,3 @@ class ReleaseContext(Validateable):
): ):
result.append(f"Releases are allowed only on {main_branch}") result.append(f"Releases are allowed only on {main_branch}")
return result 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

View file

@ -1,6 +1,5 @@
from src.main.python.ddadevops.domain import ( from src.main.python.ddadevops.domain import (
ReleaseContext,
Version, Version,
ReleaseType, ReleaseType,
EnvironmentKeys, EnvironmentKeys,
@ -116,11 +115,11 @@ class ReleaseContextRepository:
self.version_repository = version_repository self.version_repository = version_repository
self.release_type_repository = release_type_repository self.release_type_repository = release_type_repository
def get_release(self, main_branch: str) -> ReleaseContext: # def get_release(self, main_branch: str) -> ReleaseContext:
result = ReleaseContext( # result = ReleaseContext(
self.release_type_repository.get_release_type(), # self.release_type_repository.get_release_type(),
self.version_repository.get_version(), # self.version_repository.get_version(),
main_branch, # main_branch,
) # )
result.throw_if_invalid() # result.throw_if_invalid()
return result # return result

View file

@ -10,7 +10,6 @@ from src.main.python.ddadevops.domain import (
Version, Version,
ReleaseType, ReleaseType,
Release, Release,
ReleaseContext,
) )
from src.main.python.ddadevops.domain.image import Image from src.main.python.ddadevops.domain.image import Image
from .test_helper import build_devops from .test_helper import build_devops

View file

@ -11,7 +11,6 @@ from src.main.python.ddadevops.domain import (
Version, Version,
ReleaseType, ReleaseType,
Release, Release,
ReleaseContext,
) )
from src.main.python.ddadevops.domain.image import Image from src.main.python.ddadevops.domain.image import Image
from .test_helper import build_devops, devops_config from .test_helper import build_devops, devops_config
@ -50,7 +49,7 @@ def test_version(tmp_path: Path):
def test_release_context(tmp_path): def test_release_context(tmp_path):
sut = ReleaseContext( sut = Release(
devops_config( devops_config(
{ {
"release_type": "MINOR", "release_type": "MINOR",

View file

@ -1,6 +1,6 @@
from pathlib import Path 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 from .mock_infrastructure_api import MockGitApi
@ -38,6 +38,6 @@ class MockReleaseRepository():
self.main_branch = main_branch self.main_branch = main_branch
self.get_release_count = 0 self.get_release_count = 0
def get_release(self) -> ReleaseContext: def get_release(self) -> :
self.get_release_count += 1 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)

View file

@ -7,7 +7,7 @@ from src.main.python.ddadevops.infrastructure.release_mixin import (
GitApi, GitApi,
EnvironmentApi, 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 .resource_helper import ResourceHelper
from .domain.test_helper import devops_config from .domain.test_helper import devops_config