From 67d99f7ac9d2fda648b9529862183506dab06a9d Mon Sep 17 00:00:00 2001 From: gpongelli Date: Thu, 9 Jun 2022 19:36:39 +0200 Subject: [PATCH 01/28] feat(bump): add signed tag support for bump command --- commitizen/cli.py | 6 ++++++ commitizen/commands/bump.py | 3 +++ commitizen/git.py | 18 ++++++++++++++++-- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/commitizen/cli.py b/commitizen/cli.py index 0f2d52efc9..dc349ba2bf 100644 --- a/commitizen/cli.py +++ b/commitizen/cli.py @@ -160,6 +160,12 @@ "help": "create annotated tag instead of lightweight one", "action": "store_true", }, + { + "name": ["--signed-tag", "-st"], + "help": "sign tag instead of lightweight one", + "default": False, + "action": "store_true", + }, { "name": ["--changelog-to-stdout"], "action": "store_true", diff --git a/commitizen/commands/bump.py b/commitizen/commands/bump.py index e0779cd625..f515652d66 100644 --- a/commitizen/commands/bump.py +++ b/commitizen/commands/bump.py @@ -41,6 +41,7 @@ def __init__(self, config: BaseConfig, arguments: dict): "increment", "bump_message", "annotated_tag", + "signed_tag", ] if arguments[key] is not None }, @@ -233,6 +234,8 @@ def __call__(self): # noqa: C901 new_tag_version, annotated=self.bump_settings.get("annotated_tag", False) or bool(self.config.settings.get("annotated_tag", False)), + signed=self.bump_settings.get("signed_tag", False) + or bool(self.config.settings.get("signed_tag", False)), ) if c.return_code != 0: raise BumpTagFailedError(c.err) diff --git a/commitizen/git.py b/commitizen/git.py index 98ee40f2f2..f43d3656fd 100644 --- a/commitizen/git.py +++ b/commitizen/git.py @@ -1,3 +1,4 @@ +import re import os from pathlib import Path from tempfile import NamedTemporaryFile @@ -58,8 +59,13 @@ def from_line(cls, line: str, inner_delimiter: str) -> "GitTag": return cls(name=name, rev=obj, date=date) -def tag(tag: str, annotated: bool = False) -> cmd.Command: - c = cmd.run(f"git tag -a {tag} -m {tag}" if annotated else f"git tag {tag}") +def tag(tag: str, annotated: bool = False, signed: bool = False) -> cmd.Command: + _opt = "" + if annotated: + _opt = f"-a {tag} -m" + if signed: + _opt = f"-s {tag} -m" + c = cmd.run(f"git tag {_opt} {tag}") return c @@ -136,6 +142,14 @@ def tag_exist(tag: str) -> bool: return tag in c.out +def is_signed_tag(tag: str) -> bool: + c = cmd.run(f"git tag -v {tag}") + _ret = False + if re.match("gpg: Signature made [0-9/:A-Za-z ]*", c.err): + _ret = True + return _ret + + def get_latest_tag_name() -> Optional[str]: c = cmd.run("git describe --abbrev=0 --tags") if c.err: From e18b89c4c6f8937932b8367f3de6387c8eabf19b Mon Sep 17 00:00:00 2001 From: gpongelli Date: Thu, 9 Jun 2022 19:37:24 +0200 Subject: [PATCH 02/28] docs: added new argument to docs --- docs/bump.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/bump.md b/docs/bump.md index 8062044a76..a45ea7f88e 100644 --- a/docs/bump.md +++ b/docs/bump.md @@ -58,7 +58,7 @@ usage: cz bump [-h] [--dry-run] [--files-only] [--local-version] [--changelog] [--no-verify] [--yes] [--tag-format TAG_FORMAT] [--bump-message BUMP_MESSAGE] [--prerelease {alpha,beta,rc}] [--increment {MAJOR,MINOR,PATCH}] [--check-consistency] - [--annotated-tag] [--changelog-to-stdout] [--retry] + [--annotated-tag] [--signed-tag] [--changelog-to-stdout] [--retry] options: -h, --help show this help message and exit @@ -83,6 +83,7 @@ options: check consistency among versions defined in commitizen configuration and version_files --annotated-tag, -at create annotated tag instead of lightweight one + --signed-tag, -st create a signed tag instead of lightweight one or annotated tag --changelog-to-stdout Output changelog to the stdout --retry retry commit if it fails the 1st time From 049a19488418042d72561a8f27305193b07150a1 Mon Sep 17 00:00:00 2001 From: gpongelli Date: Thu, 9 Jun 2022 19:38:38 +0200 Subject: [PATCH 03/28] test: tests for signed tag and assert for annotated tags --- tests/commands/test_bump_command.py | 41 +++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tests/commands/test_bump_command.py b/tests/commands/test_bump_command.py index da15174c5d..0e056f6f07 100644 --- a/tests/commands/test_bump_command.py +++ b/tests/commands/test_bump_command.py @@ -66,6 +66,24 @@ def test_bump_minor_increment_annotated(commit_msg, mocker): cmd_res = cmd.run('git for-each-ref refs/tags --format "%(objecttype):%(refname)"') assert tag_exists is True and "tag:refs/tags/0.2.0\n" in cmd_res.out + _is_signed = git.is_signed_tag("0.2.0") + assert _is_signed is False + + +@pytest.mark.parametrize("commit_msg", ("feat: new file", "feat(user): new file")) +@pytest.mark.usefixtures("tmp_commitizen_project") +def test_bump_minor_increment_annotated(commit_msg, mocker): + create_file_and_commit(commit_msg) + testargs = ["cz", "bump", "--yes", "--signed-tag"] + mocker.patch.object(sys, "argv", testargs) + cli.main() + tag_exists = git.tag_exist("0.2.0") + cmd_res = cmd.run('git for-each-ref refs/tags --format "%(objecttype):%(refname)"') + assert tag_exists is True and "tag:refs/tags/0.2.0\n" in cmd_res.out + + _is_signed = git.is_signed_tag("0.2.0") + assert _is_signed is True + @pytest.mark.parametrize("commit_msg", ("feat: new file", "feat(user): new file")) def test_bump_minor_increment_annotated_config_file( @@ -83,6 +101,29 @@ def test_bump_minor_increment_annotated_config_file( cmd_res = cmd.run('git for-each-ref refs/tags --format "%(objecttype):%(refname)"') assert tag_exists is True and "tag:refs/tags/0.2.0\n" in cmd_res.out + _is_signed = git.is_signed_tag("0.2.0") + assert _is_signed is False + + +@pytest.mark.parametrize("commit_msg", ("feat: new file", "feat(user): new file")) +def test_bump_minor_increment_signed_config_file( + commit_msg, mocker, tmp_commitizen_project +): + tmp_commitizen_cfg_file = tmp_commitizen_project.join("pyproject.toml") + tmp_commitizen_cfg_file.write( + f"{tmp_commitizen_cfg_file.read()}\n" f"signed_tag = 1" + ) + create_file_and_commit(commit_msg) + testargs = ["cz", "bump", "--yes"] + mocker.patch.object(sys, "argv", testargs) + cli.main() + tag_exists = git.tag_exist("0.2.0") + cmd_res = cmd.run('git for-each-ref refs/tags --format "%(objecttype):%(refname)"') + assert tag_exists is True and "tag:refs/tags/0.2.0\n" in cmd_res.out + + _is_signed = git.is_signed_tag("0.2.0") + assert _is_signed is True + @pytest.mark.usefixtures("tmp_commitizen_project") @pytest.mark.parametrize( From 3acd8ce848ba239d4ebb6dea2ee64fb317797110 Mon Sep 17 00:00:00 2001 From: gpongelli Date: Fri, 10 Jun 2022 14:59:56 +0200 Subject: [PATCH 04/28] fix(test): set git to work with gpg --- tests/commands/test_bump_command.py | 8 ++++---- tests/conftest.py | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/tests/commands/test_bump_command.py b/tests/commands/test_bump_command.py index 0e056f6f07..2434d6a2d2 100644 --- a/tests/commands/test_bump_command.py +++ b/tests/commands/test_bump_command.py @@ -71,8 +71,8 @@ def test_bump_minor_increment_annotated(commit_msg, mocker): @pytest.mark.parametrize("commit_msg", ("feat: new file", "feat(user): new file")) -@pytest.mark.usefixtures("tmp_commitizen_project") -def test_bump_minor_increment_annotated(commit_msg, mocker): +@pytest.mark.usefixtures("tmp_commitizen_project_with_gpg") +def test_bump_minor_increment_signed(commit_msg, mocker): create_file_and_commit(commit_msg) testargs = ["cz", "bump", "--yes", "--signed-tag"] mocker.patch.object(sys, "argv", testargs) @@ -107,9 +107,9 @@ def test_bump_minor_increment_annotated_config_file( @pytest.mark.parametrize("commit_msg", ("feat: new file", "feat(user): new file")) def test_bump_minor_increment_signed_config_file( - commit_msg, mocker, tmp_commitizen_project + commit_msg, mocker, tmp_commitizen_project_with_gpg ): - tmp_commitizen_cfg_file = tmp_commitizen_project.join("pyproject.toml") + tmp_commitizen_cfg_file = tmp_commitizen_project_with_gpg.join("pyproject.toml") tmp_commitizen_cfg_file.write( f"{tmp_commitizen_cfg_file.read()}\n" f"signed_tag = 1" ) diff --git a/tests/conftest.py b/tests/conftest.py index aec79c2db3..c30314d280 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,5 +1,6 @@ import os +import re import pytest from commitizen import cmd, defaults @@ -23,6 +24,31 @@ def tmp_commitizen_project(tmp_git_project): yield tmp_git_project +@pytest.fixture(scope="function") +def tmp_commitizen_project_with_gpg(tmp_commitizen_project): + _gpg_file = tmp_commitizen_project.join('gpg_setup') + with open(_gpg_file, "w", newline='') as f: + f.write("Key-Type: default" + os.linesep) + f.write("Subkey-Type: default" + os.linesep) + f.write("Name-Real: Joe Tester" + os.linesep) + f.write("Name-Comment: with stupid passphrase" + os.linesep) + f.write("Name-Email: joe@foo.bar" + os.linesep) + f.write("Expire-Date: 0" + os.linesep) + f.write("Passphrase: abc" + os.linesep) + + cmd.run(f"gpg --batch --generate-key {_gpg_file}") + + _new_key = cmd.run(f"gpg --list-secret-keys joe@foo.bar") + _m = re.search(f"[a-zA-Z0-9 \[\]-_]*{os.linesep}[ ]*([0-9A-Za-z]*){os.linesep}[{os.linesep}a-zA-Z0-9 \[\]-_<>@]*", + _new_key.out) + if _m: + _key_id = _m.group(1) + cmd.run("git config --global commit.gpgsign true") + cmd.run(f"git config --global user.signingkey {_key_id}") + + yield tmp_commitizen_project + + @pytest.fixture() def config(): _config = BaseConfig() From cfe9c829d1d25a5b482f00e1917f6143a2983c93 Mon Sep 17 00:00:00 2001 From: gpongelli Date: Mon, 13 Jun 2022 11:05:48 +0200 Subject: [PATCH 05/28] pass black, isort, flake8 checks --- commitizen/git.py | 2 +- tests/conftest.py | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/commitizen/git.py b/commitizen/git.py index f43d3656fd..3c86135f8c 100644 --- a/commitizen/git.py +++ b/commitizen/git.py @@ -1,5 +1,5 @@ -import re import os +import re from pathlib import Path from tempfile import NamedTemporaryFile from typing import List, Optional diff --git a/tests/conftest.py b/tests/conftest.py index c30314d280..49aa9840f4 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,6 +1,6 @@ import os - import re + import pytest from commitizen import cmd, defaults @@ -26,8 +26,8 @@ def tmp_commitizen_project(tmp_git_project): @pytest.fixture(scope="function") def tmp_commitizen_project_with_gpg(tmp_commitizen_project): - _gpg_file = tmp_commitizen_project.join('gpg_setup') - with open(_gpg_file, "w", newline='') as f: + _gpg_file = tmp_commitizen_project.join("gpg_setup") + with open(_gpg_file, "w", newline="") as f: f.write("Key-Type: default" + os.linesep) f.write("Subkey-Type: default" + os.linesep) f.write("Name-Real: Joe Tester" + os.linesep) @@ -38,9 +38,11 @@ def tmp_commitizen_project_with_gpg(tmp_commitizen_project): cmd.run(f"gpg --batch --generate-key {_gpg_file}") - _new_key = cmd.run(f"gpg --list-secret-keys joe@foo.bar") - _m = re.search(f"[a-zA-Z0-9 \[\]-_]*{os.linesep}[ ]*([0-9A-Za-z]*){os.linesep}[{os.linesep}a-zA-Z0-9 \[\]-_<>@]*", - _new_key.out) + _new_key = cmd.run("gpg --list-secret-keys joe@foo.bar") + _m = re.search( + rf"[a-zA-Z0-9 \[\]-_]*{os.linesep}[ ]*([0-9A-Za-z]*){os.linesep}[{os.linesep}a-zA-Z0-9 \[\]-_<>@]*", + _new_key.out, + ) if _m: _key_id = _m.group(1) cmd.run("git config --global commit.gpgsign true") From e4c210ada6f029ab67eb30a5e28b9b67d78e44e0 Mon Sep 17 00:00:00 2001 From: gpongelli Date: Mon, 13 Jun 2022 11:14:28 +0200 Subject: [PATCH 06/28] setup a gpg key with no passphrase --- tests/conftest.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 49aa9840f4..8bff647a90 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -34,9 +34,8 @@ def tmp_commitizen_project_with_gpg(tmp_commitizen_project): f.write("Name-Comment: with stupid passphrase" + os.linesep) f.write("Name-Email: joe@foo.bar" + os.linesep) f.write("Expire-Date: 0" + os.linesep) - f.write("Passphrase: abc" + os.linesep) - cmd.run(f"gpg --batch --generate-key {_gpg_file}") + cmd.run(f"gpg --batch --passphrase '' --pinentry-mode loopback --generate-key {_gpg_file}") _new_key = cmd.run("gpg --list-secret-keys joe@foo.bar") _m = re.search( From 8d55a89b0c14a8aba3cce898191ff27dc9a5b798 Mon Sep 17 00:00:00 2001 From: gpongelli Date: Mon, 13 Jun 2022 11:33:46 +0200 Subject: [PATCH 07/28] reformatted file --- tests/conftest.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index 8bff647a90..f4c2a3fd9d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -35,7 +35,9 @@ def tmp_commitizen_project_with_gpg(tmp_commitizen_project): f.write("Name-Email: joe@foo.bar" + os.linesep) f.write("Expire-Date: 0" + os.linesep) - cmd.run(f"gpg --batch --passphrase '' --pinentry-mode loopback --generate-key {_gpg_file}") + cmd.run( + f"gpg --batch --passphrase '' --pinentry-mode loopback --generate-key {_gpg_file}" + ) _new_key = cmd.run("gpg --list-secret-keys joe@foo.bar") _m = re.search( From e545b0d54140ae2e0509c1945fed58c0c8282add Mon Sep 17 00:00:00 2001 From: gpongelli Date: Mon, 13 Jun 2022 14:08:38 +0200 Subject: [PATCH 08/28] temp key expires in 1 day --- tests/conftest.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index f4c2a3fd9d..cb69cf8415 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -27,25 +27,27 @@ def tmp_commitizen_project(tmp_git_project): @pytest.fixture(scope="function") def tmp_commitizen_project_with_gpg(tmp_commitizen_project): _gpg_file = tmp_commitizen_project.join("gpg_setup") + _signer_mail = "joe@foo.bar" with open(_gpg_file, "w", newline="") as f: f.write("Key-Type: default" + os.linesep) f.write("Subkey-Type: default" + os.linesep) f.write("Name-Real: Joe Tester" + os.linesep) f.write("Name-Comment: with stupid passphrase" + os.linesep) - f.write("Name-Email: joe@foo.bar" + os.linesep) - f.write("Expire-Date: 0" + os.linesep) + f.write(f"Name-Email: {_signer_mail}" + os.linesep) + f.write("Expire-Date: 1" + os.linesep) cmd.run( f"gpg --batch --passphrase '' --pinentry-mode loopback --generate-key {_gpg_file}" ) - _new_key = cmd.run("gpg --list-secret-keys joe@foo.bar") + _new_key = cmd.run(f"gpg --list-secret-keys {_signer_mail}") _m = re.search( rf"[a-zA-Z0-9 \[\]-_]*{os.linesep}[ ]*([0-9A-Za-z]*){os.linesep}[{os.linesep}a-zA-Z0-9 \[\]-_<>@]*", _new_key.out, ) if _m: _key_id = _m.group(1) + print(f"Key {_key_id} found for {_signer_mail}") cmd.run("git config --global commit.gpgsign true") cmd.run(f"git config --global user.signingkey {_key_id}") From 12987f493b0def7a5530dab5f2247d1f96e48feb Mon Sep 17 00:00:00 2001 From: gpongelli Date: Mon, 13 Jun 2022 14:37:51 +0200 Subject: [PATCH 09/28] avoid DecodeError on non-english execution --- commitizen/cmd.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/commitizen/cmd.py b/commitizen/cmd.py index fb041c9faf..3a21c376f1 100644 --- a/commitizen/cmd.py +++ b/commitizen/cmd.py @@ -20,4 +20,10 @@ def run(cmd: str) -> Command: ) stdout, stderr = process.communicate() return_code = process.returncode - return Command(stdout.decode(), stderr.decode(), stdout, stderr, return_code) + return Command( + stdout.decode("iso-8859-1"), + stderr.decode("iso-8859-1"), + stdout, + stderr, + return_code, + ) From bed207b53a8d4837e43449786473cf34e2c773f3 Mon Sep 17 00:00:00 2001 From: gpongelli Date: Mon, 13 Jun 2022 15:02:26 +0200 Subject: [PATCH 10/28] debug for macos github actions, to be reverted --- tests/conftest.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index cb69cf8415..d5207bcff6 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -51,6 +51,10 @@ def tmp_commitizen_project_with_gpg(tmp_commitizen_project): cmd.run("git config --global commit.gpgsign true") cmd.run(f"git config --global user.signingkey {_key_id}") + # debug for mac github actions + _check_macos = cmd.run('echo "test" | gpg --clearsign') + print(f"MACOS CHECK:\n{_check_macos.out}\n{_check_macos.err}") + yield tmp_commitizen_project From 95555bea53e5f516480dc00536fee29dc2b14faa Mon Sep 17 00:00:00 2001 From: gpongelli Date: Mon, 13 Jun 2022 15:14:07 +0200 Subject: [PATCH 11/28] use same mail and name as signer info to fix macos --- tests/conftest.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index d5207bcff6..4ab4393920 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -27,11 +27,11 @@ def tmp_commitizen_project(tmp_git_project): @pytest.fixture(scope="function") def tmp_commitizen_project_with_gpg(tmp_commitizen_project): _gpg_file = tmp_commitizen_project.join("gpg_setup") - _signer_mail = "joe@foo.bar" + _signer_mail = "action@github.com" with open(_gpg_file, "w", newline="") as f: f.write("Key-Type: default" + os.linesep) f.write("Subkey-Type: default" + os.linesep) - f.write("Name-Real: Joe Tester" + os.linesep) + f.write("Name-Real: GitHub Action" + os.linesep) f.write("Name-Comment: with stupid passphrase" + os.linesep) f.write(f"Name-Email: {_signer_mail}" + os.linesep) f.write("Expire-Date: 1" + os.linesep) From 6b8d38334955b16d04d61308df05efc0dc754aa5 Mon Sep 17 00:00:00 2001 From: gpongelli Date: Mon, 13 Jun 2022 15:29:00 +0200 Subject: [PATCH 12/28] more macos debug to be removed once solved --- tests/conftest.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 4ab4393920..027a0ee5e8 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,4 +1,5 @@ import os +import platform import re import pytest @@ -52,8 +53,15 @@ def tmp_commitizen_project_with_gpg(tmp_commitizen_project): cmd.run(f"git config --global user.signingkey {_key_id}") # debug for mac github actions - _check_macos = cmd.run('echo "test" | gpg --clearsign') - print(f"MACOS CHECK:\n{_check_macos.out}\n{_check_macos.err}") + if platform.system().lower() == "darwin": + _check_macos = cmd.run('echo "test" | gpg --clearsign') + print(f"MACOS CHECK:\n{_check_macos.out}\n{_check_macos.err}") + + _key_exist_macos = cmd.run("gpg --list-secret-keys") + print(f"MACOS List keys:\n{_key_exist_macos.out}\n{_key_exist_macos.err}") + + _key_gpg2_macos = cmd.run("gpg2 --list-keys") + print(f"MACOS List keys:\n{_key_gpg2_macos.out}\n{_key_gpg2_macos.err}") yield tmp_commitizen_project From b04533f152514b93087ade18d24aed8eb11b326f Mon Sep 17 00:00:00 2001 From: gpongelli Date: Mon, 13 Jun 2022 15:34:57 +0200 Subject: [PATCH 13/28] check if key is created --- tests/conftest.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index 027a0ee5e8..d70060d074 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -46,6 +46,10 @@ def tmp_commitizen_project_with_gpg(tmp_commitizen_project): rf"[a-zA-Z0-9 \[\]-_]*{os.linesep}[ ]*([0-9A-Za-z]*){os.linesep}[{os.linesep}a-zA-Z0-9 \[\]-_<>@]*", _new_key.out, ) + # debug for mac github actions + if platform.system().lower() == "darwin": + print(f"MAC OS: new key created?\n{_new_key.out}\n{_new_key.err}") + if _m: _key_id = _m.group(1) print(f"Key {_key_id} found for {_signer_mail}") @@ -60,7 +64,7 @@ def tmp_commitizen_project_with_gpg(tmp_commitizen_project): _key_exist_macos = cmd.run("gpg --list-secret-keys") print(f"MACOS List keys:\n{_key_exist_macos.out}\n{_key_exist_macos.err}") - _key_gpg2_macos = cmd.run("gpg2 --list-keys") + _key_gpg2_macos = cmd.run("gpg --list-keys") print(f"MACOS List keys:\n{_key_gpg2_macos.out}\n{_key_gpg2_macos.err}") yield tmp_commitizen_project From 478b900376ca5ae6208f0a198d473e54504cced3 Mon Sep 17 00:00:00 2001 From: gpongelli Date: Mon, 13 Jun 2022 15:48:02 +0200 Subject: [PATCH 14/28] install pinentry on macos --- .github/workflows/pythonpackage.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index 90ccbaaa30..04734fa24c 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -22,6 +22,10 @@ jobs: python -m pip install -U pip poetry poetry --version poetry install + - name: Install pinentry on macos + if: runner.os == 'Darwin' + run: | + brew install pinentry - name: Run tests and linters run: | git config --global user.email "action@github.com" From 559c4b73c535b4c920a95ce11a935efcc06547f1 Mon Sep 17 00:00:00 2001 From: gpongelli Date: Mon, 13 Jun 2022 15:50:29 +0200 Subject: [PATCH 15/28] fix alignment --- .github/workflows/pythonpackage.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index 04734fa24c..33a147d44c 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -24,8 +24,8 @@ jobs: poetry install - name: Install pinentry on macos if: runner.os == 'Darwin' - run: | - brew install pinentry + run: | + brew install pinentry - name: Run tests and linters run: | git config --global user.email "action@github.com" From cfa78be59ae7131ba85a8a20965317fad24b74ba Mon Sep 17 00:00:00 2001 From: gpongelli Date: Mon, 13 Jun 2022 15:56:23 +0200 Subject: [PATCH 16/28] Darwin not working, trying macOs --- .github/workflows/pythonpackage.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index 33a147d44c..8f41541e21 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -23,7 +23,7 @@ jobs: poetry --version poetry install - name: Install pinentry on macos - if: runner.os == 'Darwin' + if: runner.os == 'macOs' run: | brew install pinentry - name: Run tests and linters From c676c983d59a240d124adeefc6c28d162b9dd6db Mon Sep 17 00:00:00 2001 From: gpongelli Date: Mon, 13 Jun 2022 17:04:44 +0200 Subject: [PATCH 17/28] pinentry already present, check key creation --- .github/workflows/pythonpackage.yml | 4 ---- tests/conftest.py | 8 ++++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index 8f41541e21..90ccbaaa30 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -22,10 +22,6 @@ jobs: python -m pip install -U pip poetry poetry --version poetry install - - name: Install pinentry on macos - if: runner.os == 'macOs' - run: | - brew install pinentry - name: Run tests and linters run: | git config --global user.email "action@github.com" diff --git a/tests/conftest.py b/tests/conftest.py index d70060d074..48a0508314 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -37,18 +37,18 @@ def tmp_commitizen_project_with_gpg(tmp_commitizen_project): f.write(f"Name-Email: {_signer_mail}" + os.linesep) f.write("Expire-Date: 1" + os.linesep) - cmd.run( + _key = cmd.run( f"gpg --batch --passphrase '' --pinentry-mode loopback --generate-key {_gpg_file}" ) + # debug for mac github actions + if platform.system().lower() == "darwin": + print(f"MAC OS: new key created?\n{_key.out}\n{_key.err}") _new_key = cmd.run(f"gpg --list-secret-keys {_signer_mail}") _m = re.search( rf"[a-zA-Z0-9 \[\]-_]*{os.linesep}[ ]*([0-9A-Za-z]*){os.linesep}[{os.linesep}a-zA-Z0-9 \[\]-_<>@]*", _new_key.out, ) - # debug for mac github actions - if platform.system().lower() == "darwin": - print(f"MAC OS: new key created?\n{_new_key.out}\n{_new_key.err}") if _m: _key_id = _m.group(1) From 08bf3ae91e3007419902e122f73ace2163b3c765 Mon Sep 17 00:00:00 2001 From: gpongelli Date: Mon, 13 Jun 2022 17:14:50 +0200 Subject: [PATCH 18/28] use RSA, on macos default fallback to elliptic curve --- tests/conftest.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 48a0508314..163e733694 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -30,8 +30,10 @@ def tmp_commitizen_project_with_gpg(tmp_commitizen_project): _gpg_file = tmp_commitizen_project.join("gpg_setup") _signer_mail = "action@github.com" with open(_gpg_file, "w", newline="") as f: - f.write("Key-Type: default" + os.linesep) - f.write("Subkey-Type: default" + os.linesep) + f.write("Key-Type: RSA" + os.linesep) + f.write("Key-Length: 2048" + os.linesep) + f.write("Subkey-Type: RSA" + os.linesep) + f.write("Subkey-Length: 2048" + os.linesep) f.write("Name-Real: GitHub Action" + os.linesep) f.write("Name-Comment: with stupid passphrase" + os.linesep) f.write(f"Name-Email: {_signer_mail}" + os.linesep) From 9cb0cb8cdb133da0599bb925bb8083f208319db0 Mon Sep 17 00:00:00 2001 From: gpongelli Date: Mon, 13 Jun 2022 17:28:13 +0200 Subject: [PATCH 19/28] remove debug parts --- tests/conftest.py | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 163e733694..ecdb4b9dea 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,5 +1,4 @@ import os -import platform import re import pytest @@ -39,12 +38,9 @@ def tmp_commitizen_project_with_gpg(tmp_commitizen_project): f.write(f"Name-Email: {_signer_mail}" + os.linesep) f.write("Expire-Date: 1" + os.linesep) - _key = cmd.run( + cmd.run( f"gpg --batch --passphrase '' --pinentry-mode loopback --generate-key {_gpg_file}" ) - # debug for mac github actions - if platform.system().lower() == "darwin": - print(f"MAC OS: new key created?\n{_key.out}\n{_key.err}") _new_key = cmd.run(f"gpg --list-secret-keys {_signer_mail}") _m = re.search( @@ -54,21 +50,9 @@ def tmp_commitizen_project_with_gpg(tmp_commitizen_project): if _m: _key_id = _m.group(1) - print(f"Key {_key_id} found for {_signer_mail}") cmd.run("git config --global commit.gpgsign true") cmd.run(f"git config --global user.signingkey {_key_id}") - # debug for mac github actions - if platform.system().lower() == "darwin": - _check_macos = cmd.run('echo "test" | gpg --clearsign') - print(f"MACOS CHECK:\n{_check_macos.out}\n{_check_macos.err}") - - _key_exist_macos = cmd.run("gpg --list-secret-keys") - print(f"MACOS List keys:\n{_key_exist_macos.out}\n{_key_exist_macos.err}") - - _key_gpg2_macos = cmd.run("gpg --list-keys") - print(f"MACOS List keys:\n{_key_gpg2_macos.out}\n{_key_gpg2_macos.err}") - yield tmp_commitizen_project From 2d65bfa2dcf84efc3cbd0f5ee63f07a459959b3f Mon Sep 17 00:00:00 2001 From: gpongelli <842026+gpongelli@users.noreply.github.com> Date: Fri, 15 Jul 2022 14:48:29 +0200 Subject: [PATCH 20/28] align naming convention to git standard --- commitizen/cli.py | 4 ++-- commitizen/commands/bump.py | 12 ++++++------ docs/bump.md | 25 ++++++++++++++++++------- docs/config.md | 5 +++-- tests/commands/test_bump_command.py | 12 ++++-------- 5 files changed, 33 insertions(+), 25 deletions(-) diff --git a/commitizen/cli.py b/commitizen/cli.py index dc349ba2bf..7b0de81d42 100644 --- a/commitizen/cli.py +++ b/commitizen/cli.py @@ -156,12 +156,12 @@ "action": "store_true", }, { - "name": ["--annotated-tag", "-at"], + "name": ["--annotate", "-a"], "help": "create annotated tag instead of lightweight one", "action": "store_true", }, { - "name": ["--signed-tag", "-st"], + "name": ["--sign", "-s"], "help": "sign tag instead of lightweight one", "default": False, "action": "store_true", diff --git a/commitizen/commands/bump.py b/commitizen/commands/bump.py index f515652d66..327d084251 100644 --- a/commitizen/commands/bump.py +++ b/commitizen/commands/bump.py @@ -40,8 +40,8 @@ def __init__(self, config: BaseConfig, arguments: dict): "prerelease", "increment", "bump_message", - "annotated_tag", - "signed_tag", + "annotate", + "gpg_sign", ] if arguments[key] is not None }, @@ -232,10 +232,10 @@ def __call__(self): # noqa: C901 raise BumpCommitFailedError(f'2nd git.commit error: "{c.err.strip()}"') c = git.tag( new_tag_version, - annotated=self.bump_settings.get("annotated_tag", False) - or bool(self.config.settings.get("annotated_tag", False)), - signed=self.bump_settings.get("signed_tag", False) - or bool(self.config.settings.get("signed_tag", False)), + annotated=self.bump_settings.get("annotate", False) + or bool(self.config.settings.get("annotate", False)), + signed=self.bump_settings.get("gpg_sign", False) + or bool(self.config.settings.get("gpg_sign", False)), ) if c.return_code != 0: raise BumpTagFailedError(c.err) diff --git a/docs/bump.md b/docs/bump.md index a45ea7f88e..a7ed16d78a 100644 --- a/docs/bump.md +++ b/docs/bump.md @@ -58,7 +58,7 @@ usage: cz bump [-h] [--dry-run] [--files-only] [--local-version] [--changelog] [--no-verify] [--yes] [--tag-format TAG_FORMAT] [--bump-message BUMP_MESSAGE] [--prerelease {alpha,beta,rc}] [--increment {MAJOR,MINOR,PATCH}] [--check-consistency] - [--annotated-tag] [--signed-tag] [--changelog-to-stdout] [--retry] + [--annotate] [--sign] [--changelog-to-stdout] [--retry] options: -h, --help show this help message and exit @@ -82,8 +82,8 @@ options: --check-consistency, -cc check consistency among versions defined in commitizen configuration and version_files - --annotated-tag, -at create annotated tag instead of lightweight one - --signed-tag, -st create a signed tag instead of lightweight one or annotated tag + --annotate, -a create annotated tag instead of lightweight one + --sign, -s create a signed tag instead of lightweight one or annotated tag --changelog-to-stdout Output changelog to the stdout --retry retry commit if it fails the 1st time @@ -163,9 +163,9 @@ version = "5.3.5+0.1.0" If `--local-version` is used, it will bump only the local version `0.1.0` and keep the public version `5.3.5` intact, bumping to the version `5.3.5+0.2.0`. -### `--annotated-tag` +### `--annotate` -If `--annotated-tag` is used, commitizen will create annotated tags. Also available via configuration, in `pyproject.toml` or `.cz.toml`. +If `--annotate` is used, commitizen will create annotated tags. Also available via configuration, in `pyproject.toml` or `.cz.toml`. ### `--changelog-to-stdout` @@ -356,13 +356,24 @@ update_changelog_on_bump = true --- -### `annotated_tag` +### `annotate` When set to `true` commitizen will create annotated tags. ```toml [tool.commitizen] -annotated_tag = true +annotate = true +``` + +--- + +### `gpg_sign` + +When set to `true` commitizen will create gpg signed tags. + +```toml +[tool.commitizen] +gpg_sign = true ``` ## Custom bump diff --git a/docs/config.md b/docs/config.md index 6a7838e245..5927cd57cd 100644 --- a/docs/config.md +++ b/docs/config.md @@ -123,13 +123,14 @@ commitizen: ## Settings | Variable | Type | Default | Description | -| -------------------------- | ------ | --------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +|----------------------------| ------ | --------------------------- |-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | `name` | `str` | `"cz_conventional_commits"` | Name of the committing rules to use | | `version` | `str` | `None` | Current version. Example: "0.1.2" | | `version_files` | `list` | `[ ]` | Files were the version will be updated. A pattern to match a line, can also be specified, separated by `:` [See more][version_files] | | `tag_format` | `str` | `None` | Format for the git tag, useful for old projects, that use a convention like `"v1.2.1"`. [See more][tag_format] | | `update_changelog_on_bump` | `bool` | `false` | Create changelog when running `cz bump` | -| `annotated_tag` | `bool` | `false` | Use annotated tags instead of lightweight tags. [See difference][annotated-tags-vs-lightweight] | +| `annotate` | `bool` | `false` | Use annotated tags instead of lightweight tags. [See difference][annotated-tags-vs-lightweight] | +| `sign` | `bool` | `false` | Use gpg signed tags instead of lightweight tags. | | `bump_message` | `str` | `None` | Create custom commit message, useful to skip ci. [See more][bump_message] | | `allow_abort` | `bool` | `false` | Disallow empty commit messages, useful in ci. [See more][allow_abort] | | `changelog_file` | `str` | `CHANGELOG.md` | filename of exported changelog | diff --git a/tests/commands/test_bump_command.py b/tests/commands/test_bump_command.py index 2434d6a2d2..c926314fc9 100644 --- a/tests/commands/test_bump_command.py +++ b/tests/commands/test_bump_command.py @@ -59,7 +59,7 @@ def test_bump_minor_increment(commit_msg, mocker): @pytest.mark.usefixtures("tmp_commitizen_project") def test_bump_minor_increment_annotated(commit_msg, mocker): create_file_and_commit(commit_msg) - testargs = ["cz", "bump", "--yes", "--annotated-tag"] + testargs = ["cz", "bump", "--yes", "--annotate"] mocker.patch.object(sys, "argv", testargs) cli.main() tag_exists = git.tag_exist("0.2.0") @@ -74,7 +74,7 @@ def test_bump_minor_increment_annotated(commit_msg, mocker): @pytest.mark.usefixtures("tmp_commitizen_project_with_gpg") def test_bump_minor_increment_signed(commit_msg, mocker): create_file_and_commit(commit_msg) - testargs = ["cz", "bump", "--yes", "--signed-tag"] + testargs = ["cz", "bump", "--yes", "--gpg-sign"] mocker.patch.object(sys, "argv", testargs) cli.main() tag_exists = git.tag_exist("0.2.0") @@ -90,9 +90,7 @@ def test_bump_minor_increment_annotated_config_file( commit_msg, mocker, tmp_commitizen_project ): tmp_commitizen_cfg_file = tmp_commitizen_project.join("pyproject.toml") - tmp_commitizen_cfg_file.write( - f"{tmp_commitizen_cfg_file.read()}\n" f"annotated_tag = 1" - ) + tmp_commitizen_cfg_file.write(f"{tmp_commitizen_cfg_file.read()}\n" f"gpg_sign = 1") create_file_and_commit(commit_msg) testargs = ["cz", "bump", "--yes"] mocker.patch.object(sys, "argv", testargs) @@ -110,9 +108,7 @@ def test_bump_minor_increment_signed_config_file( commit_msg, mocker, tmp_commitizen_project_with_gpg ): tmp_commitizen_cfg_file = tmp_commitizen_project_with_gpg.join("pyproject.toml") - tmp_commitizen_cfg_file.write( - f"{tmp_commitizen_cfg_file.read()}\n" f"signed_tag = 1" - ) + tmp_commitizen_cfg_file.write(f"{tmp_commitizen_cfg_file.read()}\n" f"gpg_sign = 1") create_file_and_commit(commit_msg) testargs = ["cz", "bump", "--yes"] mocker.patch.object(sys, "argv", testargs) From d309a02245033814295836d85c6a0d40246c02fb Mon Sep 17 00:00:00 2001 From: gpongelli <842026+gpongelli@users.noreply.github.com> Date: Fri, 15 Jul 2022 15:26:18 +0200 Subject: [PATCH 21/28] Revert part of "align naming convention to git standard" This reverts commit 9d72ea92715ac6ec956c46cf84c69c48932a2bdf. --- commitizen/cli.py | 2 +- commitizen/commands/bump.py | 6 +++--- docs/bump.md | 13 ++++++------- docs/config.md | 4 ++-- tests/commands/test_bump_command.py | 6 ++++-- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/commitizen/cli.py b/commitizen/cli.py index 7b0de81d42..61736ecc6e 100644 --- a/commitizen/cli.py +++ b/commitizen/cli.py @@ -156,7 +156,7 @@ "action": "store_true", }, { - "name": ["--annotate", "-a"], + "name": ["--annotated-tag", "-at"], "help": "create annotated tag instead of lightweight one", "action": "store_true", }, diff --git a/commitizen/commands/bump.py b/commitizen/commands/bump.py index 327d084251..17f929bdb6 100644 --- a/commitizen/commands/bump.py +++ b/commitizen/commands/bump.py @@ -40,8 +40,8 @@ def __init__(self, config: BaseConfig, arguments: dict): "prerelease", "increment", "bump_message", - "annotate", "gpg_sign", + "annotated_tag", ] if arguments[key] is not None }, @@ -232,10 +232,10 @@ def __call__(self): # noqa: C901 raise BumpCommitFailedError(f'2nd git.commit error: "{c.err.strip()}"') c = git.tag( new_tag_version, - annotated=self.bump_settings.get("annotate", False) - or bool(self.config.settings.get("annotate", False)), signed=self.bump_settings.get("gpg_sign", False) or bool(self.config.settings.get("gpg_sign", False)), + annotated=self.bump_settings.get("annotated_tag", False) + or bool(self.config.settings.get("annotated_tag", False)), ) if c.return_code != 0: raise BumpTagFailedError(c.err) diff --git a/docs/bump.md b/docs/bump.md index a7ed16d78a..66719c1939 100644 --- a/docs/bump.md +++ b/docs/bump.md @@ -58,7 +58,7 @@ usage: cz bump [-h] [--dry-run] [--files-only] [--local-version] [--changelog] [--no-verify] [--yes] [--tag-format TAG_FORMAT] [--bump-message BUMP_MESSAGE] [--prerelease {alpha,beta,rc}] [--increment {MAJOR,MINOR,PATCH}] [--check-consistency] - [--annotate] [--sign] [--changelog-to-stdout] [--retry] + [--annotated-tag] [--gpg-sign] [--changelog-to-stdout] [--retry] options: -h, --help show this help message and exit @@ -82,8 +82,8 @@ options: --check-consistency, -cc check consistency among versions defined in commitizen configuration and version_files - --annotate, -a create annotated tag instead of lightweight one --sign, -s create a signed tag instead of lightweight one or annotated tag + --annotated-tag, -at create annotated tag instead of lightweight one --changelog-to-stdout Output changelog to the stdout --retry retry commit if it fails the 1st time @@ -163,9 +163,9 @@ version = "5.3.5+0.1.0" If `--local-version` is used, it will bump only the local version `0.1.0` and keep the public version `5.3.5` intact, bumping to the version `5.3.5+0.2.0`. -### `--annotate` +### `--annotated-tag` -If `--annotate` is used, commitizen will create annotated tags. Also available via configuration, in `pyproject.toml` or `.cz.toml`. +If `--annotated-tag` is used, commitizen will create annotated tags. Also available via configuration, in `pyproject.toml` or `.cz.toml`. ### `--changelog-to-stdout` @@ -356,14 +356,12 @@ update_changelog_on_bump = true --- -### `annotate` +### `annotated_tag` When set to `true` commitizen will create annotated tags. ```toml [tool.commitizen] -annotate = true -``` --- @@ -374,6 +372,7 @@ When set to `true` commitizen will create gpg signed tags. ```toml [tool.commitizen] gpg_sign = true +annotated_tag = true ``` ## Custom bump diff --git a/docs/config.md b/docs/config.md index 5927cd57cd..215a977208 100644 --- a/docs/config.md +++ b/docs/config.md @@ -123,14 +123,14 @@ commitizen: ## Settings | Variable | Type | Default | Description | -|----------------------------| ------ | --------------------------- |-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| -------------------------- | ------ | --------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `name` | `str` | `"cz_conventional_commits"` | Name of the committing rules to use | | `version` | `str` | `None` | Current version. Example: "0.1.2" | | `version_files` | `list` | `[ ]` | Files were the version will be updated. A pattern to match a line, can also be specified, separated by `:` [See more][version_files] | | `tag_format` | `str` | `None` | Format for the git tag, useful for old projects, that use a convention like `"v1.2.1"`. [See more][tag_format] | | `update_changelog_on_bump` | `bool` | `false` | Create changelog when running `cz bump` | -| `annotate` | `bool` | `false` | Use annotated tags instead of lightweight tags. [See difference][annotated-tags-vs-lightweight] | | `sign` | `bool` | `false` | Use gpg signed tags instead of lightweight tags. | +| `annotated_tag` | `bool` | `false` | Use annotated tags instead of lightweight tags. [See difference][annotated-tags-vs-lightweight] | | `bump_message` | `str` | `None` | Create custom commit message, useful to skip ci. [See more][bump_message] | | `allow_abort` | `bool` | `false` | Disallow empty commit messages, useful in ci. [See more][allow_abort] | | `changelog_file` | `str` | `CHANGELOG.md` | filename of exported changelog | diff --git a/tests/commands/test_bump_command.py b/tests/commands/test_bump_command.py index c926314fc9..daf3d42bac 100644 --- a/tests/commands/test_bump_command.py +++ b/tests/commands/test_bump_command.py @@ -59,7 +59,7 @@ def test_bump_minor_increment(commit_msg, mocker): @pytest.mark.usefixtures("tmp_commitizen_project") def test_bump_minor_increment_annotated(commit_msg, mocker): create_file_and_commit(commit_msg) - testargs = ["cz", "bump", "--yes", "--annotate"] + testargs = ["cz", "bump", "--yes", "--annotated-tag"] mocker.patch.object(sys, "argv", testargs) cli.main() tag_exists = git.tag_exist("0.2.0") @@ -90,7 +90,9 @@ def test_bump_minor_increment_annotated_config_file( commit_msg, mocker, tmp_commitizen_project ): tmp_commitizen_cfg_file = tmp_commitizen_project.join("pyproject.toml") - tmp_commitizen_cfg_file.write(f"{tmp_commitizen_cfg_file.read()}\n" f"gpg_sign = 1") + tmp_commitizen_cfg_file.write( + f"{tmp_commitizen_cfg_file.read()}\n" f"annotated_tag = 1" + ) create_file_and_commit(commit_msg) testargs = ["cz", "bump", "--yes"] mocker.patch.object(sys, "argv", testargs) From 29f8f860f322c3d2d614a47426190ed7a4df4abf Mon Sep 17 00:00:00 2001 From: gpongelli <842026+gpongelli@users.noreply.github.com> Date: Fri, 15 Jul 2022 15:31:51 +0200 Subject: [PATCH 22/28] align all to gpg_sign --- commitizen/cli.py | 2 +- docs/bump.md | 2 +- docs/config.md | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/commitizen/cli.py b/commitizen/cli.py index 61736ecc6e..82b08db67f 100644 --- a/commitizen/cli.py +++ b/commitizen/cli.py @@ -161,7 +161,7 @@ "action": "store_true", }, { - "name": ["--sign", "-s"], + "name": ["--gpg-sign", "-s"], "help": "sign tag instead of lightweight one", "default": False, "action": "store_true", diff --git a/docs/bump.md b/docs/bump.md index 66719c1939..bdccb30fbe 100644 --- a/docs/bump.md +++ b/docs/bump.md @@ -82,7 +82,7 @@ options: --check-consistency, -cc check consistency among versions defined in commitizen configuration and version_files - --sign, -s create a signed tag instead of lightweight one or annotated tag + --gpg-sign, -s create a signed tag instead of lightweight one or annotated tag --annotated-tag, -at create annotated tag instead of lightweight one --changelog-to-stdout Output changelog to the stdout diff --git a/docs/config.md b/docs/config.md index 215a977208..6ac36914b0 100644 --- a/docs/config.md +++ b/docs/config.md @@ -123,13 +123,13 @@ commitizen: ## Settings | Variable | Type | Default | Description | -| -------------------------- | ------ | --------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +|----------------------------| ------ | --------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `name` | `str` | `"cz_conventional_commits"` | Name of the committing rules to use | | `version` | `str` | `None` | Current version. Example: "0.1.2" | | `version_files` | `list` | `[ ]` | Files were the version will be updated. A pattern to match a line, can also be specified, separated by `:` [See more][version_files] | | `tag_format` | `str` | `None` | Format for the git tag, useful for old projects, that use a convention like `"v1.2.1"`. [See more][tag_format] | | `update_changelog_on_bump` | `bool` | `false` | Create changelog when running `cz bump` | -| `sign` | `bool` | `false` | Use gpg signed tags instead of lightweight tags. | +| `gpg_sign` | `bool` | `false` | Use gpg signed tags instead of lightweight tags. | | `annotated_tag` | `bool` | `false` | Use annotated tags instead of lightweight tags. [See difference][annotated-tags-vs-lightweight] | | `bump_message` | `str` | `None` | Create custom commit message, useful to skip ci. [See more][bump_message] | | `allow_abort` | `bool` | `false` | Disallow empty commit messages, useful in ci. [See more][allow_abort] | From 11e61638563bc3cef977ecf9e7494ebadf0f1018 Mon Sep 17 00:00:00 2001 From: gpongelli <842026+gpongelli@users.noreply.github.com> Date: Fri, 15 Jul 2022 16:22:54 +0200 Subject: [PATCH 23/28] fix: avoid that pytest overrides existing gpg config --- tests/conftest.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index ecdb4b9dea..9b91daf9ba 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -50,8 +50,8 @@ def tmp_commitizen_project_with_gpg(tmp_commitizen_project): if _m: _key_id = _m.group(1) - cmd.run("git config --global commit.gpgsign true") - cmd.run(f"git config --global user.signingkey {_key_id}") + cmd.run("git config commit.gpgsign true") + cmd.run(f"git config user.signingkey {_key_id}") yield tmp_commitizen_project From 5d1844ab08e767df90fab19afb245415a5fa5f53 Mon Sep 17 00:00:00 2001 From: gpongelli <842026+gpongelli@users.noreply.github.com> Date: Tue, 19 Jul 2022 15:20:41 +0200 Subject: [PATCH 24/28] feat: use chardet to get correct encoding --- commitizen/cmd.py | 6 ++++-- pyproject.toml | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/commitizen/cmd.py b/commitizen/cmd.py index 3a21c376f1..f621e147ad 100644 --- a/commitizen/cmd.py +++ b/commitizen/cmd.py @@ -1,6 +1,8 @@ import subprocess from typing import NamedTuple +import chardet + class Command(NamedTuple): out: str @@ -21,8 +23,8 @@ def run(cmd: str) -> Command: stdout, stderr = process.communicate() return_code = process.returncode return Command( - stdout.decode("iso-8859-1"), - stderr.decode("iso-8859-1"), + stdout.decode(chardet.detect(stdout)["encoding"]), + stderr.decode(chardet.detect(stderr)["encoding"]), stdout, stderr, return_code, diff --git a/pyproject.toml b/pyproject.toml index 5bec7cfb46..e94f877af5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -56,6 +56,7 @@ jinja2 = ">=2.10.3" pyyaml = ">=3.08" argcomplete = "^1.12.1" typing-extensions = "^4.0.1" +chardet = "^5.0.0" [tool.poetry.dev-dependencies] ipython = "^7.2" From 22c9dd81736e97e19d7088a452547a0aab843816 Mon Sep 17 00:00:00 2001 From: gpongelli <842026+gpongelli@users.noreply.github.com> Date: Tue, 19 Jul 2022 15:38:39 +0200 Subject: [PATCH 25/28] fix in case commitizen returns None --- commitizen/cmd.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/commitizen/cmd.py b/commitizen/cmd.py index f621e147ad..f65f5c8e76 100644 --- a/commitizen/cmd.py +++ b/commitizen/cmd.py @@ -23,8 +23,8 @@ def run(cmd: str) -> Command: stdout, stderr = process.communicate() return_code = process.returncode return Command( - stdout.decode(chardet.detect(stdout)["encoding"]), - stderr.decode(chardet.detect(stderr)["encoding"]), + stdout.decode(chardet.detect(stdout)["encoding"] or "utf-8"), + stderr.decode(chardet.detect(stderr)["encoding"] or "utf-8"), stdout, stderr, return_code, From 06c6d85c9473d60c158d75b6eac47d4b12b4b6c9 Mon Sep 17 00:00:00 2001 From: gpongelli <842026+gpongelli@users.noreply.github.com> Date: Tue, 19 Jul 2022 16:29:53 +0200 Subject: [PATCH 26/28] install stubs for chardet --- scripts/test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/test b/scripts/test index b5541d2d3e..71a005bf8e 100755 --- a/scripts/test +++ b/scripts/test @@ -9,5 +9,5 @@ ${PREFIX}pytest -n 3 --cov-report term-missing --cov-report=xml:coverage.xml --c ${PREFIX}black commitizen tests --check ${PREFIX}isort --check-only commitizen tests ${PREFIX}flake8 commitizen/ tests/ -${PREFIX}mypy commitizen/ tests/ +${PREFIX}mypy --install-types --non-interactive commitizen/ tests/ ${PREFIX}pydocstyle --convention=google --add-ignore=D1,D415 From f61e90ebe9ba78c7bec311fb8ee8e41e476c2d6e Mon Sep 17 00:00:00 2001 From: gpongelli <842026+gpongelli@users.noreply.github.com> Date: Fri, 22 Jul 2022 17:26:04 +0200 Subject: [PATCH 27/28] types-chardet installed into pyproject --- pyproject.toml | 1 + scripts/test | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index e94f877af5..70dfeed5c1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -82,6 +82,7 @@ mkdocs = "^1.0" mkdocs-material = "^4.1" pydocstyle = "^5.0.2" pytest-xdist = "^2.5.0" +types-chardet = "^5.0.2" [tool.poetry.scripts] cz = "commitizen.cli:main" diff --git a/scripts/test b/scripts/test index 71a005bf8e..b5541d2d3e 100755 --- a/scripts/test +++ b/scripts/test @@ -9,5 +9,5 @@ ${PREFIX}pytest -n 3 --cov-report term-missing --cov-report=xml:coverage.xml --c ${PREFIX}black commitizen tests --check ${PREFIX}isort --check-only commitizen tests ${PREFIX}flake8 commitizen/ tests/ -${PREFIX}mypy --install-types --non-interactive commitizen/ tests/ +${PREFIX}mypy commitizen/ tests/ ${PREFIX}pydocstyle --convention=google --add-ignore=D1,D415 From 2be6c41f33fe28e9e784c87fec23bb9f6246a3f9 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 22 Jul 2022 15:43:18 +0000 Subject: [PATCH 28/28] =?UTF-8?q?bump:=20version=202.28.1=20=E2=86=92=202.?= =?UTF-8?q?29.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .pre-commit-config.yaml | 2 +- CHANGELOG.md | 12 ++++++++++++ commitizen/__version__.py | 2 +- pyproject.toml | 4 ++-- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 771b0af3ea..9f9bcfb2ef 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -12,7 +12,7 @@ repos: - id: no-commit-to-branch - repo: https://github.com/commitizen-tools/commitizen - rev: v2.28.1 # automatically updated by Commitizen + rev: v2.29.0 # automatically updated by Commitizen hooks: - id: commitizen stages: [commit-msg] diff --git a/CHANGELOG.md b/CHANGELOG.md index 0acfd67771..f269842919 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,16 @@ +## v2.29.0 (2022-07-22) + +### Feat + +- use chardet to get correct encoding +- **bump**: add signed tag support for bump command + +### Fix + +- avoid that pytest overrides existing gpg config +- **test**: set git to work with gpg + ## v2.28.1 (2022-07-22) ### Fix diff --git a/commitizen/__version__.py b/commitizen/__version__.py index f604b6f4ce..ccaf0f0336 100644 --- a/commitizen/__version__.py +++ b/commitizen/__version__.py @@ -1 +1 @@ -__version__ = "2.28.1" +__version__ = "2.29.0" diff --git a/pyproject.toml b/pyproject.toml index 70dfeed5c1..a832db6dbd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.commitizen] -version = "2.28.1" +version = "2.29.0" tag_format = "v$version" version_files = [ "pyproject.toml:version", @@ -30,7 +30,7 @@ exclude = ''' [tool.poetry] name = "commitizen" -version = "2.28.1" +version = "2.29.0" description = "Python commitizen client tool" authors = ["Santiago Fraire "] license = "MIT"