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
|
2023-02-22 10:34:27 +00:00
|
|
|
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-16 13:21:27 +00:00
|
|
|
|
2023-02-22 11:05:34 +00:00
|
|
|
def create_release_mixin_config(config, release_type, config_file, main_branch):
|
|
|
|
config.update({'ReleaseMixin':
|
|
|
|
{'main_branch': main_branch,
|
|
|
|
'file': config_file}})
|
2023-02-16 13:21:27 +00:00
|
|
|
return config
|
|
|
|
|
|
|
|
|
|
|
|
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-16 13:21:27 +00:00
|
|
|
self.file = release_mixin_config['file']
|
2023-02-22 11:05:34 +00:00
|
|
|
self.main_branch = release_mixin_config['main_branch']
|
2023-02-22 10:34:27 +00:00
|
|
|
self.version_repo = VersionRepository(self.file)
|
2023-02-16 13:21:27 +00:00
|
|
|
|
2023-02-22 10:34:27 +00:00
|
|
|
def init(self): # returns versions
|
2023-02-22 11:05:34 +00:00
|
|
|
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, 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()}')
|
|
|
|
|
2023-02-22 10:34:27 +00:00
|
|
|
|
|
|
|
def tag_and_push(): # correct tag and do push
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-02-16 13:21:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2023-02-16 15:22:11 +00:00
|
|
|
|
2023-02-16 13:21:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|