diff --git a/src/semantic_release/cli/commands/version.py b/src/semantic_release/cli/commands/version.py index 771ec273f..bb9ebfc3e 100644 --- a/src/semantic_release/cli/commands/version.py +++ b/src/semantic_release/cli/commands/version.py @@ -18,7 +18,10 @@ generate_release_notes, write_changelog_files, ) -from semantic_release.cli.github_actions_output import VersionGitHubActionsOutput +from semantic_release.cli.github_actions_output import ( + PersistenceMode, + VersionGitHubActionsOutput, +) from semantic_release.cli.util import noop_report, rprint from semantic_release.const import DEFAULT_SHELL, DEFAULT_VERSION from semantic_release.enums import LevelBump @@ -468,9 +471,16 @@ def version( # noqa: C901 no_verify = runtime.no_git_verify opts = runtime.global_cli_options gha_output = VersionGitHubActionsOutput( - hvcs_client - if isinstance(hvcs_client, Github) - else Github(hvcs_client.remote_url(use_token=False)), + gh_client=( + hvcs_client + if isinstance(hvcs_client, Github) + else Github(hvcs_client.remote_url(use_token=False)) + ), + mode=( + PersistenceMode.TEMPORARY + if opts.noop or (not commit_changes and not create_tag) + else PersistenceMode.PERMANENT + ), released=False, ) diff --git a/src/semantic_release/cli/github_actions_output.py b/src/semantic_release/cli/github_actions_output.py index fe2114aa5..b7a507414 100644 --- a/src/semantic_release/cli/github_actions_output.py +++ b/src/semantic_release/cli/github_actions_output.py @@ -1,6 +1,7 @@ from __future__ import annotations import os +from enum import Enum from re import compile as regexp from typing import TYPE_CHECKING @@ -13,12 +14,18 @@ from semantic_release.hvcs.github import Github +class PersistenceMode(Enum): + TEMPORARY = "temporary" + PERMANENT = "permanent" + + class VersionGitHubActionsOutput: OUTPUT_ENV_VAR = "GITHUB_OUTPUT" def __init__( self, gh_client: Github, + mode: PersistenceMode = PersistenceMode.PERMANENT, released: bool | None = None, version: Version | None = None, commit_sha: str | None = None, @@ -26,6 +33,7 @@ def __init__( prev_version: Version | None = None, ) -> None: self._gh_client = gh_client + self._mode = mode self._released = released self._version = version self._commit_sha = commit_sha @@ -104,10 +112,11 @@ def to_output_text(self) -> str: missing.add("version") if self.released is None: missing.add("released") - if self.released and self.commit_sha is None: - missing.add("commit_sha") - if self.released and self.release_notes is None: - missing.add("release_notes") + if self.released: + if self.release_notes is None: + missing.add("release_notes") + if self._mode is PersistenceMode.PERMANENT and self.commit_sha is None: + missing.add("commit_sha") if missing: raise ValueError(