dda-devops-build/version.py

48 lines
1.8 KiB
Python
Raw Normal View History

2023-02-20 15:50:12 +00:00
from release_type import ReleaseType
from file_handlers import FileHandler
2023-02-08 09:57:40 +00:00
2023-02-08 10:37:41 +00:00
class Version():
2023-02-08 10:22:55 +00:00
def __init__(self, version_list: list):
2023-02-20 16:04:50 +00:00
self.version_list = version_list
2023-02-20 13:24:55 +00:00
self.version_string = None
2023-02-21 15:14:47 +00:00
self.is_snapshot = None
2023-02-09 12:20:42 +00:00
def increment(self, release_type: ReleaseType):
2023-02-08 11:37:00 +00:00
self.is_snapshot = False
match release_type:
2023-02-20 15:21:02 +00:00
case ReleaseType.BUMP:
self.is_snapshot = True
self.version_list[ReleaseType.PATCH.value] += 1
2023-02-20 13:24:55 +00:00
case ReleaseType.SNAPSHOT:
2023-02-08 11:37:00 +00:00
self.is_snapshot = True
2023-02-20 13:24:55 +00:00
case ReleaseType.PATCH:
self.version_list[ReleaseType.PATCH.value] += 1
case ReleaseType.MINOR:
self.version_list[ReleaseType.PATCH.value] = 0
self.version_list[ReleaseType.MINOR.value] += 1
case ReleaseType.MAJOR:
self.version_list[ReleaseType.PATCH.value] = 0
self.version_list[ReleaseType.MINOR.value] = 0
self.version_list[ReleaseType.MAJOR.value] += 1
2023-02-21 15:14:47 +00:00
case None:
2023-02-21 14:52:09 +00:00
raise Exception("Release Type was not set!")
2023-02-08 11:37:00 +00:00
def get_version_string(self) -> str:
2023-02-20 13:24:55 +00:00
self.version_string = ".".join([str(x) for x in self.version_list])
2023-02-08 11:37:00 +00:00
if self.is_snapshot:
2023-02-20 15:21:02 +00:00
self.version_string += "-SNAPSHOT"
2023-02-20 16:04:50 +00:00
return self.version_string
2023-02-21 14:52:09 +00:00
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_type)
return release_version
2023-02-21 14:52:09 +00:00
def create_bump_version(self):
bump_version = Version(self.version_list.copy())
bump_version.is_snapshot = self.is_snapshot
bump_version.increment(ReleaseType.BUMP)
return bump_version