Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: Revert local changes if creating a GitHub release fails #981

Merged
merged 1 commit into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion pontos/release/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
14 changes: 11 additions & 3 deletions tests/release/test_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"
Expand Down
Loading