get_version now works
This commit is contained in:
parent
f2c6f7787e
commit
6a0ed7deef
2 changed files with 85 additions and 40 deletions
|
@ -49,7 +49,7 @@ class BuildFile(Validateable):
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def get_version(self) -> Version:
|
def get_version(self) -> Version:
|
||||||
version = None
|
try:
|
||||||
match self.build_file_type():
|
match self.build_file_type():
|
||||||
case BuildFileType.JS:
|
case BuildFileType.JS:
|
||||||
print(json.loads(self.content))
|
print(json.loads(self.content))
|
||||||
|
@ -61,4 +61,19 @@ class BuildFile(Validateable):
|
||||||
version_string = re.search(
|
version_string = re.search(
|
||||||
'[0-9]*\\.[0-9]*\\.[0-9]*(-SNAPSHOT)?', version_line_group)
|
'[0-9]*\\.[0-9]*\\.[0-9]*(-SNAPSHOT)?', version_line_group)
|
||||||
version = version_string.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)
|
return Version.from_str(version)
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import pytest
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from src.main.python.ddadevops.domain import (
|
from src.main.python.ddadevops.domain import (
|
||||||
BuildFileType,
|
BuildFileType,
|
||||||
|
@ -7,48 +8,32 @@ from src.main.python.ddadevops.domain import (
|
||||||
|
|
||||||
|
|
||||||
def test_sould_validate_build_file():
|
def test_sould_validate_build_file():
|
||||||
sut = BuildFile(
|
sut = BuildFile(Path("./project.clj"), "content")
|
||||||
Path("./project.clj"),
|
|
||||||
"content"
|
|
||||||
)
|
|
||||||
assert sut.is_valid()
|
assert sut.is_valid()
|
||||||
|
|
||||||
sut = BuildFile(
|
sut = BuildFile(None, "")
|
||||||
None,
|
|
||||||
""
|
|
||||||
)
|
|
||||||
assert not sut.is_valid()
|
assert not sut.is_valid()
|
||||||
|
|
||||||
sut = BuildFile(
|
sut = BuildFile(Path("./unknown.extension"), "content")
|
||||||
Path("./unknown.extension"),
|
|
||||||
"content"
|
|
||||||
)
|
|
||||||
assert not sut.is_valid()
|
assert not sut.is_valid()
|
||||||
|
|
||||||
|
|
||||||
def test_sould_calculate_build_type():
|
def test_sould_calculate_build_type():
|
||||||
sut = BuildFile(
|
sut = BuildFile(Path("./project.clj"), "content")
|
||||||
Path("./project.clj"),
|
|
||||||
"content"
|
|
||||||
)
|
|
||||||
assert sut.build_file_type() == BuildFileType.JAVA_CLOJURE
|
assert sut.build_file_type() == BuildFileType.JAVA_CLOJURE
|
||||||
|
|
||||||
sut = BuildFile(
|
sut = BuildFile(Path("./build.gradle"), "content")
|
||||||
Path("./build.gradle"),
|
|
||||||
"content"
|
|
||||||
)
|
|
||||||
assert sut.build_file_type() == BuildFileType.JAVA_GRADLE
|
assert sut.build_file_type() == BuildFileType.JAVA_GRADLE
|
||||||
|
|
||||||
sut = BuildFile(
|
sut = BuildFile(Path("./package.json"), "content")
|
||||||
Path("./package.json"),
|
|
||||||
"content"
|
|
||||||
)
|
|
||||||
assert sut.build_file_type() == BuildFileType.JS
|
assert sut.build_file_type() == BuildFileType.JS
|
||||||
|
|
||||||
def test_sould_parse_version():
|
|
||||||
|
def test_sould_parse_js():
|
||||||
sut = BuildFile(
|
sut = BuildFile(
|
||||||
Path("./package.json"),
|
Path("./package.json"),
|
||||||
"""{
|
"""
|
||||||
|
{
|
||||||
"name":"c4k-jira",
|
"name":"c4k-jira",
|
||||||
"description": "Generate c4k yaml for a jira deployment.",
|
"description": "Generate c4k yaml for a jira deployment.",
|
||||||
"author": "meissa GmbH",
|
"author": "meissa GmbH",
|
||||||
|
@ -58,16 +43,61 @@ def test_sould_parse_version():
|
||||||
"c4k-jira": "./c4k-jira.js"
|
"c4k-jira": "./c4k-jira.js"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"""
|
""",
|
||||||
)
|
)
|
||||||
assert sut.get_version() == Version.from_str("1.1.5-SNAPSHOT")
|
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(
|
sut = BuildFile(
|
||||||
Path("./build.gradle"),
|
Path("./build.gradle"),
|
||||||
"""
|
"""
|
||||||
version = "1.1.5-SNAPSHOT"
|
version = "1.1.5-SNAPSHOT"
|
||||||
|
|
||||||
"""
|
""",
|
||||||
)
|
)
|
||||||
assert sut.get_version() == Version.from_str("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