2023-03-02 15:26:52 +00:00
|
|
|
from infrastructure import ReleaseRepository
|
|
|
|
from infrastructure_api import GitApi
|
2023-03-02 14:08:41 +00:00
|
|
|
from domain import Version, Release
|
2023-02-22 08:59:16 +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-28 13:56:07 +00:00
|
|
|
self.release = release_repo.get_release()
|
|
|
|
self.git_api = GitApi()
|
2023-02-23 14:07:22 +00:00
|
|
|
|
|
|
|
def __write_and_commit_version(self, version: Version, commit_message: str):
|
2023-03-02 13:59:06 +00:00
|
|
|
self.release.validate(self.release_repo.main_branch)
|
|
|
|
|
2023-02-28 13:56:07 +00:00
|
|
|
self.release_repo.version_repository.write_file(version.get_version_string())
|
|
|
|
self.git_api.add_file(self.release_repo.version_repository.file)
|
2023-03-02 13:26:34 +00:00
|
|
|
self.git_api.commit(commit_message)
|
2023-02-23 14:07:22 +00:00
|
|
|
|
2023-02-28 13:56:07 +00:00
|
|
|
def write_and_commit_release(self):
|
2023-03-02 13:26:34 +00:00
|
|
|
self.__write_and_commit_version(self.release.release_version(), commit_message=f'Release v{self.release.release_version().get_version_string()}')
|
2023-02-23 14:07:22 +00:00
|
|
|
|
2023-03-02 13:26:34 +00:00
|
|
|
def write_and_commit_bump(self):
|
|
|
|
self.__write_and_commit_version(self.release.bump_version(), commit_message='Version bump')
|
2023-02-16 15:55:01 +00:00
|
|
|
|
|
|
|
class TagAndPushReleaseService():
|
2023-03-02 13:26:34 +00:00
|
|
|
|
2023-02-28 12:25:47 +00:00
|
|
|
def __init__(self, git_api: GitApi):
|
|
|
|
self.git_api = git_api
|
2023-02-23 14:33:34 +00:00
|
|
|
|
2023-03-02 15:37:42 +00:00
|
|
|
def tag_release(self, release: Release):
|
2023-03-02 14:04:30 +00:00
|
|
|
annotation = 'v' + release.version.get_version_string()
|
2023-02-23 14:33:34 +00:00
|
|
|
message = 'Release ' + annotation
|
2023-02-28 12:25:47 +00:00
|
|
|
self.git_api.tag_annotated(annotation, message, 1)
|
2023-03-02 15:37:42 +00:00
|
|
|
|
|
|
|
def push_release(self):
|
|
|
|
self.git_api.push()
|