Skip to content

Commit f6a681f

Browse files
ci: Check types in CI (#147)
Signed-off-by: Edgar Ramírez Mondragón <edgarrm358@gmail.com>
1 parent ed8c90d commit f6a681f

7 files changed

Lines changed: 519 additions & 243 deletions

File tree

.github/workflows/test.yml

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,33 @@ jobs:
2828
- "3.15"
2929
steps:
3030
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
31-
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
32-
id: setup-python
33-
with:
34-
python-version: ${{ matrix.python-version }}
35-
allow-prereleases: true
3631
- name: Install uv
3732
uses: astral-sh/setup-uv@eac588ad8def6316056a12d4907a9d4d84ff7a3b # v7.3.0
3833
with:
34+
python-version: ${{ matrix.python-version }}
3935
version: ">=0.9.0"
4036
- name: Install dependencies
41-
env:
42-
UV_PYTHON: ${{ steps.setup-python.outputs.python-path }}
4337
run: |
4438
uv sync
45-
4639
- name: Run tests
4740
run: |
4841
uv run pytest
42+
43+
types:
44+
name: Static Analysis
45+
runs-on: ubuntu-latest
46+
steps:
47+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
48+
- name: Install uv
49+
uses: astral-sh/setup-uv@eac588ad8def6316056a12d4907a9d4d84ff7a3b # v7.3.0
50+
with:
51+
version: ">=0.9.0"
52+
- name: Install dependencies
53+
run: |
54+
uv sync
55+
- name: Check types with mypy
56+
run: |
57+
uv run mypy cz_version_bump tests
58+
- name: Check types with ty
59+
run: |
60+
uv run ty check

.pre-commit-config.yaml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,13 @@ repos:
1515
- id: trailing-whitespace
1616

1717
- repo: https://github.com/astral-sh/ruff-pre-commit
18-
rev: v0.15.1
18+
rev: v0.15.9
1919
hooks:
20-
- id: ruff
21-
args: [ --fix ]
20+
- id: ruff-check
21+
args: [ --fix, --show-fixes ]
2222
- id: ruff-format
23+
24+
- repo: https://github.com/hukkin/mdformat
25+
rev: 1.0.0
26+
hooks:
27+
- id: mdformat

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@
22

33
Commitizen customized for Meltano projects (https://commitizen-tools.github.io/commitizen/customization)
44

5-
65
## Usage:
76

87
Install this Python package, and set the Commitizen config option `name` to `cz_version_bump`.
98

109
If using [`commitizen-action`](https://github.com/commitizen-tools/commitizen-action), this package can be installed using the `extra_requirements` option:
1110

12-
1311
```yml
1412
- name: Version bump
1513
uses: commitizen-tools/commitizen-action@master

cz_version_bump/__init__.py

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import sys
66
from collections import OrderedDict
77
from textwrap import dedent
8-
from typing import TYPE_CHECKING, Any, ClassVar
8+
from typing import TYPE_CHECKING, Any, ClassVar # noqa: F401
99

1010
from commitizen import defaults, git
1111
from commitizen.cz.base import BaseCommitizen
@@ -20,14 +20,16 @@
2020
from typing_extensions import override
2121

2222
if TYPE_CHECKING:
23-
from commitizen.defaults import Questions
23+
from collections.abc import Mapping
24+
25+
from commitizen.question import CzQuestion
2426

2527
issue_id_pattern = re.compile(r"\s+\(#(\d+)\)$")
2628

2729

2830
class MeltanoCommitizen(BaseCommitizen):
2931
bump_pattern = r"^(feat|fix|refactor|perf|break|docs|ci|chore|style|revert|test|build|packaging)(\(.+\))?(!)?" # noqa: E501
30-
bump_map: ClassVar = OrderedDict(
32+
bump_map = OrderedDict( # noqa: RUF012
3133
(
3234
(
3335
r"^break",
@@ -48,16 +50,6 @@ class MeltanoCommitizen(BaseCommitizen):
4850
)
4951
)
5052
commit_parser = r"^(?P<change_type>feat|fix|refactor|perf|break|docs|packaging)(?:\((?P<scope>[^()\r\n]*)\)|\()?(?P<breaking>!)?:\s(?P<message>.*)?" # noqa: E501
51-
schema_pattern = r"(feat|fix|refactor|perf|break|docs|ci|chore|style|revert|test|build|packaging)(?:\((?P<scope>[^()\r\n]*)\)|\()?(?P<breaking>!)?:(\s.*)" # noqa: E501
52-
schema = dedent(
53-
"""
54-
<type>(<scope>): <subject>
55-
<BLANK LINE>
56-
<body>
57-
<BLANK LINE>
58-
(BREAKING CHANGE: )<footer>
59-
"""
60-
).strip("\n")
6153
change_type_order = [ # noqa: RUF012
6254
"BREAKING CHANGES",
6355
"✨ New",
@@ -87,7 +79,25 @@ def __init__(self: MeltanoCommitizen, *args: Any, **kwargs: Any) -> None:
8779
self.thanker = Thanker(self.repo_name)
8880

8981
@override
90-
def questions(self: MeltanoCommitizen) -> Questions:
82+
def schema(self: MeltanoCommitizen) -> str:
83+
"""Schema definition of the commit message."""
84+
return dedent(
85+
"""
86+
<type>(<scope>): <subject>
87+
<BLANK LINE>
88+
<body>
89+
<BLANK LINE>
90+
(BREAKING CHANGE: )<footer>
91+
"""
92+
).strip("\n")
93+
94+
@override
95+
def schema_pattern(self: MeltanoCommitizen) -> str:
96+
"""Regex matching the schema used for message validation."""
97+
return r"(feat|fix|refactor|perf|break|docs|ci|chore|style|revert|test|build|packaging)(?:\((?P<scope>[^()\r\n]*)\)|\()?(?P<breaking>!)?:(\s.*)" # noqa: E501
98+
99+
@override
100+
def questions(self: MeltanoCommitizen) -> list[CzQuestion]:
91101
"""Questions regarding the commit message."""
92102
return [
93103
{
@@ -130,7 +140,7 @@ def questions(self: MeltanoCommitizen) -> Questions:
130140
]
131141

132142
@override
133-
def message(self: MeltanoCommitizen, answers: dict) -> str:
143+
def message(self: MeltanoCommitizen, answers: Mapping[str, Any]) -> str:
134144
"""Format the git message."""
135145
message_template = Template("{{change_type}}: {{message}}")
136146
return message_template.render(**answers)

cz_version_bump/git.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
def repo_name_from_git_remote() -> str:
55
git_remote_output = subprocess.run(
6-
("git", "remote", "-v"),
6+
("git", "remote", "-v"), # noqa: S607
77
stdout=subprocess.PIPE,
88
text=True,
99
check=False,

pyproject.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,18 @@ cz_version_bump = "cz_version_bump:MeltanoCommitizen"
1616

1717
[dependency-groups]
1818
dev = [
19+
{ include-group = "tests" },
20+
{ include-group = "typing" },
21+
]
22+
tests = [
1923
"pytest>=9",
2024
"pytest-httpserver>=1",
2125
]
26+
typing = [
27+
"mypy>=1.20.0",
28+
"ty>=0.0.29",
29+
{ include-group = "tests" },
30+
]
2231

2332
[tool.hatch.build.targets.sdist]
2433
include = ["cz_version_bump", "tests"]

0 commit comments

Comments
 (0)