add some version funct.

This commit is contained in:
Michael Jerger 2023-05-10 09:28:43 +02:00
parent 9ae6679bfd
commit d38c2baaa1
3 changed files with 49 additions and 39 deletions

View file

@ -37,25 +37,29 @@ classDiagram
release_main_branch
release_current_branch
release_type
version
}
class BuildFile {
filename
<<AggregateRoot>>
file_path [id]
file_type
content
}
class Version {
get_version_string(release_type: ReleaseType)
create_release_version(release_type: ReleaseType):
create_bump_version(release_type: ReleaseType):
get_version_string()
create_major()
create_minor()
create_patchn()
create_bump()
}
Devops *-- "0..1" Image: spcialized_builds
Devops *-- "0..1" C4k: spcialized_builds
Devops *-- "0..1" Release: mixins
Release *-- "0..1" BuildFile: primary_release_file
Release *-- "0..n" BuildFile: secondary_release_files
Release o-- "0..1" BuildFile: primary_release_file
Release o-- "0..n" BuildFile: secondary_release_files
BuildFile *-- "1" Version
C4k *-- DnsRecord

View file

@ -48,17 +48,21 @@ class Version(Validateable):
result += [f"version_list must have at least 3 levels."]
if self.version_list and self.version_string and self.to_string() != self.version_string:
result += [f"version_string not parsed correct. Input was {self.version_string} parsed was {self.to_string()}"]
return result
# def create_release_version(self, release_type: ReleaseType | None):
# release_version = Version(self.path, self.version_list.copy())
# release_version.is_snapshot = self.is_snapshot
# release_version.increment(release_type)
# return release_version
def create_patch(self):
new_version_list = self.version_list.copy()
if self.is_snapshot():
return Version(new_version_list, snapshot_suffix=None, version_str=None)
else:
new_version_list[2] += 1
return Version(new_version_list, snapshot_suffix=None, version_str=None)
# def create_bump_version(self):
# bump_version = Version(self.path, self.version_list.copy())
# bump_version.is_snapshot = self.is_snapshot
# bump_version.increment(ReleaseType.BUMP)
# return bump_version
def create_minor(self):
new_version_list = self.version_list.copy()
if self.is_snapshot() and new_version_list[2] == 0:
return Version(new_version_list, snapshot_suffix=None, version_str=None)
else:
new_version_list[2] = 0
new_version_list[1] += 1
return Version(new_version_list, snapshot_suffix=None, version_str=None)

View file

@ -52,28 +52,30 @@ def test_should_validate_parsing():
assert sut.is_valid()
def test_version():
pass
# version = Version.version_from_str("1.2.3-SNAPSHOT")
# version.increment(ReleaseType.NONE)
# assert version.get_version_string() == "1.2.3-SNAPSHOT"
# assert version.version_list == [1, 2, 3]
# assert version.is_snapshot
def test_should_create_patch():
version = Version.from_str("1.2.3-SNAPSHOT")
sut = version.create_patch()
assert sut.to_string() == "1.2.3"
assert version.to_string() == "1.2.3-SNAPSHOT"
# version = Version.version_from_str("1.2.3")
# version.increment(ReleaseType.PATCH)
# assert version.get_version_string() == "1.2.4"
# assert version.version_list == [1, 2, 4]
# assert not version.is_snapshot
version = Version.from_str("1.2.3")
sut = version.create_patch()
assert sut.to_string() == "1.2.4"
assert version.to_string() == "1.2.3"
# version = Version.version_from_str("1.2.3")
# version.increment(ReleaseType.MINOR)
# assert version.get_version_string() == "1.3.0"
# assert version.version_list == [1, 3, 0]
# assert not version.is_snapshot
def test_should_create_minor():
version = Version.from_str("1.2.3-SNAPSHOT")
sut = version.create_minor()
assert sut.to_string() == "1.3.0"
# version = Version.version_from_str("1.2.3")
# version.increment(ReleaseType.MAJOR)
# assert version.get_version_string() == "2.0.0"
# assert version.version_list == [2, 0, 0]
# assert not version.is_snapshot
version = Version.from_str("1.2.3")
sut = version.create_minor()
assert sut.to_string() == "1.3.0"
version = Version.from_str("1.3.0-SNAPSHOT")
sut = version.create_minor()
assert sut.to_string() == "1.3.0"
version = Version.from_str("1.3.0")
sut = version.create_minor()
assert sut.to_string() == "1.4.0"