dda-devops-build/devops_test.py

52 lines
No EOL
1.5 KiB
Python

from enum import Enum
from file_handlers import FileHandler
def init_project():
# validate_values()
version = Version.from_file('build.gradle')
version.increment(ReleaseLevel.SNAPSHOT)
version.write()
def prepare_release():
pass
def release_in_git():
pass
class ReleaseLevel(Enum):
MAJOR = 0
MINOR = 1
PATCH = 2
SNAPSHOT = 3
class Version():
def __init__(self, version, is_snapshot):
self.version = version
self.is_snapshot = is_snapshot
@classmethod
def from_file(cls, config_file_path):
file_handler = FileHandler.from_file_path(config_file_path)
return cls(file_handler.parse())
def increment(self, level: ReleaseLevel):
self.is_snapshot = False
match level:
case ReleaseLevel.SNAPSHOT:
self.is_snapshot = True
case ReleaseLevel.PATCH:
self.version[ReleaseLevel.PATCH.value] += 1
case ReleaseLevel.MINOR:
self.version[ReleaseLevel.PATCH.value] = 0
self.version[ReleaseLevel.MINOR.value] += 1
case ReleaseLevel.MAJOR:
self.version[ReleaseLevel.PATCH.value] = 0
self.version[ReleaseLevel.MINOR.value] = 0
self.version[ReleaseLevel.MAJOR.value] += 1
def get(self) -> str:
version_string = ".".join([str(x) for x in self.version])
if self.is_snapshot:
version_string += "-SNAPSHOT"
return version_string