2023-02-08 10:22:55 +00:00
|
|
|
from enum import Enum
|
2023-02-09 11:38:04 +00:00
|
|
|
from file_handlers import FileHandler
|
2023-02-08 09:57:40 +00:00
|
|
|
|
|
|
|
def init_project():
|
|
|
|
# validate_values()
|
2023-02-20 15:21:02 +00:00
|
|
|
version = Version.from_file('build.gradle')
|
2023-02-20 13:24:55 +00:00
|
|
|
version.increment(ReleaseType.SNAPSHOT)
|
2023-02-09 12:20:42 +00:00
|
|
|
version.to_file()
|
2023-02-09 11:52:58 +00:00
|
|
|
print(version.get())
|
2023-02-08 09:57:40 +00:00
|
|
|
|
|
|
|
def prepare_release():
|
|
|
|
pass
|
|
|
|
|
|
|
|
def release_in_git():
|
|
|
|
pass
|
|
|
|
|
2023-02-20 13:24:55 +00:00
|
|
|
class ReleaseType(Enum):
|
2023-02-08 10:52:15 +00:00
|
|
|
MAJOR = 0
|
|
|
|
MINOR = 1
|
|
|
|
PATCH = 2
|
|
|
|
SNAPSHOT = 3
|
2023-02-20 15:21:02 +00:00
|
|
|
BUMP = None
|
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
|
|
|
|
2023-02-20 13:24:55 +00:00
|
|
|
def __init__(self, version_list, release_type):
|
|
|
|
self.version_list = None
|
|
|
|
self.version_string = None
|
2023-02-20 13:45:15 +00:00
|
|
|
self.is_snapshot = None
|
2023-02-09 12:20:42 +00:00
|
|
|
|
2023-02-20 13:24:55 +00:00
|
|
|
def increment(self, release_type: ReleaseType):
|
2023-02-08 11:37:00 +00:00
|
|
|
self.is_snapshot = False
|
2023-02-20 13:24:55 +00:00
|
|
|
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-08 11:37:00 +00:00
|
|
|
|
2023-02-20 12:47:14 +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 13:24:55 +00:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def create_release_version(cls, version_list, release_type):
|
|
|
|
inst = cls(version_list, release_type)
|
2023-02-20 15:21:02 +00:00
|
|
|
if release_type == ReleaseType.PATCH:
|
|
|
|
inst.is_snapshot = False
|
|
|
|
else:
|
|
|
|
inst.increment(release_type)
|
2023-02-20 13:24:55 +00:00
|
|
|
return inst
|
|
|
|
|
|
|
|
@classmethod
|
2023-02-20 15:21:02 +00:00
|
|
|
def create_bump_version(cls, version_list):
|
|
|
|
inst = cls(version_list, ReleaseType.BUMP)
|
|
|
|
inst.increment(release_type)
|
|
|
|
return inst
|