2023-02-23 14:07:22 +00:00
|
|
|
from pathlib import Path
|
2023-02-24 10:39:38 +00:00
|
|
|
from infrastructure import ReleaseRepository
|
2023-02-24 09:31:04 +00:00
|
|
|
from domain import Version, ReleaseType
|
2023-02-22 08:59:16 +00:00
|
|
|
|
2023-02-16 15:55:01 +00:00
|
|
|
|
2023-02-24 10:39:38 +00:00
|
|
|
# Todo: can be removed
|
|
|
|
class InitReleaseService():
|
2023-02-16 15:55:01 +00:00
|
|
|
|
2023-02-24 10:39:38 +00:00
|
|
|
def __init__(self, release_repo: ReleaseRepository):
|
|
|
|
self.release_repo = release_repo
|
|
|
|
|
2023-02-23 13:38:54 +00:00
|
|
|
def get_version(self):
|
2023-02-24 10:39:38 +00:00
|
|
|
return self.release_repo.get_release().version
|
2023-02-22 10:33:44 +00:00
|
|
|
|
2023-02-20 14:50:58 +00:00
|
|
|
|
2023-02-22 10:33:44 +00:00
|
|
|
class PrepareReleaseService():
|
2023-02-16 15:55:01 +00:00
|
|
|
|
2023-02-24 10:39:38 +00:00
|
|
|
def __init__(self, release_repo: ReleaseRepository):
|
|
|
|
self.release_repo = release_repo
|
2023-02-23 14:07:22 +00:00
|
|
|
|
|
|
|
def __write_and_commit_version(self, version: Version, commit_message: str):
|
|
|
|
if self.main_branch != self.git_repository.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)
|
|
|
|
|
|
|
|
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_bump(self, bump_version: Version):
|
|
|
|
self.__write_and_commit_version(bump_version, commit_message=f'Version bump')
|
2023-02-16 15:55:01 +00:00
|
|
|
|
|
|
|
class TagAndPushReleaseService():
|
2023-02-23 14:33:34 +00:00
|
|
|
|
|
|
|
def __init__(self, git_repository: GitRepository):
|
|
|
|
self.git_repository = git_repository
|
|
|
|
|
|
|
|
def tag_and_push_release(self, release_version: Version):
|
|
|
|
annotation = 'v' + release_version.get_version_string()
|
|
|
|
message = 'Release ' + annotation
|
|
|
|
self.git_repository.tag_annotated(annotation, message, 1)
|
2023-02-23 15:34:22 +00:00
|
|
|
# self.git_repository.push()
|
2023-02-23 14:33:34 +00:00
|
|
|
|
2023-02-16 15:55:01 +00:00
|
|
|
|