feat: add release link to github action outputs by codejedi365 · Pull Request #1301 · python-semantic-release/python-semantic-release
Expand Up
@@ -3,18 +3,24 @@
import os
from textwrap import dedent
from typing import TYPE_CHECKING
from unittest import mock
import pytest
from semantic_release.cli.github_actions_output import VersionGitHubActionsOutput from semantic_release.hvcs.github import Github from semantic_release.version.version import Version
from tests.const import EXAMPLE_HVCS_DOMAIN, EXAMPLE_REPO_NAME, EXAMPLE_REPO_OWNER from tests.util import actions_output_to_dict
if TYPE_CHECKING: from pathlib import Path
BASE_VCS_URL = f"https://{EXAMPLE_HVCS_DOMAIN}/{EXAMPLE_REPO_OWNER}/{EXAMPLE_REPO_NAME}"
@pytest.mark.parametrize( "version, is_prerelease", [ Expand All @@ -41,25 +47,29 @@ def test_version_github_actions_output_format( version={version} tag=v{version} is_prerelease={'true' if is_prerelease else 'false'} link={BASE_VCS_URL}/releases/tag/v{version} commit_sha={commit_sha} """ ) + f"release_notes<<EOF\n{release_notes}EOF{os.linesep}" )
output = VersionGitHubActionsOutput( released=released, version=Version.parse(version), commit_sha=commit_sha, release_notes=release_notes, ) with mock.patch.dict(os.environ, {}, clear=True): actual_output_text = VersionGitHubActionsOutput( gh_client=Github(f"{BASE_VCS_URL}.git", hvcs_domain=EXAMPLE_HVCS_DOMAIN), released=released, version=Version.parse(version), commit_sha=commit_sha, release_notes=release_notes, ).to_output_text()
# Evaluate (expected -> actual) assert expected_output == output.to_output_text() assert expected_output == actual_output_text
def test_version_github_actions_output_fails_if_missing_released_param(): output = VersionGitHubActionsOutput( gh_client=Github(f"{BASE_VCS_URL}.git"), version=Version.parse("1.2.3"), )
Expand All @@ -70,6 +80,7 @@ def test_version_github_actions_output_fails_if_missing_released_param():
def test_version_github_actions_output_fails_if_missing_commit_sha_param(): output = VersionGitHubActionsOutput( gh_client=Github(f"{BASE_VCS_URL}.git"), released=True, version=Version.parse("1.2.3"), ) Expand All @@ -81,6 +92,7 @@ def test_version_github_actions_output_fails_if_missing_commit_sha_param():
def test_version_github_actions_output_fails_if_missing_release_notes_param(): output = VersionGitHubActionsOutput( gh_client=Github(f"{BASE_VCS_URL}.git"), released=True, version=Version.parse("1.2.3"), ) Expand All @@ -91,7 +103,7 @@ def test_version_github_actions_output_fails_if_missing_release_notes_param():
def test_version_github_actions_output_writes_to_github_output_if_available( monkeypatch: pytest.MonkeyPatch, tmp_path: Path tmp_path: Path, ): mock_output_file = tmp_path / "action.out" version_str = "1.2.3" Expand All @@ -103,15 +115,17 @@ def test_version_github_actions_output_writes_to_github_output_if_available( - Fixed bug """ ) monkeypatch.setenv("GITHUB_OUTPUT", str(mock_output_file.resolve())) output = VersionGitHubActionsOutput( version=Version.parse(version_str), released=True, commit_sha=commit_sha, release_notes=release_notes, )
output.write_if_possible() patched_environ = {"GITHUB_OUTPUT": str(mock_output_file.resolve())}
with mock.patch.dict(os.environ, patched_environ, clear=True): VersionGitHubActionsOutput( gh_client=Github(f"{BASE_VCS_URL}.git", hvcs_domain=EXAMPLE_HVCS_DOMAIN), version=Version.parse(version_str), released=True, commit_sha=commit_sha, release_notes=release_notes, ).write_if_possible()
with open(mock_output_file, encoding="utf-8", newline=os.linesep) as rfd: action_outputs = actions_output_to_dict(rfd.read()) Expand All @@ -120,6 +134,7 @@ def test_version_github_actions_output_writes_to_github_output_if_available( assert version_str == action_outputs["version"] assert str(True).lower() == action_outputs["released"] assert str(False).lower() == action_outputs["is_prerelease"] assert f"{BASE_VCS_URL}/releases/tag/v{version_str}" == action_outputs["link"] assert f"v{version_str}" == action_outputs["tag"] assert commit_sha == action_outputs["commit_sha"] assert release_notes == action_outputs["release_notes"] Expand All @@ -129,6 +144,7 @@ def test_version_github_actions_output_no_error_if_not_in_gha( monkeypatch: pytest.MonkeyPatch, ): output = VersionGitHubActionsOutput( gh_client=Github(f"{BASE_VCS_URL}.git"), version=Version.parse("1.2.3"), released=True, commit_sha="0" * 40, # 40 zeroes to simulate a SHA-1 hash Expand Down
import pytest
from semantic_release.cli.github_actions_output import VersionGitHubActionsOutput from semantic_release.hvcs.github import Github from semantic_release.version.version import Version
from tests.const import EXAMPLE_HVCS_DOMAIN, EXAMPLE_REPO_NAME, EXAMPLE_REPO_OWNER from tests.util import actions_output_to_dict
if TYPE_CHECKING: from pathlib import Path
BASE_VCS_URL = f"https://{EXAMPLE_HVCS_DOMAIN}/{EXAMPLE_REPO_OWNER}/{EXAMPLE_REPO_NAME}"
@pytest.mark.parametrize( "version, is_prerelease", [ Expand All @@ -41,25 +47,29 @@ def test_version_github_actions_output_format( version={version} tag=v{version} is_prerelease={'true' if is_prerelease else 'false'} link={BASE_VCS_URL}/releases/tag/v{version} commit_sha={commit_sha} """ ) + f"release_notes<<EOF\n{release_notes}EOF{os.linesep}" )
output = VersionGitHubActionsOutput( released=released, version=Version.parse(version), commit_sha=commit_sha, release_notes=release_notes, ) with mock.patch.dict(os.environ, {}, clear=True): actual_output_text = VersionGitHubActionsOutput( gh_client=Github(f"{BASE_VCS_URL}.git", hvcs_domain=EXAMPLE_HVCS_DOMAIN), released=released, version=Version.parse(version), commit_sha=commit_sha, release_notes=release_notes, ).to_output_text()
# Evaluate (expected -> actual) assert expected_output == output.to_output_text() assert expected_output == actual_output_text
def test_version_github_actions_output_fails_if_missing_released_param(): output = VersionGitHubActionsOutput( gh_client=Github(f"{BASE_VCS_URL}.git"), version=Version.parse("1.2.3"), )
Expand All @@ -70,6 +80,7 @@ def test_version_github_actions_output_fails_if_missing_released_param():
def test_version_github_actions_output_fails_if_missing_commit_sha_param(): output = VersionGitHubActionsOutput( gh_client=Github(f"{BASE_VCS_URL}.git"), released=True, version=Version.parse("1.2.3"), ) Expand All @@ -81,6 +92,7 @@ def test_version_github_actions_output_fails_if_missing_commit_sha_param():
def test_version_github_actions_output_fails_if_missing_release_notes_param(): output = VersionGitHubActionsOutput( gh_client=Github(f"{BASE_VCS_URL}.git"), released=True, version=Version.parse("1.2.3"), ) Expand All @@ -91,7 +103,7 @@ def test_version_github_actions_output_fails_if_missing_release_notes_param():
def test_version_github_actions_output_writes_to_github_output_if_available( monkeypatch: pytest.MonkeyPatch, tmp_path: Path tmp_path: Path, ): mock_output_file = tmp_path / "action.out" version_str = "1.2.3" Expand All @@ -103,15 +115,17 @@ def test_version_github_actions_output_writes_to_github_output_if_available( - Fixed bug """ ) monkeypatch.setenv("GITHUB_OUTPUT", str(mock_output_file.resolve())) output = VersionGitHubActionsOutput( version=Version.parse(version_str), released=True, commit_sha=commit_sha, release_notes=release_notes, )
output.write_if_possible() patched_environ = {"GITHUB_OUTPUT": str(mock_output_file.resolve())}
with mock.patch.dict(os.environ, patched_environ, clear=True): VersionGitHubActionsOutput( gh_client=Github(f"{BASE_VCS_URL}.git", hvcs_domain=EXAMPLE_HVCS_DOMAIN), version=Version.parse(version_str), released=True, commit_sha=commit_sha, release_notes=release_notes, ).write_if_possible()
with open(mock_output_file, encoding="utf-8", newline=os.linesep) as rfd: action_outputs = actions_output_to_dict(rfd.read()) Expand All @@ -120,6 +134,7 @@ def test_version_github_actions_output_writes_to_github_output_if_available( assert version_str == action_outputs["version"] assert str(True).lower() == action_outputs["released"] assert str(False).lower() == action_outputs["is_prerelease"] assert f"{BASE_VCS_URL}/releases/tag/v{version_str}" == action_outputs["link"] assert f"v{version_str}" == action_outputs["tag"] assert commit_sha == action_outputs["commit_sha"] assert release_notes == action_outputs["release_notes"] Expand All @@ -129,6 +144,7 @@ def test_version_github_actions_output_no_error_if_not_in_gha( monkeypatch: pytest.MonkeyPatch, ): output = VersionGitHubActionsOutput( gh_client=Github(f"{BASE_VCS_URL}.git"), version=Version.parse("1.2.3"), released=True, commit_sha="0" * 40, # 40 zeroes to simulate a SHA-1 hash Expand Down