aboutsummaryrefslogtreecommitdiff
path: root/.venv/lib/python3.12/site-packages/hatchet_sdk/semver.py
blob: 4bb9aa4f86504b1e8648958ee03d15ffec0c4c64 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
def bump_minor_version(version: str) -> str:
    """
    Bumps the minor version of a semantic version string. NOTE this doesn't follow full semver,
    missing the build metadata and pre-release version.

    :param version: A semantic version string in the format major.minor.patch
    :return: A string with the minor version bumped and patch version reset to 0
    :raises ValueError: If the input is not a valid semantic version string
    """
    # if it starts with a v, remove it
    had_v = False
    if version.startswith("v"):
        version = version[1:]
        had_v = True

    parts = version.split(".")
    if len(parts) != 3:
        raise ValueError(f"Invalid semantic version: {version}")

    try:
        major, minor, _ = map(int, parts)
    except ValueError:
        raise ValueError(f"Invalid semantic version: {version}")

    new_minor = minor + 1
    new_version = f"{major}.{new_minor}.0"

    if had_v:
        new_version = "v" + new_version
    return new_version