File: setup-release.py

package info (click to toggle)
python-maison 2.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 816 kB
  • sloc: python: 1,549; makefile: 9; sh: 5
file content (68 lines) | stat: -rw-r--r-- 2,067 bytes parent folder | download
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
"""Script responsible for preparing a release of the maison package."""

import argparse
import subprocess
from typing import Optional

from util import REPO_FOLDER
from util import bump_version
from util import check_dependencies
from util import create_release_branch
from util import get_bumped_package_version
from util import get_package_version


def main() -> None:
    """Parses args and passes through to setup_release."""
    parser: argparse.ArgumentParser = get_parser()
    args: argparse.Namespace = parser.parse_args()
    setup_release(increment=args.increment)


def get_parser() -> argparse.ArgumentParser:
    """Creates the argument parser for prepare-release."""
    parser: argparse.ArgumentParser = argparse.ArgumentParser(
        prog="prepare-release", usage="python ./scripts/prepare-release.py patch"
    )
    parser.add_argument(
        "increment",
        nargs="?",
        default=None,
        type=str,
        help="Increment type to use when preparing the release.",
        choices=["MAJOR", "MINOR", "PATCH", "PRERELEASE"],
    )
    return parser


def setup_release(increment: Optional[str] = None) -> None:
    """Prepares a release of the maison package.

    Sets up a release branch from the main branch, bumps the version, and creates a release commit. Does not tag the
    release or push any changes.
    """
    check_dependencies(path=REPO_FOLDER, dependencies=["git"])

    current_version: str = get_package_version()
    new_version: str = get_bumped_package_version(increment=increment)
    create_release_branch(new_version=new_version)
    bump_version(increment=increment)

    commands: list[list[str]] = [
        ["uv", "sync", "--all-groups"],
        ["git", "add", "."],
        [
            "git",
            "commit",
            "-m",
            f"bump: version {current_version} → {new_version}",
            "--no-verify",
        ],
    ]

    for command in commands:
        subprocess.run(command, cwd=REPO_FOLDER, capture_output=True, check=True)


if __name__ == "__main__":
    main()