Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from python-semantic-release:master #105

Merged
merged 4 commits into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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: >
Expand Down
18 changes: 18 additions & 0 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions semantic_release/cli/commands/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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(
Expand All @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions semantic_release/cli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
52 changes: 51 additions & 1 deletion tests/command_line/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -24,7 +26,6 @@
)

if TYPE_CHECKING:
from pathlib import Path
from unittest.mock import MagicMock

from click.testing import CliRunner
Expand Down Expand Up @@ -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,
Expand Down
Loading