diff --git a/pontos/release/create.py b/pontos/release/create.py index 3076d572b..2436fb2ea 100644 --- a/pontos/release/create.py +++ b/pontos/release/create.py @@ -13,7 +13,7 @@ from pontos.changelog.conventional_commits import ChangelogBuilder from pontos.errors import PontosError -from pontos.git import Git +from pontos.git import Git, ResetMode from pontos.github.actions.core import ActionIO from pontos.github.api import GitHubAsyncRESTApi from pontos.release.command import AsyncCommand @@ -315,6 +315,11 @@ async def async_run( # type: ignore[override] self.terminal.ok(f"Created release {release_version}") except httpx.HTTPStatusError as e: self.print_error(str(e)) + # revert commit and tag + self.git.delete_tag(git_version) + self.git.push(git_version, delete=True, remote=git_remote_name) + self.git.reset("HEAD^", mode=ResetMode.HARD) + self.git.push(force=True, remote=git_remote_name) return CreateReleaseReturnValue.CREATE_RELEASE_ERROR if next_version is None: diff --git a/tests/release/test_create.py b/tests/release/test_create.py index 4c000192b..6a7597537 100644 --- a/tests/release/test_create.py +++ b/tests/release/test_create.py @@ -15,7 +15,7 @@ from httpx import HTTPStatusError, Request, Response -from pontos.git import ConfigScope, Git, StatusEntry +from pontos.git import ConfigScope, Git, ResetMode, StatusEntry from pontos.github.actions.errors import GitHubActionsError from pontos.release.create import ( CreateReleaseReturnValue, @@ -1653,9 +1653,17 @@ def test_github_create_release_failure( released, CreateReleaseReturnValue.CREATE_RELEASE_ERROR ) - git_instance_mock.push.assert_called_once_with( - follow_tags=True, remote=None + git_instance_mock.push.assert_has_calls( + [ + call(follow_tags=True, remote=None), + call("v0.0.1", delete=True, remote=None), + call(force=True, remote=None), + ] + ) + git_instance_mock.reset.assert_called_once_with( + "HEAD^", mode=ResetMode.HARD ) + git_instance_mock.delete_tag.assert_called_once_with("v0.0.1") git_instance_mock.add.assert_called_once_with(Path("MyProject.conf")) git_instance_mock.commit.assert_called_once_with( "Automatic release to 0.0.1", verify=False, gpg_signing_key="1234"