fix release

This commit is contained in:
Michael Jerger 2023-05-10 19:52:53 +02:00
parent 2e2c04c8ba
commit 8359406330
6 changed files with 33 additions and 39 deletions

View file

@ -34,9 +34,9 @@ classDiagram
} }
class Release { class Release {
release_type
release_main_branch release_main_branch
release_current_branch release_current_branch
release_type
version version
} }

View file

@ -5,6 +5,7 @@ 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 from .release import Release
from .version import Version
class DevopsFactory: class DevopsFactory:
@ -23,7 +24,8 @@ class DevopsFactory:
mixins = {} mixins = {}
if MixinType.RELEASE in mixin_types: 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) devops = Devops(input, specialized_builds=specialized_builds, mixins=mixins)

View file

@ -16,33 +16,26 @@ class EnvironmentKeys(Enum):
class Release(Validateable): 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_type = ReleaseType[input.get("release_type", "NONE")]
self.release_main_branch = input.get("release_main_branch", "main") self.release_main_branch = input.get("release_main_branch", "main")
self.release_current_branch = input.get("release_current_branch") self.release_current_branch = input.get("release_current_branch")
self.release_config_file = input.get("release_config_file", "project.clj") self.release_config_file = input.get("release_config_file", "./project.clj")
self.release_current_version = Version.from_str(input.get("release_current_version")) 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): def validate(self):
result = [] result = []
result += self.__validate_is_not_empty__("release_type") 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_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_config_file")
result += self.__validate_is_not_empty__("release_current_version") result += self.__validate_is_not_empty__("version")
if self.release_current_version: if self.version:
result += self.release_current_version.validate() result += self.version.validate()
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
and self.release_main_branch != self.release_current_branch 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 return result

View file

@ -52,11 +52,11 @@ def test_devops_factory():
"project_root_path": "../../..", "project_root_path": "../../..",
"build_types": [], "build_types": [],
"mixin_types": ["RELEASE"], "mixin_types": ["RELEASE"],
"release_main_branch": "main", "version": "1.0.0",
"release_config_file": "project.clj",
"release_type": "NONE", "release_type": "NONE",
"release_current_version": "1.0.0", "release_main_branch": "main",
"release_current_branch": "my_feature", "release_current_branch": "my_feature",
"release_config_file": "project.clj",
} }
) )
assert sut is not None assert sut is not None

View file

@ -18,11 +18,11 @@ def devops_config(overrides: dict) -> dict:
"c4k_grafana_cloud_password": "password", "c4k_grafana_cloud_password": "password",
"c4k_grafana_cloud_url": "https://prometheus-prod-01-eu-west-0.grafana.net/api/prom/push", "c4k_grafana_cloud_url": "https://prometheus-prod-01-eu-west-0.grafana.net/api/prom/push",
"c4k_auth": {}, "c4k_auth": {},
"release_main_branch": "main", "version": "1.0.0",
"release_config_file": "project.clj",
"release_type": "NONE", "release_type": "NONE",
"release_current_version": "1.0.0", "release_main_branch": "main",
"release_current_branch": "my_feature", "release_current_branch": "my_feature",
"release_config_file": "./project.clj",
} }
input = default.copy() input = default.copy()
input.update(overrides) input.update(overrides)

View file

@ -15,27 +15,26 @@ from src.main.python.ddadevops.domain import (
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
def test_release_context(tmp_path):
def test_sould_validate_release():
sut = Release( sut = Release(
devops_config( devops_config(
{ {
"release_type": "MINOR", "release_type": "MINOR",
"release_current_version": "1.2.3",
"release_current_branch": "main", "release_current_branch": "main",
} }
),
Version.from_str("1.3.1-SNAPSHOT"),
) )
) assert sut.is_valid()
assert sut.release_version().get_version_string() == "1.3.0"
assert sut.bump_version().get_version_string() == "1.3.1-SNAPSHOT"
sut = Release(
def test_release(tmp_path): devops_config(
sut = build_devops(
{ {
"release_type": "MINOR", "release_type": "MINOR",
"release_current_version": "1.2.3", "release_current_branch": "some-feature-branch",
"release_current_branch": "main",
} }
),
Version.from_str("1.3.1-SNAPSHOT"),
) )
assert sut.mixins[MixinType.RELEASE] assert not sut.is_valid()
assert sut.is_valid()