Repository: relekang/python-semantic-release
Pull request #457 (2022-06-16 06:53:49)

fix: ensure should_bump checks against release version if not prerelease


Patch:
diff --git a/semantic_release/cli.py b/semantic_release/cli.py
index df4a637..ccf5e59 100644
--- a/semantic_release/cli.py
+++ b/semantic_release/cli.py
@@ -117,7 +117,7 @@ def print_version(*, current=False, force_level=None, prerelease=False, **kwargs
     new_version = get_new_version(
         current_version, current_release_version, level_bump, prerelease
     )
-    if should_bump_version(current_version=current_version, new_version=new_version):
+    if should_bump_version(current_version=current_version, new_version=new_version, current_release_version=current_release_version, prerelease=prerelease):
         print(new_version, end="")
         return True
 
@@ -153,7 +153,7 @@ def version(*, retry=False, noop=False, force_level=None, prerelease=False, **kw
     )
 
     if not should_bump_version(
-        current_version=current_version, new_version=new_version, retry=retry, noop=noop
+        current_version=current_version, new_version=new_version, current_release_version=current_release_version, prerelease=prerelease, retry=retry, noop=noop
     ):
         return False
 
@@ -166,9 +166,11 @@ def version(*, retry=False, noop=False, force_level=None, prerelease=False, **kw
     return True
 
 
-def should_bump_version(*, current_version, new_version, retry=False, noop=False):
+def should_bump_version(*, current_version, current_release_version, new_version, prerelease, retry=False, noop=False):
+    match_version = current_version if prerelease else current_release_version
+    
     """Test whether the version should be bumped."""
-    if new_version == current_version and not retry:
+    if new_version == match_version and not retry:
         logger.info("No release will be made.")
         return False
 
@@ -289,6 +291,8 @@ def publish(
     if should_bump_version(
         current_version=current_version,
         new_version=new_version,
+        current_release_version=current_release_version,
+        prerelease=prerelease,
         retry=retry,
         noop=noop,
     ):


Test patch:
diff --git a/tests/test_cli.py b/tests/test_cli.py
index feb4e1b..0c9af34 100644
--- a/tests/test_cli.py
+++ b/tests/test_cli.py
@@ -967,7 +967,7 @@ def test_publish_retry_version_fail(mocker):
     mock_ci_check.assert_called()
     mock_checkout.assert_called_once_with("my_branch")
     mock_should_bump_version.assert_called_once_with(
-        current_version="previous", new_version="current", noop=False, retry=True
+        current_version="previous", new_version="current", current_release_version="1.2.3", prerelease=False, noop=False, retry=True
     )
 
 
@@ -1017,7 +1017,7 @@ def test_publish_bad_token(mocker):
     mock_ci_check.assert_called()
     mock_checkout.assert_called_once_with("my_branch")
     mock_should_bump_version.assert_called_once_with(
-        current_version="previous", new_version="current", noop=False, retry=True
+        current_version="previous", new_version="current", current_release_version="1.2.3", prerelease=False, noop=False, retry=True
     )
     mock_get_token.assert_called()
     mock_get_domain.assert_called()
@@ -1096,7 +1096,7 @@ def test_publish_giterror_when_posting(mocker):
     mock_ci_check.assert_called()
     mock_checkout.assert_called_once_with("my_branch")
     mock_should_bump_version.assert_called_once_with(
-        current_version="1.2.3", new_version="new", noop=False, retry=False
+        current_version="1.2.3", new_version="new", current_release_version="1.2.3", prerelease=False, noop=False, retry=False
     )
     mock_update_changelog_file.assert_called_once_with("new", "super md changelog")
     mock_bump_version.assert_called_once_with("new", "patch")