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

feat: custom git tag format support #373

Merged
merged 3 commits into from Aug 16, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions docs/configuration.rst
Expand Up @@ -435,3 +435,17 @@ If enabled, the status of the head commit will be checked and a release will onl
if the status is success.

Default: `false`

.. _config-tag_format:

``tag_format``
------------------
Git tag format. Accepts the following variables as format fields:

================ ========
Variable Contents
================ ========
``{version}`` The new version number in the format ``X.Y.Z``.
================ ========

Default: ``v{version}``
1 change: 1 addition & 0 deletions semantic_release/defaults.cfg
Expand Up @@ -24,3 +24,4 @@ changelog_file=CHANGELOG.md
changelog_placeholder=<!--next-version-placeholder-->
changelog_scope=true
tag_commit=true
tag_format=v{version}
6 changes: 4 additions & 2 deletions semantic_release/vcs_helpers.py
Expand Up @@ -196,11 +196,13 @@ def update_changelog_file(version: str, content_to_add: str):
@LoggedFunction(logger)
def tag_new_version(version: str):
"""
Create a new tag with the version number, prefixed with v.
Create a new tag with the version number, prefixed with v by default.

:param version: The version number used in the tag as a string.
"""
return repo.git.tag("-a", f"v{version}", m=f"v{version}")
tag_format = config.get("tag_format")
tag = tag_format.format(version=version)
return repo.git.tag("-a", tag, m=tag)


@check_repo
Expand Down
8 changes: 6 additions & 2 deletions tests/test_vcs_helpers.py
Expand Up @@ -103,9 +103,13 @@ def test_add_and_commit(mock_git, mocker, params):
mock_git.commit.assert_called_once_with(**params["commit_args"])


def test_tag_new_version(mock_git):
def test_tag_new_version(mock_git, mocker):
mocker.patch(
"semantic_release.vcs_helpers.config.get",
return_value="ver{version}",
)
tag_new_version("1.0.0")
mock_git.tag.assert_called_with("-a", "v1.0.0", m="v1.0.0")
mock_git.tag.assert_called_with("-a", "ver1.0.0", m="ver1.0.0")


def test_push_new_version(mock_git):
Expand Down