dda-devops-build/release_mixin.py

65 lines
2.6 KiB
Python
Raw Normal View History

import copy
2023-02-16 13:21:27 +00:00
from ddadevops import DevopsBuild
from ddadevops import execute
from ddadevops import gopass_field_from_path, gopass_password_from_path
from version import Version
from version_repository import VersionRepository
2023-02-22 11:05:34 +00:00
from services import InitReleaseService, PrepareReleaseService, TagAndPushReleaseService
from git_repository import GitRepository
2023-02-22 14:14:48 +00:00
from release_type import ReleaseType
2023-02-16 13:21:27 +00:00
2023-02-22 13:11:39 +00:00
def create_release_mixin_config(config_file, main_branch) -> dict:
config = {}
config.update(
{'ReleaseMixin':
{'main_branch': main_branch,
2023-02-23 13:23:32 +00:00
'config_file': config_file}})
2023-02-16 13:21:27 +00:00
return config
2023-02-22 13:11:39 +00:00
def add_versions(config, release_version, bump_version) -> dict:
config['ReleaseMixin'].update(
{'release_version': release_version,
'bump_version': bump_version})
return config
2023-02-16 13:21:27 +00:00
class ReleaseMixin(DevopsBuild):
def __init__(self, project, config):
super().__init__(project, config)
release_mixin_config = config['ReleaseMixin']
2023-02-23 13:23:32 +00:00
self.config_file = release_mixin_config['config_file']
2023-02-22 11:05:34 +00:00
self.main_branch = release_mixin_config['main_branch']
2023-02-23 13:23:32 +00:00
self.version_repo = VersionRepository(self.config_file)
self.git_repo = GitRepository()
2023-02-22 13:11:39 +00:00
self.release_version = None
self.bump_version = None
self.commit_string = None
2023-02-16 13:21:27 +00:00
def init_release(self):
2023-02-22 11:05:34 +00:00
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()
2023-02-22 11:05:34 +00:00
def prepare_release(self):
prepare_release_service = PrepareReleaseService(self.version_repo, self.config_file, self.main_branch)
if self.release_version is None or self.bump_version is None:
raise Exception('prepare_release was called before init_release')
2023-02-22 11:05:34 +00:00
# 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)
2023-02-22 13:11:39 +00:00
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()