From e5d1203435d7e0ed90520a1ea1bb0ec23f55fea7 Mon Sep 17 00:00:00 2001 From: bom Date: Fri, 17 Nov 2023 12:53:47 +0100 Subject: [PATCH] Update version suffix to fit build file type Resolves a bug where when using "build.py" as the primary build file and some other secondary file like "build.gradle", would result in the ".gradle" file version having a "-dev" suffix instead of "-SNAPSHOT" Includes regression test --- .../python/ddadevops/domain/build_file.py | 4 ++ src/test/python/test_release_mixin.py | 38 ++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/main/python/ddadevops/domain/build_file.py b/src/main/python/ddadevops/domain/build_file.py index 07711cd..89feed6 100644 --- a/src/main/python/ddadevops/domain/build_file.py +++ b/src/main/python/ddadevops/domain/build_file.py @@ -85,6 +85,10 @@ class BuildFile(Validateable): def set_version(self, new_version: Version): # TODO: How can we create regex-pattern constants to use them at both places? + + if new_version.is_snapshot(): + new_version.snapshot_suffix = self.get_default_suffix() + try: match self.build_file_type(): case BuildFileType.JS: diff --git a/src/test/python/test_release_mixin.py b/src/test/python/test_release_mixin.py index a2539a6..98f4122 100644 --- a/src/test/python/test_release_mixin.py +++ b/src/test/python/test_release_mixin.py @@ -5,7 +5,9 @@ from pybuilder.core import Project from src.main.python.ddadevops.release_mixin import ReleaseMixin from src.main.python.ddadevops.domain import Devops, Release -from .domain.helper import devops_config +from src.main.python.ddadevops.application import ReleaseService +from src.main.python.ddadevops.infrastructure import BuildFileRepository +from .domain.helper import devops_config, GitApiMock, ArtifactDeploymentApiMock from .resource_helper import copy_resource @@ -30,3 +32,37 @@ def test_release_mixin(tmp_path): sut.initialize_build_dir() assert sut.build_path() == f"{str_tmp_path}/target/name/release-test" + +def test_release_mixin_different_version_suffixes(tmp_path): + str_tmp_path = str(tmp_path) + copy_resource(Path("config.py"), tmp_path) + copy_resource(Path("config.gradle"), tmp_path) + + project = Project(str_tmp_path, name="name") + + os.environ["RELEASE_ARTIFACT_TOKEN"] = "ratoken" + + sut = ReleaseMixin( + project, + devops_config( + { + "project_root_path": str_tmp_path, + "mixin_types": ["RELEASE"], + "build_types": [], + "module": "release-test", + "release_current_branch": "main", + "release_main_branch": "main", + "release_primary_build_file": "config.py", + "release_secondary_build_files": ["config.gradle"], + } + ), + ) + sut.release_service = ReleaseService(GitApiMock(), ArtifactDeploymentApiMock(), BuildFileRepository(project.basedir)) + + sut.initialize_build_dir() + sut.update_release_type("PATCH") + sut.prepare_release() + sut.tag_bump_and_push_release() + + assert sut.release_service.build_file_repository.get(Path("config.py")).get_version().to_string() == "3.1.5-dev" + assert sut.release_service.build_file_repository.get(Path("config.gradle")).get_version().to_string() == "3.1.5-SNAPSHOT" \ No newline at end of file