Skip to content

Commit 33f8d59

Browse files
committed
docs(bump.md): add documentation about the bump rule change
1 parent 7f0e33f commit 33f8d59

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).
@@ -659,7 +659,95 @@ version_scheme = "semver"
659659

660660
## Custom bump
661661

662-
Read the [customizing section](../customization.md).
662+
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:
663+
664+
### Bump Pattern
665+
666+
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.
667+
668+
Example:
669+
```python
670+
# Simple pattern matching major/minor/patch types
671+
r"^((?P<major>major)|(?P<minor>minor)|(?P<patch>patch))(?P<scope>\(.+\))?(?P<bang>!)?:"
672+
673+
# Conventional commits style pattern
674+
r"^((?P<minor>feat)|(?P<patch>fix|perf|refactor)|(?P<breaking>BREAKING[\-\ ]CHANGE))(?P<scope>\(.+\))?(?P<bang>!)?:"
675+
```
676+
677+
### Bump Map
678+
679+
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:
680+
681+
- `"MAJOR"`
682+
- `"MINOR"`
683+
- `"PATCH"`
684+
685+
Example for conventional commits:
686+
```python
687+
{
688+
# Breaking changes (either by type or bang)
689+
"breaking": "MAJOR", # When type is "BREAKING CHANGE"
690+
"bang": "MAJOR", # When commit ends with ! (e.g., feat!: new feature)
691+
# New features
692+
"minor": "MINOR",
693+
# Bug fixes and improvements
694+
"patch": "PATCH",
695+
}
696+
```
697+
698+
Or using regex patterns:
699+
```python
700+
{
701+
(r"^.+!$", "MAJOR"),
702+
(r"^BREAKING[\-\ ]CHANGE", "MAJOR"),
703+
(r"^feat", "MINOR"),
704+
(r"^fix", "PATCH"),
705+
(r"^refactor", "PATCH"),
706+
(r"^perf", "PATCH"),
707+
}
708+
```
709+
710+
### Major Version Zero Map
711+
712+
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.
713+
714+
Example for conventional commits during initial development:
715+
```python
716+
{
717+
# Breaking changes (either by type or bang)
718+
"breaking": "MINOR", # When type is "BREAKING CHANGE"
719+
"bang": "MINOR", # When commit ends with ! (e.g., feat!: new feature)
720+
# New features
721+
"minor": "MINOR",
722+
# Bug fixes and improvements
723+
"patch": "PATCH",
724+
}
725+
```
726+
727+
Or with regex patterns:
728+
```python
729+
{
730+
(r"^.+!$", "MINOR"),
731+
(r"^BREAKING[\-\ ]CHANGE", "MINOR"),
732+
(r"^feat", "MINOR"),
733+
(r"^fix", "PATCH"),
734+
(r"^refactor", "PATCH"),
735+
(r"^perf", "PATCH"),
736+
}
737+
```
738+
739+
This configuration will handle commit messages like:
740+
741+
- `BREAKING CHANGE: remove deprecated API` → MAJOR (or MINOR in major version zero)
742+
- `feat!: add new API` → MAJOR (or MINOR in major version zero)
743+
- `feat: add new feature` → MINOR
744+
- `fix: fix bug` → PATCH
745+
- `perf: improve performance` → PATCH
746+
- `refactor: restructure code` → PATCH
747+
748+
For more details on implementing custom bump rules, see the [customization guide](../customization.md).
749+
750+
<!-- TODO: maybe sync the content with the customization guide? -->
663751

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

0 commit comments

Comments
 (0)