Skip to content

Commit

Permalink
feat: custom git tag format support (#373)
Browse files Browse the repository at this point in the history
* feat: custom git tag format support
* test: add git tag format check
* docs: add tag_format config option
  • Loading branch information
perewall committed Aug 16, 2021
1 parent 45ee34a commit 1d76632
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
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

0 comments on commit 1d76632

Please sign in to comment.