Compare commits
9 commits
c137344932
...
156d336314
Author | SHA1 | Date | |
---|---|---|---|
156d336314 | |||
f96733f8b5 | |||
b06728c553 | |||
d539c73318 | |||
1743dce46d | |||
80c0799d1a | |||
e790bc6eee | |||
3d3b26b70e | |||
54c3917ec2 |
4 changed files with 56 additions and 94 deletions
7
release_type.py
Normal file
7
release_type.py
Normal file
|
@ -0,0 +1,7 @@
|
|||
from enum import Enum
|
||||
class ReleaseType(Enum):
|
||||
MAJOR = 0
|
||||
MINOR = 1
|
||||
PATCH = 2
|
||||
SNAPSHOT = 3
|
||||
BUMP = None
|
|
@ -1,29 +1,54 @@
|
|||
from devops_test import Version, ReleaseLevel
|
||||
from pathlib import Path
|
||||
import sys
|
||||
import os
|
||||
|
||||
# getting the name of the directory
|
||||
# where the this file is present.
|
||||
current = os.path.dirname(os.path.realpath(__file__))
|
||||
|
||||
# Getting the parent directory name
|
||||
# where the current directory is present.
|
||||
parent = os.path.dirname(current)
|
||||
|
||||
# adding the parent directory to
|
||||
# the sys.path.
|
||||
sys.path.append(parent)
|
||||
|
||||
# now we can import the module in the parent
|
||||
# directory.
|
||||
|
||||
from version import Version
|
||||
from version_repository import VersionRepository
|
||||
from release_type import ReleaseType
|
||||
|
||||
def test_version():
|
||||
version = Version([1, 2, 3], False)
|
||||
version = Version([1, 2, 3])
|
||||
|
||||
version.increment(ReleaseLevel.SNAPSHOT)
|
||||
assert version.get() == "1.2.3-SNAPSHOT"
|
||||
assert version.version == [1, 2, 3]
|
||||
version.increment(ReleaseType.SNAPSHOT)
|
||||
assert version.get_version_string() == "1.2.3-SNAPSHOT"
|
||||
assert version.version_list == [1, 2, 3]
|
||||
assert version.is_snapshot
|
||||
|
||||
version.increment(ReleaseLevel.PATCH)
|
||||
assert version.get() == "1.2.4"
|
||||
assert version.version == [1, 2, 4]
|
||||
version.increment(ReleaseType.BUMP)
|
||||
assert version.get_version_string() == "1.2.4-SNAPSHOT"
|
||||
assert version.version_list == [1, 2, 4]
|
||||
assert version.is_snapshot
|
||||
|
||||
version.increment(ReleaseType.PATCH)
|
||||
assert version.get_version_string() == "1.2.5"
|
||||
assert version.version_list == [1, 2, 5]
|
||||
assert not version.is_snapshot
|
||||
|
||||
version.increment(ReleaseLevel.SNAPSHOT)
|
||||
assert version.get() == "1.2.4-SNAPSHOT"
|
||||
version.increment(ReleaseLevel.SNAPSHOT)
|
||||
assert version.get() == "1.2.4-SNAPSHOT"
|
||||
version.increment(ReleaseType.SNAPSHOT)
|
||||
assert version.get_version_string() == "1.2.5-SNAPSHOT"
|
||||
version.increment(ReleaseType.SNAPSHOT)
|
||||
assert version.get_version_string() == "1.2.5-SNAPSHOT"
|
||||
|
||||
version.increment(ReleaseLevel.MINOR)
|
||||
assert version.get() == "1.3.0"
|
||||
version.increment(ReleaseType.MINOR)
|
||||
assert version.get_version_string() == "1.3.0"
|
||||
|
||||
version.increment(ReleaseLevel.MAJOR)
|
||||
assert version.get() == "2.0.0"
|
||||
version.increment(ReleaseType.MAJOR)
|
||||
assert version.get_version_string() == "2.0.0"
|
||||
|
||||
|
||||
def test_gradle(tmp_path):
|
||||
|
@ -36,60 +61,9 @@ def test_gradle(tmp_path):
|
|||
f.write_text(contents)
|
||||
|
||||
# test
|
||||
version = Version.from_file(f)
|
||||
version.increment(ReleaseLevel.SNAPSHOT)
|
||||
version.to_file()
|
||||
version_repo = VersionRepository.get(f)
|
||||
version = Version.create_release_version(ReleaseType.SNAPSHOT)
|
||||
version_repo.write_file(version.get_version_string)
|
||||
|
||||
# check
|
||||
assert 'version = "12.4.678-SNAPSHOT"' in f.read_text()
|
||||
|
||||
def test_json(tmp_path):
|
||||
# init
|
||||
file_name = 'config.json'
|
||||
with open(f'test/resources/{file_name}', 'r') as gradle_file:
|
||||
contents = gradle_file.read()
|
||||
|
||||
f = tmp_path / file_name
|
||||
f.write_text(contents)
|
||||
|
||||
# test
|
||||
version = Version.from_file(f)
|
||||
version.increment(ReleaseLevel.SNAPSHOT)
|
||||
version.to_file()
|
||||
|
||||
# check
|
||||
assert '"version": "123.123.456-SNAPSHOT"' in f.read_text()
|
||||
|
||||
def test_clojure(tmp_path):
|
||||
# init
|
||||
file_name = 'config.clj'
|
||||
with open(f'test/resources/{file_name}', 'r') as gradle_file:
|
||||
contents = gradle_file.read()
|
||||
|
||||
f = tmp_path / file_name
|
||||
f.write_text(contents)
|
||||
|
||||
# test
|
||||
version = Version.from_file(f)
|
||||
version.increment(ReleaseLevel.SNAPSHOT)
|
||||
version.to_file()
|
||||
|
||||
# check
|
||||
assert '1.1.3-SNAPSHOT' in f.read_text()
|
||||
|
||||
def test_python(tmp_path):
|
||||
# init
|
||||
file_name = 'config.py'
|
||||
with open(f'test/resources/{file_name}', 'r') as gradle_file:
|
||||
contents = gradle_file.read()
|
||||
|
||||
f = tmp_path / file_name
|
||||
f.write_text(contents)
|
||||
|
||||
# test
|
||||
version = Version.from_file(f)
|
||||
version.increment(ReleaseLevel.SNAPSHOT)
|
||||
version.to_file()
|
||||
|
||||
# check
|
||||
assert '3.1.3-SNAPSHOT' in f.read_text()
|
27
version.py
27
version.py
|
@ -1,30 +1,10 @@
|
|||
from enum import Enum
|
||||
from release_type import ReleaseType
|
||||
from file_handlers import FileHandler
|
||||
|
||||
def init_project():
|
||||
# validate_values()
|
||||
version = Version.from_file('build.gradle')
|
||||
version.increment(ReleaseType.SNAPSHOT)
|
||||
version.to_file()
|
||||
print(version.get())
|
||||
|
||||
def prepare_release():
|
||||
pass
|
||||
|
||||
def release_in_git():
|
||||
pass
|
||||
|
||||
class ReleaseType(Enum):
|
||||
MAJOR = 0
|
||||
MINOR = 1
|
||||
PATCH = 2
|
||||
SNAPSHOT = 3
|
||||
BUMP = None
|
||||
|
||||
class Version():
|
||||
|
||||
def __init__(self, version_list, release_type):
|
||||
self.version_list = None
|
||||
def __init__(self, version_list: list):
|
||||
self.version_list = version_list
|
||||
self.version_string = None
|
||||
self.is_snapshot = None
|
||||
|
||||
|
@ -50,6 +30,7 @@ class Version():
|
|||
self.version_string = ".".join([str(x) for x in self.version_list])
|
||||
if self.is_snapshot:
|
||||
self.version_string += "-SNAPSHOT"
|
||||
return self.version_string
|
||||
|
||||
@classmethod
|
||||
def create_release_version(cls, version_list, release_type):
|
||||
|
|
|
@ -25,7 +25,7 @@ class VersionRepository():
|
|||
return version_list, is_snapshot
|
||||
|
||||
@classmethod
|
||||
def get(cls, file) -> VersionRepository:
|
||||
def get(cls, file):
|
||||
inst = cls(file)
|
||||
|
||||
file_handler= inst.load_file(file)
|
||||
|
|
Loading…
Reference in a new issue