Update release_mixin methods

This commit is contained in:
erik 2023-02-22 14:11:39 +01:00
parent a07c23434e
commit 7d7347653e

View file

@ -6,12 +6,19 @@ from version_repository import VersionRepository
from services import InitReleaseService, PrepareReleaseService, TagAndPushReleaseService
from git_repository import GitRepository
def create_release_mixin_config(config, release_type, config_file, main_branch):
config.update({'ReleaseMixin':
{'main_branch': main_branch,
'file': config_file}})
def create_release_mixin_config(config_file, main_branch) -> dict:
config = {}
config.update(
{'ReleaseMixin':
{'main_branch': main_branch,
'file': config_file}})
return config
def add_versions(config, release_version, bump_version) -> dict:
config['ReleaseMixin'].update(
{'release_version': release_version,
'bump_version': bump_version})
return config
class ReleaseMixin(DevopsBuild):
@ -21,40 +28,40 @@ class ReleaseMixin(DevopsBuild):
self.file = release_mixin_config['file']
self.main_branch = release_mixin_config['main_branch']
self.version_repo = VersionRepository(self.file)
self.release_version = None
self.bump_version = None
def init(self): # returns versions
def init(self):
init_service = InitReleaseService(self.version_repo)
release_version = init_service.create_release_version()
bump_version = release_version.create_bump_version()
return release_version, bump_version
self.release_version = init_service.create_release_version()
self.bump_version = self.release_version.create_bump_version()
return self.release_version, self.bump_version
def prepare(self, release_version: Version, bump_version: Version): # writes into files, add. commit
def prepare(self, version):
git_repository = GitRepository()
if self.main_branch not in git_repository.get_current_branch():
raise Exception('Trying to release while not on main branch')
self.version_repo.write_file(release_version.get_version_string())
git_repository.add_file(self.file)
git_repository.commit(f'Release {release_version.get_version_string()}')
self.version_repo.write_file(bump_version.get_version_string())
git_repository.add_file(self.file)
git_repository.commit(f'Version bump {bump_version.get_version_string()}')
self.version_repo.write_file(version.get_version_string())
git_repository.add_file(self.file)
match version.release_type:
case None:
raise Exception('Release type not set but trying to commit.')
case ReleaseType.BUMP:
git_repository.commit(f'Version bump')
case _:
git_repository.commit(f'Release {version.get_version_string()}')
def tag_and_push(): # correct tag and do push
pass
def tag_and_push(self, version):
git_repository = GitRepository()
match version.release_type:
case None:
raise Exception('Release type not set but trying to tag and push.')
case ReleaseType.BUMP:
annotation = 'v' + version.get_version_string()
message = 'Version bump'
case _:
annotation = 'v' + self.release_version.get_version_string()
message = 'Release' + annotation
git_repository.tag_annotated(annotation, message)
git_repository.push()