From 77f47c7e905332ea56a7f4c2635476d1410ed3c7 Mon Sep 17 00:00:00 2001 From: perewall Date: Mon, 16 Aug 2021 11:39:03 +0300 Subject: [PATCH 1/3] feat: custom git tag format support --- semantic_release/defaults.cfg | 1 + semantic_release/vcs_helpers.py | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/semantic_release/defaults.cfg b/semantic_release/defaults.cfg index f45e8a700..6ceee2b0d 100644 --- a/semantic_release/defaults.cfg +++ b/semantic_release/defaults.cfg @@ -24,3 +24,4 @@ changelog_file=CHANGELOG.md changelog_placeholder= changelog_scope=true tag_commit=true +tag_format=v{version} diff --git a/semantic_release/vcs_helpers.py b/semantic_release/vcs_helpers.py index 6ca139fb2..31d2a3662 100644 --- a/semantic_release/vcs_helpers.py +++ b/semantic_release/vcs_helpers.py @@ -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 From ad5857c3d186d7dcb322d0b72f25c5c06386c979 Mon Sep 17 00:00:00 2001 From: perewall Date: Mon, 16 Aug 2021 11:47:25 +0300 Subject: [PATCH 2/3] test: add git tag format check --- tests/test_vcs_helpers.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/test_vcs_helpers.py b/tests/test_vcs_helpers.py index 6bc542015..969a0be6b 100644 --- a/tests/test_vcs_helpers.py +++ b/tests/test_vcs_helpers.py @@ -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): From 88751398126b4bbea7e35e913f61173d10c107dc Mon Sep 17 00:00:00 2001 From: perewall Date: Mon, 16 Aug 2021 11:50:11 +0300 Subject: [PATCH 3/3] docs: add tag_format config option --- docs/configuration.rst | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/docs/configuration.rst b/docs/configuration.rst index cb5eb2249..2a138591d 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -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}``