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
This commit is contained in:
bom 2023-11-17 12:53:47 +01:00
parent 78824ea38b
commit e5d1203435
2 changed files with 41 additions and 1 deletions

View file

@ -85,6 +85,10 @@ class BuildFile(Validateable):
def set_version(self, new_version: Version): def set_version(self, new_version: Version):
# TODO: How can we create regex-pattern constants to use them at both places? # 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: try:
match self.build_file_type(): match self.build_file_type():
case BuildFileType.JS: case BuildFileType.JS:

View file

@ -5,7 +5,9 @@ from pybuilder.core import Project
from src.main.python.ddadevops.release_mixin import ReleaseMixin from src.main.python.ddadevops.release_mixin import ReleaseMixin
from src.main.python.ddadevops.domain import Devops, Release 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 from .resource_helper import copy_resource
@ -30,3 +32,37 @@ def test_release_mixin(tmp_path):
sut.initialize_build_dir() sut.initialize_build_dir()
assert sut.build_path() == f"{str_tmp_path}/target/name/release-test" 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"