diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index c66b4d4f7..69f6d6ee4 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -52,10 +52,12 @@ jobs: days-before-pr-close: ${{ env.STALE_PR_CLOSURE_DAYS }} exempt-pr-labels: confirmed, dependabot stale-pr-message: > - This PR is stale because it has not been confirmed or planned by the maintainers - and has been open ${{ env.STALE_PR_WARNING_DAYS }} days with no recent activity. - It will be closed in ${{ env.STALE_PR_CLOSURE_DAYS }} days, if no further - activity occurs. Thank you for your contributions. + This PR is stale because it has not been confirmed or considered ready for merge + by the maintainers but has been open ${{ env.STALE_PR_WARNING_DAYS }} days with + no recent activity. It will be closed in ${{ env.STALE_PR_CLOSURE_DAYS }} days, + if no further activity occurs. Please make sure to add the proper testing, docs, + and descriptions of changes before your PR can be merged. Thank you for your + contributions. close-pr-message: > This PR was closed due to lack of activity. @@ -72,6 +74,7 @@ jobs: only-labels: awaiting-reply stale-issue-label: unresponsive stale-pr-label: unresponsive + remove-stale-when-updated: awaiting-reply days-before-stale: ${{ env.UNRESPONSIVE_WARNING_DAYS }} days-before-close: ${{ env.UNRESPONSIVE_CLOSURE_DAYS }} stale-issue-message: > diff --git a/docs/configuration.rst b/docs/configuration.rst index 2591c62ce..2977c13b7 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -702,6 +702,24 @@ When :ref:`config-allow_zero_version` is set to ``false``, this setting is ignor ---- +.. _config-no_git_verify: + +``no_git_verify`` +""""""""""""""""" + +**Type:** ``bool`` + +This flag is passed along to ``git`` upon performing a ``git commit`` during :ref:`cmd-version`. + +When true, it will bypass any git hooks that are set for the repository when Python Semantic +Release makes a version commit. When false, the commit is performed as normal. This option +has no effect when there are not any git hooks configured nor when the ``--no-commit`` option +is passed. + +**Default:** ``false`` + +---- + .. _config-publish: ``publish`` diff --git a/pyproject.toml b/pyproject.toml index 089734922..e94e727cb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -74,7 +74,7 @@ test = [ dev = [ "pre-commit ~= 3.5", "tox ~= 4.11", - "ruff == 0.4.3" + "ruff == 0.4.4" ] mypy = [ "mypy == 1.10.0", diff --git a/semantic_release/cli/commands/version.py b/semantic_release/cli/commands/version.py index 9608f17b4..9f2879fa9 100644 --- a/semantic_release/cli/commands/version.py +++ b/semantic_release/cli/commands/version.py @@ -330,6 +330,7 @@ def version( # noqa: C901 commit_author = runtime.commit_author commit_message = runtime.commit_message major_on_zero = runtime.major_on_zero + no_verify = runtime.no_git_verify build_command = runtime.build_command opts = runtime.global_cli_options gha_output = VersionGitHubActionsOutput() @@ -613,6 +614,7 @@ def custom_git_environment() -> ContextManager[None]: ) command += f"git commit -m '{indented_commit_message}'" + command += "--no-verify" if no_verify else "" noop_report( indented( @@ -628,6 +630,7 @@ def custom_git_environment() -> ContextManager[None]: repo.git.commit( m=commit_message.format(version=new_version), date=int(commit_date.timestamp()), + no_verify=no_verify, ) # Run the tagging after potentially creating a new HEAD commit. diff --git a/semantic_release/cli/config.py b/semantic_release/cli/config.py index 9262bd4a2..3b8b63888 100644 --- a/semantic_release/cli/config.py +++ b/semantic_release/cli/config.py @@ -225,6 +225,7 @@ class RawConfig(BaseModel): major_on_zero: bool = True allow_zero_version: bool = True remote: RemoteConfig = RemoteConfig() + no_git_verify: bool = False tag_format: str = "v{version}" publish: PublishConfig = PublishConfig() version_toml: Optional[Tuple[str, ...]] = None @@ -347,6 +348,7 @@ class RuntimeContext: major_on_zero: bool allow_zero_version: bool prerelease: bool + no_git_verify: bool assets: List[str] commit_author: Actor commit_message: str @@ -596,6 +598,7 @@ def from_raw_config( upload_to_vcs_release=raw.publish.upload_to_vcs_release, global_cli_options=global_cli_options, masker=masker, + no_git_verify=raw.no_git_verify, ) # credential masker self.apply_log_masking(self.masker) diff --git a/tests/command_line/test_version.py b/tests/command_line/test_version.py index 416f2fe4c..4d610f74a 100644 --- a/tests/command_line/test_version.py +++ b/tests/command_line/test_version.py @@ -5,7 +5,9 @@ import os import re import shutil +from pathlib import Path from subprocess import CompletedProcess +from textwrap import dedent from typing import TYPE_CHECKING from unittest import mock @@ -24,7 +26,6 @@ ) if TYPE_CHECKING: - from pathlib import Path from unittest.mock import MagicMock from click.testing import CliRunner @@ -547,6 +548,55 @@ def test_version_prints_current_version_if_no_new_version( assert result.stdout == "1.2.0-alpha.2\n" +def test_version_version_no_verify( + repo_with_single_branch_angular_commits: Repo, + cli_runner: CliRunner, + update_pyproject_toml: UpdatePyprojectTomlFn, +): + # setup: set configuration setting + update_pyproject_toml("tool.semantic_release.no_git_verify", True) + repo_with_single_branch_angular_commits.git.commit( + m="chore: adjust project configuration for --no-verify release commits", a=True + ) + # create executable pre-commit script + precommit_hook = Path( + repo_with_single_branch_angular_commits.git_dir, "hooks", "pre-commit" + ) + precommit_hook.parent.mkdir(parents=True, exist_ok=True) + precommit_hook.write_text( + dedent( + """\ + #!/bin/sh + echo >&2 "Always fail pre-commit" && exit 1; + """ + ) + ) + precommit_hook.chmod(0o754) + repo_with_single_branch_angular_commits.git.config( + "core.hookspath", + str( + precommit_hook.parent.relative_to( + repo_with_single_branch_angular_commits.working_dir + ) + ), + local=True, + ) + # Take measurement beforehand + head_before = repo_with_single_branch_angular_commits.head.commit + + # Execute + result = cli_runner.invoke( + main, [version_subcmd, "--patch", "--no-tag", "--no-push"] + ) + + # Evaluate + head_after = repo_with_single_branch_angular_commits.head.commit + + assert head_before != head_after # A commit has been made + assert head_before in repo_with_single_branch_angular_commits.head.commit.parents + assert result.exit_code == 0 + + @pytest.mark.parametrize("shell", ("/usr/bin/bash", "/usr/bin/zsh", "powershell")) def test_version_runs_build_command( repo_with_git_flow_angular_commits: Repo,