terraformDummyRepo/devops_test.py
2023-02-08 11:52:15 +01:00

55 lines
No EOL
1.5 KiB
Python

import json
from enum import Enum
def init_project():
# validate_values()
version = Version('package.json')
version.parse()
version.increment(ReleaseLevel.PATCH)
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, config_file_path):
self.version = "0.0.0"
self.config_file_path = config_file_path
def parse(self):
if self.config_file_path.split('.')[-1] == 'json':
self.__parse_json()
def __parse_json(self):
with open(self.config_file_path, 'r') as json_file:
json_data = json.load(json_file)
self.version = json_data['version']
def increment(self, level: ReleaseLevel):
match level:
case ReleaseLevel.SNAPSHOT:
if "-SNAPSHOT" not in self.version:
self.version = self.version + "-SNAPSHOT"
case ReleaseLevel.PATCH:
split_version = self.version.split('.')
patch_version = int(split_version[ReleaseLevel.PATCH.value])
self.version = split_version[:ReleaseLevel.PATCH.value] + str(patch_version + 1)
print(self.version)
case ReleaseLevel.MINOR:
pass
case ReleaseLevel.MAJOR:
pass
def get(self) -> str:
return self.version