Repository: relekang/python-semantic-release
Pull request #341 (2021-06-08 14:11:43)

Feature: add option to omit tagging
I'm trying to use `python-semantic-release` in a monorepo, where I need to version individual libraries separately. This sadly gets blocked `python-semantic-release`: Some libraries could have the same version and while versioning would like to create the same (an existing) tag.

This PR solves this problem (the easy way for now) by adding an option to omit the tagging of commits. This obviously only works with the `version_source="commit"` option.

I'm relatively new to python, so any feedback on the implementation is highly appreciated :)

OT: it would be nice if `python-semantic-release` would support custom version string formats, e.g. like [lerna](https://github.com/lerna/lerna/tree/main/commands/version) for js does - this would enable alpha, beta, canary releases as well as custom version tags for individual libs in monorepos.
Should this be an interesting option, I would create a real issue for this and would throw in my dev hands to implement this :) 


Patch:
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 88fbdb9..7b2eac1 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -56,28 +56,34 @@ jobs:
       new_sha: ${{ steps.sha.outputs.SHA }}
 
     steps:
-      - uses: actions/checkout@v2
-      - name: Set up Python 3.8
+      - name: Set up Python 3.9
         uses: actions/setup-python@v1
         with:
-          python-version: 3.8
+          python-version: 3.9
+
+      - name: Checkout repository
+        uses: actions/checkout@v2
+
+      - name: Install Black
+        run: python -m pip install black
+
+      - name: Beautify with Black
+        run: python -m black .
+
+      - name: Install isort
+        run: python -m pip install "isort >=4,<5"
 
-      - name: Format code
-        run: |
-          python -m pip install black
-          python -m black .
       - name: Sort imports
-        run: |
-          python -m pip install "isort >=4,<5"
-          python -m isort -y -rc semantic_release tests
+        run: python -m isort -y -rc .
 
       - name: Commit and push changes
         uses: github-actions-x/commit@v2.5
         with:
           github-token: ${{ secrets.GITHUB_TOKEN }}
-          commit-message: 'style: improve code formatting'
+          commit-message: 'style: beautify ${{ github.sha }}'
           name: github-actions
           email: action@github.com
+
       - name: Get new SHA
         id: sha
         run: |
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d639f92..a196624 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,10 @@
 
 <!--next-version-placeholder-->
 
+## v7.15.6 (2021-06-08)
+### Fix
+* Update click and tomlkit ([#339](https://github.com/relekang/python-semantic-release/issues/339)) ([`947ea3b`](https://github.com/relekang/python-semantic-release/commit/947ea3bc0750735941446cf4a87bae20e750ba12))
+
 ## v7.15.5 (2021-05-26)
 ### Fix
 * Pin tomlkit to 0.7.0 ([`2cd0db4`](https://github.com/relekang/python-semantic-release/commit/2cd0db4537bb9497b72eb496f6bab003070672ab))
diff --git a/docs/conf.py b/docs/conf.py
index ac5500b..f2c4d4b 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -1,10 +1,11 @@
 # -*- coding: utf-8 -*-
-import sys
 import os
+import sys
+
+import semantic_release  # noqa
 
 sys.path.insert(0, os.path.abspath("."))
 sys.path.insert(0, os.path.abspath(".."))
-import semantic_release  # noqa
 
 # -- General configuration ------------------------------------------------
 
diff --git a/semantic_release/__init__.py b/semantic_release/__init__.py
index 78f74cc..dfce9ba 100644
--- a/semantic_release/__init__.py
+++ b/semantic_release/__init__.py
@@ -1,6 +1,6 @@
 """Semantic Release
 """
-__version__ = "7.15.5"
+__version__ = "7.15.6"
 
 
 from .errors import UnknownCommitMessageStyleError  # noqa; noqa
diff --git a/semantic_release/cli.py b/semantic_release/cli.py
index f14acf5..4495dd4 100644
--- a/semantic_release/cli.py
+++ b/semantic_release/cli.py
@@ -182,7 +182,8 @@ def bump_version(new_version, level_bump):
         config.get("version_source") == "commit",
     ):
         commit_new_version(new_version)
-    tag_new_version(new_version)
+    if config.get("version_source") == "tag" or config.get("tag_commit"):
+        tag_new_version(new_version)
 
     logger.info(f"Bumping with a {level_bump} version to {new_version}")
 
@@ -377,6 +378,7 @@ def main(**kwargs):
         "major_on_zero",
         "upload_to_pypi",
         "version_source",
+        "no_git_tag",
     ]:
         obj[key] = config.get(key)
     logger.debug(f"Main config: {obj}")
diff --git a/semantic_release/defaults.cfg b/semantic_release/defaults.cfg
index 3a000b8..f45e8a7 100644
--- a/semantic_release/defaults.cfg
+++ b/semantic_release/defaults.cfg
@@ -23,3 +23,4 @@ changelog_sections=feature,fix,breaking,documentation,performance,:boom:,:sparkl
 changelog_file=CHANGELOG.md
 changelog_placeholder=<!--next-version-placeholder-->
 changelog_scope=true
+tag_commit=true
diff --git a/semantic_release/settings.py b/semantic_release/settings.py
index 1bd6ddc..434934f 100644
--- a/semantic_release/settings.py
+++ b/semantic_release/settings.py
@@ -46,6 +46,7 @@ def _config_from_ini(paths):
         "remove_dist",
         "upload_to_pypi",
         "upload_to_release",
+        "tag_commit",
     }
 
     # Iterate through the sections so that default values are applied
diff --git a/setup.py b/setup.py
index 16b2947..f01ffcb 100644
--- a/setup.py
+++ b/setup.py
@@ -1,7 +1,8 @@
 import re
-from setuptools import find_packages, setup
 import sys
 
+from setuptools import find_packages, setup
+
 
 def _read_long_description():
     try:
@@ -34,7 +35,7 @@ setup(
     packages=find_packages(exclude=("tests",)),
     license="MIT",
     install_requires=[
-        "click>=7,<8",
+        "click>=7,<9",
         "click_log>=0.3,<1",
         "gitpython>=3.0.8,<4",
         "invoke>=1.4.1,<2",
@@ -43,7 +44,7 @@ setup(
         "requests>=2.25,<3",
         "wheel",
         "python-gitlab>=1.10,<3",
-        "tomlkit==0.7.0",
+        "tomlkit==0.7.2",
         "dotty-dict>=1.3.0,<2",
     ],
     extras_require={


Test patch:
diff --git a/tests/test_cli.py b/tests/test_cli.py
index 831b742..1592cc0 100644
--- a/tests/test_cli.py
+++ b/tests/test_cli.py
@@ -96,10 +96,9 @@ def test_version_by_tag_should_call_correct_functions(mocker):
     mocker.patch(
         "semantic_release.cli.config.get",
         wrapped_config_get(
-            version_source="tag",
+            version_source="tag"
         ),
     )
-    mocker.patch("semantic_release.cli.config.get", lambda *x, **y: False)
     mock_set_new_version = mocker.patch("semantic_release.cli.set_new_version")
     mock_tag_new_version = mocker.patch("semantic_release.cli.tag_new_version")
     mock_new_version = mocker.patch(
@@ -120,6 +119,36 @@ def test_version_by_tag_should_call_correct_functions(mocker):
     mock_set_new_version.assert_called_once_with("2.0.0")
     mock_tag_new_version.assert_called_once_with("2.0.0")
 
+def test_version_by_commit_without_tag_should_call_correct_functions(mocker):
+    mocker.patch(
+        "semantic_release.cli.config.get",
+        wrapped_config_get(
+            version_source="commit",
+            tag_commit=False
+        ),
+    )
+    mock_set_new_version = mocker.patch("semantic_release.cli.set_new_version")
+    mock_tag_new_version = mocker.patch("semantic_release.cli.tag_new_version")
+    mock_commit_new_version = mocker.patch("semantic_release.cli.commit_new_version")
+    mock_new_version = mocker.patch(
+        "semantic_release.cli.get_new_version", return_value="2.0.0"
+    )
+    mock_evaluate_bump = mocker.patch(
+        "semantic_release.cli.evaluate_version_bump", return_value="major"
+    )
+    mock_current_version = mocker.patch(
+        "semantic_release.cli.get_current_version", return_value="1.2.3"
+    )
+
+    version()
+
+    mock_current_version.assert_called_once_with()
+    mock_evaluate_bump.assert_called_once_with("1.2.3", None)
+    mock_new_version.assert_called_once_with("1.2.3", "major")
+    mock_set_new_version.assert_called_once_with("2.0.0")
+    mock_commit_new_version.assert_called_once_with("2.0.0")
+    assert not mock_tag_new_version.called
+
 
 def test_force_major(mocker, runner):
     mock_version = mocker.patch("semantic_release.cli.version")