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 {
release_type
release_main_branch
release_current_branch
release_type
version
}

View file

@ -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)

View file

@ -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"))
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()
self.release_config_file = input.get("release_config_file", "./project.clj")
self.version = 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

View file

@ -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

View file

@ -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)

View file

@ -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()