get_version now works
This commit is contained in:
parent
f2c6f7787e
commit
6a0ed7deef
2 changed files with 85 additions and 40 deletions
|
@ -49,16 +49,31 @@ class BuildFile(Validateable):
|
|||
return result
|
||||
|
||||
def get_version(self) -> Version:
|
||||
version = None
|
||||
match self.build_file_type():
|
||||
case BuildFileType.JS:
|
||||
print(json.loads(self.content))
|
||||
version = json.loads(self.content)["version"]
|
||||
print(version)
|
||||
case BuildFileType.JAVA_GRADLE:
|
||||
version_line = re.search("\nversion = .*", self.content)
|
||||
version_line_group = version_line.group()
|
||||
version_string = re.search(
|
||||
'[0-9]*\\.[0-9]*\\.[0-9]*(-SNAPSHOT)?', version_line_group)
|
||||
version = version_string.group()
|
||||
try:
|
||||
match self.build_file_type():
|
||||
case BuildFileType.JS:
|
||||
print(json.loads(self.content))
|
||||
version = json.loads(self.content)["version"]
|
||||
print(version)
|
||||
case BuildFileType.JAVA_GRADLE:
|
||||
version_line = re.search("\nversion = .*", self.content)
|
||||
version_line_group = version_line.group()
|
||||
version_string = re.search(
|
||||
'[0-9]*\\.[0-9]*\\.[0-9]*(-SNAPSHOT)?', version_line_group)
|
||||
version = version_string.group()
|
||||
case BuildFileType.PYTHON:
|
||||
version_line = re.search("\nversion = .*\n", self.content)
|
||||
version_line_group = version_line.group()
|
||||
version_string = re.search(
|
||||
'[0-9]*\\.[0-9]*\\.[0-9]*(-dev)?[0-9]*', version_line_group)
|
||||
version = version_string.group()
|
||||
case BuildFileType.JAVA_CLOJURE:
|
||||
version_line = re.search("\\(defproject .*\n", self.content)
|
||||
version_line_group = version_line.group()
|
||||
version_string = re.search(
|
||||
'[0-9]*\\.[0-9]*\\.[0-9]*(-SNAPSHOT)?', version_line_group)
|
||||
version = version_string.group()
|
||||
except:
|
||||
raise Exception(f"Version not found in file {self.file_path}")
|
||||
|
||||
return Version.from_str(version)
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import pytest
|
||||
from pathlib import Path
|
||||
from src.main.python.ddadevops.domain import (
|
||||
BuildFileType,
|
||||
|
@ -7,48 +8,32 @@ from src.main.python.ddadevops.domain import (
|
|||
|
||||
|
||||
def test_sould_validate_build_file():
|
||||
sut = BuildFile(
|
||||
Path("./project.clj"),
|
||||
"content"
|
||||
)
|
||||
sut = BuildFile(Path("./project.clj"), "content")
|
||||
assert sut.is_valid()
|
||||
|
||||
sut = BuildFile(
|
||||
None,
|
||||
""
|
||||
)
|
||||
sut = BuildFile(None, "")
|
||||
assert not sut.is_valid()
|
||||
|
||||
sut = BuildFile(
|
||||
Path("./unknown.extension"),
|
||||
"content"
|
||||
)
|
||||
sut = BuildFile(Path("./unknown.extension"), "content")
|
||||
assert not sut.is_valid()
|
||||
|
||||
|
||||
def test_sould_calculate_build_type():
|
||||
sut = BuildFile(
|
||||
Path("./project.clj"),
|
||||
"content"
|
||||
)
|
||||
sut = BuildFile(Path("./project.clj"), "content")
|
||||
assert sut.build_file_type() == BuildFileType.JAVA_CLOJURE
|
||||
|
||||
sut = BuildFile(
|
||||
Path("./build.gradle"),
|
||||
"content"
|
||||
)
|
||||
sut = BuildFile(Path("./build.gradle"), "content")
|
||||
assert sut.build_file_type() == BuildFileType.JAVA_GRADLE
|
||||
|
||||
sut = BuildFile(
|
||||
Path("./package.json"),
|
||||
"content"
|
||||
)
|
||||
sut = BuildFile(Path("./package.json"), "content")
|
||||
assert sut.build_file_type() == BuildFileType.JS
|
||||
|
||||
def test_sould_parse_version():
|
||||
|
||||
def test_sould_parse_js():
|
||||
sut = BuildFile(
|
||||
Path("./package.json"),
|
||||
"""{
|
||||
"""
|
||||
{
|
||||
"name":"c4k-jira",
|
||||
"description": "Generate c4k yaml for a jira deployment.",
|
||||
"author": "meissa GmbH",
|
||||
|
@ -58,16 +43,61 @@ def test_sould_parse_version():
|
|||
"c4k-jira": "./c4k-jira.js"
|
||||
}
|
||||
}
|
||||
"""
|
||||
""",
|
||||
)
|
||||
assert sut.get_version() == Version.from_str("1.1.5-SNAPSHOT")
|
||||
|
||||
sut = BuildFile(
|
||||
Path("./package.json"),
|
||||
"""
|
||||
{
|
||||
"name":"c4k-jira",
|
||||
"description": "Generate c4k yaml for a jira deployment.",
|
||||
"author": "meissa GmbH",
|
||||
"homepage": "https://gitlab.com/domaindrivenarchitecture/c4k-jira#readme",
|
||||
"bin":{
|
||||
"c4k-jira": "./c4k-jira.js"
|
||||
}
|
||||
}
|
||||
""",
|
||||
)
|
||||
with pytest.raises(Exception):
|
||||
sut.get_version()
|
||||
|
||||
|
||||
def test_sould_parse_gradle():
|
||||
sut = BuildFile(
|
||||
Path("./build.gradle"),
|
||||
"""
|
||||
version = "1.1.5-SNAPSHOT"
|
||||
|
||||
"""
|
||||
""",
|
||||
)
|
||||
assert sut.get_version() == Version.from_str("1.1.5-SNAPSHOT")
|
||||
|
||||
|
||||
def test_sould_parse_py():
|
||||
sut = BuildFile(
|
||||
Path("./build.py"),
|
||||
"""
|
||||
from pybuilder.core import init, use_plugin, Author
|
||||
use_plugin("python.core")
|
||||
|
||||
name = "ddadevops"
|
||||
version = "1.1.5-dev"
|
||||
""",
|
||||
)
|
||||
assert sut.get_version() == Version.from_str("1.1.5-dev")
|
||||
|
||||
|
||||
def test_sould_parse_clj():
|
||||
sut = BuildFile(
|
||||
Path("./project.clj"),
|
||||
"""
|
||||
(defproject org.domaindrivenarchitecture/c4k-jira "1.1.5-SNAPSHOT"
|
||||
:description "jira c4k-installation package"
|
||||
:url "https://domaindrivenarchitecture.org"
|
||||
)
|
||||
""",
|
||||
)
|
||||
assert sut.get_version() == Version.from_str("1.1.5-SNAPSHOT")
|
||||
|
|
Loading…
Reference in a new issue