Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug when bumping pre-label #272

Closed
coordt opened this issue Dec 19, 2024 · 1 comment
Closed

Bug when bumping pre-label #272

coordt opened this issue Dec 19, 2024 · 1 comment

Comments

@coordt
Copy link
Member

coordt commented Dec 19, 2024

My parse, serialize and [tool.bumpversion.parts.pre_label] are pretty much a paste-in from the Automate the pre-release numbering section of the docs:

Configuration

parse = """(?x)
    (?P<major>0|[1-9]\\d*)\\.
    (?P<minor>0|[1-9]\\d*)\\.
    (?P<patch>0|[1-9]\\d*)
    (?:
        -                             # dash separator for pre-release section
        (?P<pre_label>[a-zA-Z-]+)     # pre-release label
        (?P<pre_n>0|[1-9]\\d*)        # pre-release version number
    )?                                # pre-release section is optional
"""

serialize = [
    "{major}.{minor}.{patch}-{pre_label}{distance_to_latest_tag}",
    "{major}.{minor}.{patch}",
]

[tool.bumpversion.parts.pre_label]
values = ["dev", "rc", "final"]
optional_value = "final"

My show-bump shows pre_label bumping up to rc as expected:

Pre-bump State

$ bump-my-version show-bump
0.1.2-dev2 ── bump ─┬─ major ───── 1.0.0-dev2
                    ├─ minor ───── 0.2.0-dev2
                    ├─ patch ───── 0.1.3-dev2
                    ╰─ pre_label ─ 0.1.2-rc2

After Bump

Instead of bump-my-version bump pre_label giving me 0.1.2-rc2, I get rc2 inserted in front of dev2

[tool.bumpversion]
current_version = "0.1.2-rc2-dev2"

The docs don't show any changes to the parse value. Am I missing something?

Originally posted by @dougscc in #271

@coordt
Copy link
Member Author

coordt commented Dec 19, 2024

The bug happens when the labels of the parsing do not match the labels of serialization, and the value is required.

In this example, when the pre_label is dev or rc and the pre_n value is greater than 0, it evaluates the labels_for_format against the version.required_components().

The required labels are {'patch', 'pre_label', 'minor', 'pre_n'}, while the correct serialization labels are {'minor', 'distance_to_latest_tag', 'patch', 'pre_label', 'major'}. The pre_n and the distance_to_latest_tag are equivalent but not currently recognized. When this happens, it defaults to the "{major}.{minor}.{patch}" format.

@coordt coordt closed this as completed in c027879 Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant