From 5053b79ad456dff01165410cc02ebfc80aca955d Mon Sep 17 00:00:00 2001 From: bom Date: Fri, 24 Nov 2023 22:28:39 +0100 Subject: [PATCH] Make version regex for python and gradle more concrete Check that "version" is the start of the string to avoid changing cases like "kotlin_version = ..." --- .../python/ddadevops/domain/build_file.py | 4 +-- src/test/python/domain/test_build_file.py | 28 ++++++++++++++++++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/main/python/ddadevops/domain/build_file.py b/src/main/python/ddadevops/domain/build_file.py index c1dbbf5..3b41577 100644 --- a/src/main/python/ddadevops/domain/build_file.py +++ b/src/main/python/ddadevops/domain/build_file.py @@ -48,9 +48,9 @@ class BuildFile(Validateable): def __get_file_type_regex_str(self, file_type: BuildFileType): match file_type: case BuildFileType.JAVA_GRADLE: - return r'(?Pversion\s?=\s?)\"(?P\d*\.\d*\.\d*(-SNAPSHOT)?)\"' + return r'(?P\bversion\s?=\s?)\"(?P\d*\.\d*\.\d*(-SNAPSHOT)?)\"' case BuildFileType.PYTHON: - return r'(?Pversion\s?=\s?)\"(?P\d*\.\d*\.\d*(-SNAPSHOT|-dev\d*)?)\"' + return r'(?P\bversion\s?=\s?)\"(?P\d*\.\d*\.\d*(-SNAPSHOT|-dev\d*)?)\"' case BuildFileType.JAVA_CLOJURE: return r'(?P\(defproject\s(\S)*\s)\"(?P\d*\.\d*\.\d*(-SNAPSHOT)?)\"' case _: diff --git a/src/test/python/domain/test_build_file.py b/src/test/python/domain/test_build_file.py index 58fbea7..1bee1e0 100644 --- a/src/test/python/domain/test_build_file.py +++ b/src/test/python/domain/test_build_file.py @@ -195,4 +195,30 @@ def test_should_throw_for_clj_wrong_version(): ) with pytest.raises(RuntimeError): - sut.get_version() \ No newline at end of file + sut.get_version() + +def test_should_ignore_first_version_for_py(): + sut = BuildFile( + Path("./build.py"), + """ +from pybuilder.core import init, use_plugin, Author +use_plugin("python.core") + +name = "ddadevops" +project_version = "0.0.2-dev1" +version = "1.1.5-dev12" +summary = "tools to support builds combining gopass, terraform, dda-pallet, aws & hetzner-cloud" +""", + ) + assert sut.get_version() == Version.from_str("1.1.5-dev12", "dev") + +def test_should_ignore_first_version_for_gradle(): + sut = BuildFile( + Path("./build.gradle"), + """ +kotlin_version = "3.3.3" +version = "1.1.5-SNAPSHOT" + +""", + ) + assert sut.get_version() == Version.from_str("1.1.5-SNAPSHOT", "SNAPSHOT") \ No newline at end of file