GRM-34: fix: skip commit when version file unchanged in release.py

This commit is contained in:
emil
2026-06-21 16:18:02 +00:00
parent f0afa8171a
commit ea6276ff38
2 changed files with 64 additions and 11 deletions
+42 -2
View File
@@ -137,11 +137,23 @@ class TestUpdateInitVersion:
class TestCreateReleaseCommit:
@patch("scripts.release.run_cmd")
def test_commits(self, mock_run_cmd: MagicMock) -> None:
create_release_commit("0.2.0")
# git diff --cached --quiet returns 1 (changes exist)
mock_run_cmd.return_value = MagicMock(returncode=1, stdout="", stderr="")
result = create_release_commit("0.2.0")
assert result is True
calls = [c.args[0] for c in mock_run_cmd.call_args_list]
assert ["git", "add", "src/gitea_runner_manager/__init__.py"] in calls
assert ["git", "commit", "-m", "chore(release): prepare for v0.2.0"] in calls
@patch("scripts.release.run_cmd")
def test_skips_when_no_changes(self, mock_run_cmd: MagicMock) -> None:
# git diff --cached --quiet returns 0 (no changes)
mock_run_cmd.return_value = MagicMock(returncode=0, stdout="", stderr="")
result = create_release_commit("0.1.0")
assert result is False
calls = [c.args[0] for c in mock_run_cmd.call_args_list]
assert ["git", "commit", "-m", "chore(release): prepare for v0.1.0"] not in calls
class TestCreateAndPushTag:
@patch("scripts.release.run_cmd")
@@ -258,7 +270,7 @@ class TestMain:
@patch.dict("os.environ", {})
@patch("scripts.release.create_and_push_tag")
@patch("scripts.release.create_release_commit")
@patch("scripts.release.create_release_commit", return_value=True)
@patch("scripts.release.update_init_version")
@patch("scripts.release.get_changelog", return_value="changelog")
@patch("scripts.release.get_latest_tag", return_value="v0.1.0")
@@ -284,3 +296,31 @@ class TestMain:
mock_update_init.assert_called_once_with("0.2.0")
mock_commit.assert_called_once_with("0.2.0")
mock_tag.assert_called_once_with("0.2.0", "changelog", False)
@patch.dict("os.environ", {})
@patch("scripts.release.create_and_push_tag")
@patch("scripts.release.create_release_commit", return_value=False)
@patch("scripts.release.update_init_version")
@patch("scripts.release.get_changelog", return_value="changelog")
@patch("scripts.release.get_latest_tag", return_value="v0.1.0")
@patch("scripts.release.get_bumped_version", return_value="0.1.0")
@patch("scripts.release.has_unreleased_changes", return_value=True)
@patch("scripts.release.run_cmd")
def test_full_flow_no_commit(
self,
mock_run_cmd: MagicMock,
mock_has: MagicMock,
mock_bumped: MagicMock,
mock_latest: MagicMock,
mock_changelog: MagicMock,
mock_update_init: MagicMock,
mock_commit: MagicMock,
mock_tag: MagicMock,
) -> None:
"""When version is unchanged, skip commit but still tag."""
mock_run_cmd.return_value = MagicMock(returncode=0, stdout="master\n", stderr="")
runner = CliRunner()
result = runner.invoke(main, [])
assert result.exit_code == 0
assert "Skipping commit push" in result.output
mock_tag.assert_called_once_with("0.1.0", "changelog", False)