Compare commits

...

3 commits

Author SHA1 Message Date
9bde301ee4 Use release class
Create it out of the given release_repo.
Thus simplifying the call tree as we only access the release_repo in the
service.
2023-02-28 15:04:14 +01:00
39d60f6854 WIP Remove prepare release service 2023-02-28 14:55:51 +01:00
802dd7d57b WIP Remove prepare release service 2023-02-28 14:55:41 +01:00
3 changed files with 23 additions and 33 deletions

View file

@ -43,6 +43,5 @@ def initialize(project):
def release(project):
build = get_devops_build(project)
build.init_release()
build.prepare_release()
build.tag_and_push_release()

View file

@ -2,8 +2,8 @@ import copy
from ddadevops import DevopsBuild
from ddadevops import execute
from ddadevops import gopass_field_from_path, gopass_password_from_path
from infrastructure import VersionRepository, GitApi
from services import InitReleaseService, PrepareReleaseService, TagAndPushReleaseService
from infrastructure import GitApi, ReleaseRepository, ReleaseTypeRepository, VersionRepository
from services import PrepareReleaseService, TagAndPushReleaseService
from domain import ReleaseType, Version
def create_release_mixin_config(config_file, main_branch) -> dict:
@ -27,25 +27,23 @@ class ReleaseMixin(DevopsBuild):
release_mixin_config = config['ReleaseMixin']
self.config_file = release_mixin_config['config_file']
self.main_branch = release_mixin_config['main_branch']
self.version_repo = VersionRepository(self.config_file)
self.git_api = GitApi()
self.release_type_repo = ReleaseTypeRepository(self.git_api)
self.version_repo = VersionRepository(self.config_file)
self.release_repo = ReleaseRepository(self.version_repo, self.release_type_repo, self.main_branch)
self.release_version = None
self.bump_version = None
self.commit_string = None
def init_release(self):
init_service = InitReleaseService(self.version_repo)
self.release_version = init_service.create_release_version(self.commit_string)
self.bump_version = self.release_version.create_bump_version()
def prepare_release(self):
prepare_release_service = PrepareReleaseService(self.version_repo, self.git_api, self.config_file, self.main_branch)
prepare_release_service = PrepareReleaseService(self.release_repo)
if self.release_version is None or self.bump_version is None:
raise Exception('prepare_release was called before init_release')
# prepare_release_service.run_tests() # not implemented
prepare_release_service.write_and_commit_release(self.release_version)
prepare_release_service.write_and_commit_bump(self.bump_version)
prepare_release_service.write_and_commit_release()
prepare_release_service.write_and_commit_bump()
def tag_and_push_release(self):
tag_and_push_release_service = TagAndPushReleaseService(self.git_api)

View file

@ -1,36 +1,29 @@
from pathlib import Path
from infrastructure import ReleaseRepository, GitApi
from infrastructure import VersionRepository, ReleaseRepository, GitApi
from domain import Version, ReleaseType
# Todo: can be removed
class InitReleaseService():
def __init__(self, release_repo: ReleaseRepository):
self.release_repo = release_repo
def get_version(self):
return self.release_repo.get_release().version
class PrepareReleaseService():
def __init__(self, release_repo: ReleaseRepository):
self.release_repo = release_repo
self.release = release_repo.get_release()
self.git_api = GitApi()
self.main_branch = None
def __write_and_commit_version(self, version: Version, commit_message: str):
if self.main_branch != self.git_repository.get_current_branch():
if self.main_branch != self.git_api.get_current_branch():
raise Exception('Trying to release while not on main branch')
self.version_repository.write_file(version.get_version_string())
self.git_repository.add_file(self.config_file)
self.git_repository.commit(commit_message)
self.release_repo.version_repository.write_file(version.get_version_string())
self.git_api.add_file(self.release_repo.version_repository.file)
self.git_api.commit(commit_message)
def write_and_commit_release(self, release_version: Version):
self.__write_and_commit_version(release_version, commit_message=f'Release {release_version.get_version_string()}')
def write_and_commit_release(self):
self.__write_and_commit_version(self.release.release_version(), commit_message=f'Release {self.release.release_version().get_version_string()}')
def write_and_commit_bump(self, bump_version: Version):
self.__write_and_commit_version(bump_version, commit_message=f'Version bump')
def write_and_commit_bump(self):
self.__write_and_commit_version(self.release.bump_version(), commit_message=f'Version bump')
class TagAndPushReleaseService():
@ -41,6 +34,6 @@ class TagAndPushReleaseService():
annotation = 'v' + release_version.get_version_string()
message = 'Release ' + annotation
self.git_api.tag_annotated(annotation, message, 1)
# self.git_repository.push()
# self.git_api.push()