Skip to content

Commit

Permalink
Add: Revert local changes if creating a GitHub release fails
Browse files Browse the repository at this point in the history
Improve the create release "workflow" by reverting the changes (tag and
version update commit) if creating a GitHub release via the API did
fail.
  • Loading branch information
bjoernricks committed Feb 6, 2024
1 parent 85ad900 commit 2ee191e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
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

0 comments on commit 2ee191e

Please sign in to comment.