Compare commits

...

3 commits

Author SHA1 Message Date
1112b1ad49 WIP Implement prepare and tagandpush services 2023-02-22 11:34:27 +01:00
821e06f82a Pass VersionRepo to InitReleaseService
Update Tests.
2023-02-22 11:33:44 +01:00
1d2cb7882e Fix test 2023-02-22 10:59:35 +01:00
4 changed files with 61 additions and 26 deletions

View file

@ -21,9 +21,14 @@ def initialize(project):
config = create_release_mixin_config(CONFIG_FILE, COMMIT_ID)
build = MyBuild(project, config)
build.init()
build = MyBuild(project, config)
release_version, bump_version = build.init()
build.prepare()
build.tag_and_push()
@task

View file

@ -3,6 +3,7 @@ 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
def create_release_mixin_config(config, release_type, commit, file):
@ -16,14 +17,23 @@ class ReleaseMixin(DevopsBuild):
def __init__(self, project, config):
super().__init__(project, config)
release_mixin_config = config['ReleaseMixin']
self.commit_id = release_mixin_config['commit_id']
release_mixin_config = config['ReleaseMixin']
self.file = release_mixin_config['file']
self.version_repo = VersionRepository(self.file)
def init(self):
release_and_bump_version = InitReleaseService(self.commit_id, self.file).get_version()
def init(self): # returns versions
release_and_bump_version = InitReleaseService(self.version_repo).get_version()
return release_and_bump_version
def prepare(self, version: Version): # writes into files, add. commit
pass
def tag_and_push(): # correct tag and do push
pass

View file

@ -1,12 +1,14 @@
from version_repository import VersionRepository
from release_type import ReleaseType
from git_repository import GitRepository
from version import Version
class InitReleaseService():
def __init__(self, file):
self.file = file
self.version_repo = None
def __init__(self, version_repo: VersionRepository):
if version_repo is None:
raise Exception('VersionRepo was not created. Did you run create_release_version()?')
self.version_repo = version_repo
def __calculate_release_type(self, commit_string = None):
if commit_string is None:
@ -14,27 +16,43 @@ class InitReleaseService():
else:
return GitRepository.create_from_commit_string(commit_string).get_release_type_from_latest_commit()
def get_version(self, release_type):
self.version_repo = VersionRepository(self.file)
def get_version(self, release_type):
return self.version_repo.get_version(release_type)
def create_release_version(self, commit_string = None):
release_type = self.__calculate_release_type(commit_string)
version = self.get_version(release_type).create_release_version()
self.version_repo.write_file(version.get_version_string())
version = self.get_version(release_type).create_release_version()
return version
def create_bump_version(self):
if self.version_repo == None:
raise Exception('VersionRepo was not created. Did you run create_release_version()?')
def create_bump_version(self):
version = self.get_version(ReleaseType.BUMP).create_bump_version()
return version
self.version_repo.write_file(version.get_version_string())
class PrepareReleaseService():
def __init__(self):
self.version_repo
pass
def run_tests(self): # maybe auto?
pass
def prepare_release(self, version: Version):
# self.version_repo.write_file(version.get_version_string()) # side effect
pass
def prepare_bump(self, version: Version):
# self.version_repo.write_file(version.get_version_string()) # side effect
pass
# write
# add
# commit
pass
class TagAndPushReleaseService():

View file

@ -19,6 +19,7 @@ sys.path.append(parent)
from services import InitReleaseService
from release_type import ReleaseType
from version_repository import VersionRepository
def test_init_release_service(tmp_path):
# init
@ -29,11 +30,12 @@ def test_init_release_service(tmp_path):
f = tmp_path / file_name
f.write_text(contents)
release_service = InitReleaseService(f)
release_service.create_release_version(commit_string='Release MINOR')
repo = VersionRepository(f)
release_service = InitReleaseService(repo)
version = release_service.create_release_version(commit_string='Release MINOR')
assert '"version": "123.124.1"' in f.read_text()
assert "123.124.0" in version.get_version_string()
release_service.create_bump_version()
version = release_service.create_bump_version()
assert '"version": "123.124.2-SNAPSHOT"' in f.read_text()
assert "123.123.457-SNAPSHOT" in version.get_version_string()