dda-devops-build/version.py
erik 88c3acb73c WIP Create version repo in services with classmethod
The goal is to create a single version_repo object for each
file loaded. In that way we may avoid loading the file for loading
and writing.
2023-02-20 13:33:28 +01:00

48 lines
No EOL
1.4 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.to_file()
print(version.get())
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
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