Skip to content

Commit 83c02fe

Browse files
committed
docs(bump.md): add documentation about the bump rule change
1 parent 8dd8d42 commit 83c02fe

File tree

1 file changed

+90
-2
lines changed

1 file changed

+90
-2
lines changed

docs/commands/bump.md

Lines changed: 90 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ cz bump --changelog
9999
### `--prerelease`
100100

101101
The bump is a pre-release bump, meaning that in addition to a possible version bump the new version receives a
102-
pre-release segment compatible with the bumps version scheme, where the segment consist of a _phase_ and a
102+
pre-release segment compatible with the bump's version scheme, where the segment consist of a _phase_ and a
103103
non-negative number. Supported options for `--prerelease` are the following phase names `alpha`, `beta`, or
104104
`rc` (release candidate). For more details, refer to the
105105
[Python Packaging User Guide](https://packaging.python.org/en/latest/specifications/version-specifiers/#pre-releases).
@@ -658,7 +658,95 @@ version_scheme = "semver"
658658

659659
## Custom bump
660660

661-
Read the [customizing section](../customization.md).
661+
You can create custom bump rules to define how version numbers should be incremented based on your commit messages. This is done by configuring three main components:
662+
663+
### Bump Pattern
664+
665+
The `bump_pattern` is a regex pattern string used to match commit messages. It defines the structure of your commit messages and captures named groups for different types of changes. The captured groups will be used as keys in the bump map.
666+
667+
Example:
668+
```python
669+
# Simple pattern matching major/minor/patch types
670+
r"^((?P<major>major)|(?P<minor>minor)|(?P<patch>patch))(?P<scope>\(.+\))?(?P<bang>!)?:"
671+
672+
# Conventional commits style pattern
673+
r"^((?P<minor>feat)|(?P<patch>fix|perf|refactor)|(?P<breaking>BREAKING[\-\ ]CHANGE))(?P<scope>\(.+\))?(?P<bang>!)?:"
674+
```
675+
676+
### Bump Map
677+
678+
The `bump_map` defines how different commit types map to version increments. The keys in this dictionary must match the named capture groups from your pattern. The values are the version increment types:
679+
680+
- `"MAJOR"`
681+
- `"MINOR"`
682+
- `"PATCH"`
683+
684+
Example for conventional commits:
685+
```python
686+
{
687+
# Breaking changes (either by type or bang)
688+
"breaking": "MAJOR", # When type is "BREAKING CHANGE"
689+
"bang": "MAJOR", # When commit ends with ! (e.g., feat!: new feature)
690+
# New features
691+
"minor": "MINOR",
692+
# Bug fixes and improvements
693+
"patch": "PATCH",
694+
}
695+
```
696+
697+
Or using regex patterns:
698+
```python
699+
{
700+
(r"^.+!$", "MAJOR"),
701+
(r"^BREAKING[\-\ ]CHANGE", "MAJOR"),
702+
(r"^feat", "MINOR"),
703+
(r"^fix", "PATCH"),
704+
(r"^refactor", "PATCH"),
705+
(r"^perf", "PATCH"),
706+
}
707+
```
708+
709+
### Major Version Zero Map
710+
711+
The `bump_map_major_version_zero` allows you to define different versioning behavior when your project is in initial development (major version is 0). This is useful for following semantic versioning principles where breaking changes in 0.x.x versions don't require a major version bump.
712+
713+
Example for conventional commits during initial development:
714+
```python
715+
{
716+
# Breaking changes (either by type or bang)
717+
"breaking": "MINOR", # When type is "BREAKING CHANGE"
718+
"bang": "MINOR", # When commit ends with ! (e.g., feat!: new feature)
719+
# New features
720+
"minor": "MINOR",
721+
# Bug fixes and improvements
722+
"patch": "PATCH",
723+
}
724+
```
725+
726+
Or with regex patterns:
727+
```python
728+
{
729+
(r"^.+!$", "MINOR"),
730+
(r"^BREAKING[\-\ ]CHANGE", "MINOR"),
731+
(r"^feat", "MINOR"),
732+
(r"^fix", "PATCH"),
733+
(r"^refactor", "PATCH"),
734+
(r"^perf", "PATCH"),
735+
}
736+
```
737+
738+
This configuration will handle commit messages like:
739+
740+
- `BREAKING CHANGE: remove deprecated API` → MAJOR (or MINOR in major version zero)
741+
- `feat!: add new API` → MAJOR (or MINOR in major version zero)
742+
- `feat: add new feature` → MINOR
743+
- `fix: fix bug` → PATCH
744+
- `perf: improve performance` → PATCH
745+
- `refactor: restructure code` → PATCH
746+
747+
For more details on implementing custom bump rules, see the [customization guide](../customization.md).
748+
749+
<!-- TODO: maybe sync the content with the customization guide? -->
662750

663751
[pep440]: https://www.python.org/dev/peps/pep-0440/
664752
[semver]: https://semver.org/

0 commit comments

Comments
 (0)