Compare commits
7 commits
2fe05b0e06
...
4a23b0b800
Author | SHA1 | Date | |
---|---|---|---|
4a23b0b800 | |||
e7152301dd | |||
fa6beebc4e | |||
c58ddf70da | |||
1ce4bd9c55 | |||
992c72bda3 | |||
0df4db54d8 |
7 changed files with 93 additions and 94 deletions
|
@ -16,9 +16,14 @@ class GitRepository():
|
|||
inst.latest_commit = commit_string
|
||||
return inst
|
||||
|
||||
def get_latest_n_commits(self, n: int):
|
||||
self.system_repository.run_checked('git', 'log', '--oneline', '--format="%s %b"', f'-n {n}')
|
||||
return self.system_repository.stdout
|
||||
|
||||
def get_latest_commit(self):
|
||||
self.system_repository.run_checked('git', 'log', '--oneline', '--format="%s %b"', '-n 1')
|
||||
self.latest_commit = " ".join(self.system_repository.stdout) # returns a list of strings otherwise
|
||||
output = self.get_latest_n_commits(1)
|
||||
self.latest_commit = " ".join(output) # returns a list of strings otherwise
|
||||
return self.latest_commit
|
||||
|
||||
def get_release_type_from_latest_commit(self):
|
||||
if self.latest_commit is None:
|
||||
|
@ -38,6 +43,9 @@ class GitRepository():
|
|||
def tag_annotated(self, annotation: str, message: str):
|
||||
self.system_repository.run_checked('git', 'tag', '-a', annotation, '-m', message)
|
||||
|
||||
def tag_annotated(self, annotation: str, message: str, count: int):
|
||||
self.system_repository.run_checked('git', 'tag', '-a', annotation, '-m', message, f'HEAD~{count}')
|
||||
|
||||
def get_current_branch(self):
|
||||
self.system_repository.run_checked('git', 'branch', '--show-current')
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ def create_release_mixin_config(config_file, main_branch) -> dict:
|
|||
config.update(
|
||||
{'ReleaseMixin':
|
||||
{'main_branch': main_branch,
|
||||
'file': config_file}})
|
||||
'config_file': config_file}})
|
||||
return config
|
||||
|
||||
def add_versions(config, release_version, bump_version) -> dict:
|
||||
|
@ -27,44 +27,28 @@ class ReleaseMixin(DevopsBuild):
|
|||
def __init__(self, project, config):
|
||||
super().__init__(project, config)
|
||||
release_mixin_config = config['ReleaseMixin']
|
||||
self.file = release_mixin_config['file']
|
||||
self.config_file = release_mixin_config['config_file']
|
||||
self.main_branch = release_mixin_config['main_branch']
|
||||
self.version_repo = VersionRepository(self.file)
|
||||
self.version_repo = VersionRepository(self.config_file)
|
||||
self.git_repo = GitRepository()
|
||||
self.release_version = None
|
||||
self.bump_version = None
|
||||
self.commit_string = None
|
||||
|
||||
def init(self):
|
||||
def init_release(self):
|
||||
init_service = InitReleaseService(self.version_repo)
|
||||
self.release_version = init_service.create_release_version(self.commit_string)
|
||||
release_version_copy = copy.deepcopy(self.release_version) # otherwise we'll modify the release_version again
|
||||
self.bump_version = release_version_copy.create_bump_version()
|
||||
self.bump_version = self.release_version.create_bump_version()
|
||||
|
||||
def prepare(self, version):
|
||||
git_repository = GitRepository()
|
||||
if self.main_branch not in git_repository.get_current_branch():
|
||||
raise Exception('Trying to release while not on main branch')
|
||||
def prepare_release(self):
|
||||
prepare_release_service = PrepareReleaseService(self.version_repo, self.config_file, self.main_branch)
|
||||
if self.release_version is None or self.bump_version is None:
|
||||
raise Exception('prepare_release was called before init_release')
|
||||
|
||||
self.version_repo.write_file(version.get_version_string())
|
||||
git_repository.add_file(self.file)
|
||||
match version.release_type:
|
||||
case None:
|
||||
raise Exception('Release type not set but trying to commit.')
|
||||
case ReleaseType.BUMP:
|
||||
git_repository.commit(f'Version bump')
|
||||
case _:
|
||||
git_repository.commit(f'Release {version.get_version_string()}')
|
||||
# prepare_release_service.run_tests() # not implemented
|
||||
prepare_release_service.write_and_commit_release(self.release_version)
|
||||
prepare_release_service.write_and_commit_bump(self.bump_version)
|
||||
|
||||
def tag_and_push(self, version):
|
||||
git_repository = GitRepository()
|
||||
match version.release_type:
|
||||
case None:
|
||||
raise Exception('Release type not set but trying to tag and push.')
|
||||
case ReleaseType.BUMP:
|
||||
annotation = 'v' + version.get_version_string()
|
||||
message = 'Version bump'
|
||||
case _:
|
||||
annotation = 'v' + self.release_version.get_version_string()
|
||||
message = 'Release' + annotation
|
||||
git_repository.tag_annotated(annotation, message)
|
||||
git_repository.push()
|
||||
def tag_and_push(self):
|
||||
tag_and_push_release_service = TagAndPushReleaseService(self.git_repo)
|
||||
tag_and_push_release_service.tag_and_push_release(self.release_version)
|
||||
|
|
53
services.py
53
services.py
|
@ -1,3 +1,4 @@
|
|||
from pathlib import Path
|
||||
from version_repository import VersionRepository
|
||||
from release_type import ReleaseType
|
||||
from git_repository import GitRepository
|
||||
|
@ -16,45 +17,53 @@ class InitReleaseService():
|
|||
else:
|
||||
return GitRepository.create_from_commit_string(commit_string).get_release_type_from_latest_commit()
|
||||
|
||||
def get_version(self, release_type):
|
||||
return self.version_repo.get_version(release_type)
|
||||
def get_version(self):
|
||||
return self.version_repo.get_version()
|
||||
|
||||
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()
|
||||
version = self.get_version().create_release_version(release_type)
|
||||
return version
|
||||
|
||||
def create_bump_version(self):
|
||||
version = self.get_version(ReleaseType.BUMP).create_bump_version()
|
||||
version = self.get_version().create_bump_version()
|
||||
return version
|
||||
|
||||
|
||||
|
||||
class PrepareReleaseService():
|
||||
|
||||
def __init__(self, version_repo: VersionRepository):
|
||||
self.version_repo = version_repo
|
||||
|
||||
def __init__(self, version_repository: VersionRepository, git_repository: GitRepository, config_file: Path, main_branch: str):
|
||||
self.version_repository = version_repository
|
||||
self.git_repository = git_repository
|
||||
self.main_branch = main_branch
|
||||
self.config_file = config_file
|
||||
|
||||
def run_tests(self): # maybe auto?
|
||||
pass
|
||||
raise NotImplementedError
|
||||
|
||||
def prepare_release(self, version: Version):
|
||||
# self.version_repo.write_file(version.get_version_string()) # side effect
|
||||
pass
|
||||
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')
|
||||
|
||||
def prepare_bump(self, version: Version):
|
||||
# self.version_repo.write_file(version.get_version_string()) # side effect
|
||||
pass
|
||||
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()}')
|
||||
|
||||
# write
|
||||
|
||||
|
||||
# add
|
||||
# commit
|
||||
pass
|
||||
def write_and_commit_bump(self, bump_version: Version):
|
||||
self.__write_and_commit_version(bump_version, commit_message=f'Version bump')
|
||||
|
||||
class TagAndPushReleaseService():
|
||||
pass
|
||||
|
||||
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)
|
||||
self.git_repository.push()
|
||||
|
||||
|
||||
|
|
|
@ -34,10 +34,10 @@ class MyBuild(ReleaseMixin):
|
|||
def initialize(project, CONFIG_FILE):
|
||||
project.build_depends_on('ddadevops>=3.1.2')
|
||||
config = create_release_mixin_config(CONFIG_FILE, MAIN_BRANCH)
|
||||
config.update({'stage': STAGE})
|
||||
config.update({'module': MODULE})
|
||||
config.update({'project_root_path': PROJECT_ROOT_PATH})
|
||||
config.update({'build_dir_name': BUILD_DIR_NAME})
|
||||
config.update({'stage': STAGE,
|
||||
'module': MODULE,
|
||||
'project_root_path': PROJECT_ROOT_PATH,
|
||||
'build_dir_name': BUILD_DIR_NAME})
|
||||
build = MyBuild(project, config)
|
||||
return build
|
||||
|
||||
|
@ -56,7 +56,7 @@ def test_release_mixin(tmp_path):
|
|||
# init
|
||||
build = initialize(project, CONFIG_FILE)
|
||||
build.commit_string = "MAJOR bla"
|
||||
build.init()
|
||||
build.init_release()
|
||||
release_version = build.release_version
|
||||
|
||||
# test
|
||||
|
|
|
@ -22,33 +22,33 @@ from version_repository import VersionRepository
|
|||
from release_type import ReleaseType
|
||||
|
||||
def test_version():
|
||||
version = Version([1, 2, 3], ReleaseType.SNAPSHOT)
|
||||
version = Version([1, 2, 3])
|
||||
|
||||
version.increment()
|
||||
version.increment(ReleaseType.SNAPSHOT)
|
||||
assert version.get_version_string() == "1.2.3-SNAPSHOT"
|
||||
assert version.version_list == [1, 2, 3]
|
||||
assert version.is_snapshot
|
||||
|
||||
version = Version([1, 2, 3], ReleaseType.BUMP)
|
||||
version.increment()
|
||||
version = Version([1, 2, 3])
|
||||
version.increment(ReleaseType.BUMP)
|
||||
assert version.get_version_string() == "1.2.4-SNAPSHOT"
|
||||
assert version.version_list == [1, 2, 4]
|
||||
assert version.is_snapshot
|
||||
|
||||
version = Version([1, 2, 3], ReleaseType.PATCH)
|
||||
version.increment()
|
||||
version = Version([1, 2, 3])
|
||||
version.increment(ReleaseType.PATCH)
|
||||
assert version.get_version_string() == "1.2.4"
|
||||
assert version.version_list == [1, 2, 4]
|
||||
assert not version.is_snapshot
|
||||
|
||||
version = Version([1, 2, 3], ReleaseType.MINOR)
|
||||
version.increment()
|
||||
version = Version([1, 2, 3])
|
||||
version.increment(ReleaseType.MINOR)
|
||||
assert version.get_version_string() == "1.3.0"
|
||||
assert version.version_list == [1, 3, 0]
|
||||
assert not version.is_snapshot
|
||||
|
||||
version = Version([1, 2, 3], ReleaseType.MAJOR)
|
||||
version.increment()
|
||||
version = Version([1, 2, 3])
|
||||
version.increment(ReleaseType.MAJOR)
|
||||
assert version.get_version_string() == "2.0.0"
|
||||
assert version.version_list == [2, 0, 0]
|
||||
assert not version.is_snapshot
|
||||
|
@ -65,8 +65,8 @@ def test_gradle(tmp_path):
|
|||
|
||||
# test
|
||||
repo = VersionRepository(f)
|
||||
version = repo.get_version(ReleaseType.SNAPSHOT)
|
||||
version = version.create_release_version()
|
||||
version = repo.get_version()
|
||||
version = version.create_release_version(ReleaseType.SNAPSHOT)
|
||||
repo.write_file(version.get_version_string())
|
||||
|
||||
# check
|
||||
|
@ -83,8 +83,8 @@ def test_json(tmp_path):
|
|||
|
||||
# test
|
||||
repo = VersionRepository(f)
|
||||
version = repo.get_version(ReleaseType.SNAPSHOT)
|
||||
version = version.create_release_version()
|
||||
version = repo.get_version()
|
||||
version = version.create_release_version(ReleaseType.SNAPSHOT)
|
||||
repo.write_file(version.get_version_string())
|
||||
|
||||
# check
|
||||
|
@ -101,8 +101,8 @@ def test_clojure(tmp_path):
|
|||
|
||||
# test
|
||||
repo = VersionRepository(f)
|
||||
version = repo.get_version(ReleaseType.SNAPSHOT)
|
||||
version = version.create_release_version()
|
||||
version = repo.get_version()
|
||||
version = version.create_release_version(ReleaseType.SNAPSHOT)
|
||||
repo.write_file(version.get_version_string())
|
||||
|
||||
# check
|
||||
|
@ -119,8 +119,8 @@ def test_python(tmp_path):
|
|||
|
||||
# test
|
||||
repo = VersionRepository(f)
|
||||
version = repo.get_version(ReleaseType.SNAPSHOT)
|
||||
version = version.create_release_version()
|
||||
version = repo.get_version()
|
||||
version = version.create_release_version(ReleaseType.SNAPSHOT)
|
||||
repo.write_file(version.get_version_string())
|
||||
|
||||
# check
|
||||
|
|
18
version.py
18
version.py
|
@ -3,15 +3,14 @@ from file_handlers import FileHandler
|
|||
|
||||
class Version():
|
||||
|
||||
def __init__(self, version_list: list, release_type: ReleaseType):
|
||||
def __init__(self, version_list: list):
|
||||
self.version_list = version_list
|
||||
self.release_type = release_type
|
||||
self.version_string = None
|
||||
self.is_snapshot = None
|
||||
|
||||
def increment(self):
|
||||
def increment(self, release_type: ReleaseType):
|
||||
self.is_snapshot = False
|
||||
match self.release_type:
|
||||
match release_type:
|
||||
case ReleaseType.BUMP:
|
||||
self.is_snapshot = True
|
||||
self.version_list[ReleaseType.PATCH.value] += 1
|
||||
|
@ -35,15 +34,14 @@ class Version():
|
|||
self.version_string += "-SNAPSHOT"
|
||||
return self.version_string
|
||||
|
||||
def create_release_version(self):
|
||||
release_version = Version(self.version_list, self.release_type)
|
||||
def create_release_version(self, release_type: ReleaseType):
|
||||
release_version = Version(self.version_list.copy())
|
||||
release_version.is_snapshot = self.is_snapshot
|
||||
release_version.increment()
|
||||
release_version.increment(release_type)
|
||||
return release_version
|
||||
|
||||
def create_bump_version(self):
|
||||
bump_version = Version(self.version_list, self.release_type)
|
||||
bump_version = Version(self.version_list.copy())
|
||||
bump_version.is_snapshot = self.is_snapshot
|
||||
bump_version.release_type = ReleaseType.BUMP
|
||||
bump_version.increment()
|
||||
bump_version.increment(ReleaseType.BUMP)
|
||||
return bump_version
|
||||
|
|
|
@ -21,11 +21,11 @@ class VersionRepository():
|
|||
version_list, is_snapshot = self.file_handler.parse()
|
||||
return version_list, is_snapshot
|
||||
|
||||
def get_version(self, release_type):
|
||||
def get_version(self):
|
||||
|
||||
self.file_handler = self.load_file()
|
||||
version_list, is_snapshot = self.parse_file()
|
||||
version = Version(version_list, release_type)
|
||||
version = Version(version_list)
|
||||
version.is_snapshot = is_snapshot
|
||||
|
||||
return version
|
||||
|
|
Loading…
Reference in a new issue