Skip to content

Commit

Permalink
Change: Also create pre releases on GitHub
Browse files Browse the repository at this point in the history
Create pre releases on GitHub for pre release release versions. Reflect
pre releases also on GitHub.
  • Loading branch information
bjoernricks committed Mar 1, 2023
1 parent acd1e33 commit 95db4fa
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 2 deletions.
3 changes: 2 additions & 1 deletion pontos/release/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def _create_changelog(
)

async def _create_release(
self, release_version: str, token: str, release_text: str
self, release_version: Version, token: str, release_text: str
) -> None:
github = GitHubAsyncRESTApi(token=token)

Expand All @@ -121,6 +121,7 @@ async def _create_release(
git_version,
name=f"{self.project} {release_version}",
body=release_text,
prerelease=release_version.is_prerelease,
)

async def run(
Expand Down
99 changes: 98 additions & 1 deletion tests/release/test_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -1416,7 +1416,11 @@ def test_release_github_api(
)

create_api_mock.assert_awaited_once_with(
"bar/foo", "v0.0.1", name="foo 0.0.1", body="A Changelog"
"bar/foo",
"v0.0.1",
name="foo 0.0.1",
body="A Changelog",
prerelease=False,
)

version_command_mock.update_version.assert_has_calls(
Expand All @@ -1436,6 +1440,99 @@ def test_release_github_api(

self.assertEqual(released, ReleaseReturnValue.SUCCESS)

@patch("pontos.release.release.Git", autospec=True)
@patch("pontos.release.release.GitHubAsyncRESTApi", autospec=True)
@patch(
"pontos.release.release.ReleaseCommand._create_changelog", autospec=True
)
@patch("pontos.release.release.gather_project", autospec=True)
def test_release_github_api_pre_release(
self,
gather_project_mock: MagicMock,
create_changelog_mock: MagicMock,
github_api_mock: AsyncMock,
git_mock,
):
current_version = Version("0.0.0")
release_version = Version("0.0.1a1")
next_version = Version("0.0.1a1+dev1")
version_command_mock = MagicMock(spec=VersionCommand)
gather_project_mock.return_value = version_command_mock
version_command_mock.update_version.side_effect = [
VersionUpdate(
previous=current_version,
new=release_version,
changed_files=["MyProject.conf"],
),
VersionUpdate(
previous=release_version,
new=next_version,
changed_files=["MyProject.conf"],
),
]
create_changelog_mock.return_value = "A Changelog"
create_api_mock = AsyncMock()
github_api_mock.return_value.releases.create = create_api_mock

_, token, args = parse_args(
[
"release",
"--space",
"bar",
"--project",
"foo",
"--release-version",
"0.0.1a1",
"--next-version",
"0.0.1a1+dev1",
"--git-remote-name",
"upstream",
"--git-signing-key",
"1234",
]
)

with temp_git_repository():
released = release(
terminal=mock_terminal(),
args=args,
token=token,
)

git_mock.return_value.push.assert_has_calls(
[
call(follow_tags=True, remote="upstream"),
call(follow_tags=True, remote="upstream"),
],
)

create_api_mock.assert_awaited_once_with(
"bar/foo",
"v0.0.1a1",
name="foo 0.0.1a1",
body="A Changelog",
prerelease=True,
)

version_command_mock.update_version.assert_has_calls(
[call(release_version), call(next_version)],
)

git_mock.return_value.add.assert_called_with("MyProject.conf")
git_mock.return_value.commit.assert_called_with(
"Automatic adjustments after release\n\n"
"* Update to version 0.0.1a1+dev1\n",
verify=False,
gpg_signing_key="1234",
)
git_mock.return_value.tag.assert_called_once_with(
"v0.0.1a1",
gpg_key_id="1234",
message="Automatic release to 0.0.1a1",
)

self.assertEqual(released, ReleaseReturnValue.SUCCESS)

@patch("pontos.release.release.Git", autospec=True)
@patch(
"pontos.release.release.ReleaseCommand._create_release", autospec=True
Expand Down

0 comments on commit 95db4fa

Please sign in to comment.