2023-02-22 15:25:18 +00:00
|
|
|
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
|
2023-02-28 13:55:51 +00:00
|
|
|
from infrastructure import GitApi, ReleaseRepository, ReleaseTypeRepository, VersionRepository
|
|
|
|
from services import PrepareReleaseService, TagAndPushReleaseService
|
2023-02-24 09:14:26 +00:00
|
|
|
from domain import ReleaseType, Version
|
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)
|
2023-02-22 10:34:27 +00:00
|
|
|
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-28 12:25:47 +00:00
|
|
|
self.git_api = GitApi()
|
2023-02-28 13:55:51 +00:00
|
|
|
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)
|
2023-02-16 13:21:27 +00:00
|
|
|
|
2023-02-23 14:07:22 +00:00
|
|
|
def prepare_release(self):
|
2023-02-28 13:55:51 +00:00
|
|
|
prepare_release_service = PrepareReleaseService(self.release_repo)
|
2023-02-23 14:07:22 +00:00
|
|
|
# prepare_release_service.run_tests() # not implemented
|
2023-02-28 13:55:51 +00:00
|
|
|
prepare_release_service.write_and_commit_release()
|
|
|
|
prepare_release_service.write_and_commit_bump()
|
2023-02-22 13:11:39 +00:00
|
|
|
|
2023-02-23 15:31:33 +00:00
|
|
|
def tag_and_push_release(self):
|
2023-02-28 12:25:47 +00:00
|
|
|
tag_and_push_release_service = TagAndPushReleaseService(self.git_api)
|
2023-02-23 14:33:34 +00:00
|
|
|
tag_and_push_release_service.tag_and_push_release(self.release_version)
|