From 238b0304b66336ce7f052d7163f08551b8eacf4c Mon Sep 17 00:00:00 2001 From: bom Date: Wed, 22 Feb 2023 12:05:34 +0100 Subject: [PATCH] Implement prepare for ReleaseMixin --- release_mixin.py | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/release_mixin.py b/release_mixin.py index 9b8a5d2..c78ec1f 100644 --- a/release_mixin.py +++ b/release_mixin.py @@ -1,15 +1,15 @@ - 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 +from services import InitReleaseService, PrepareReleaseService, TagAndPushReleaseService +from git_repository import GitRepository - -def create_release_mixin_config(config, release_type, commit, file): - config.update({'ReleaseMixin': - {'commit_id': commit, - 'file': file}}) +def create_release_mixin_config(config, release_type, config_file, main_branch): + config.update({'ReleaseMixin': + {'main_branch': main_branch, + 'file': config_file}}) return config @@ -19,14 +19,28 @@ class ReleaseMixin(DevopsBuild): super().__init__(project, config) release_mixin_config = config['ReleaseMixin'] self.file = release_mixin_config['file'] + self.main_branch = release_mixin_config['main_branch'] self.version_repo = VersionRepository(self.file) def init(self): # returns versions - release_and_bump_version = InitReleaseService(self.version_repo).get_version() - return release_and_bump_version + 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 - def prepare(self, version: Version): # writes into files, add. commit - pass + def prepare(self, release_version: Version, bump_version: Version): # writes into files, add. commit + 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()}') + def tag_and_push(): # correct tag and do push pass