Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .cookiecutter.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"_commit": "7dad9f1bff1e967b310ac506944085bd6a370b73",
"_commit": "3483e9e38f95d0437dc803cfd09db2050ab10194",
"_max_python_version_minor_int": 14,
"_min_python_version_minor_int": 10,
"_template": "C:\\Users\\56kyl\\source\\repos\\cookiecutter-robust-python",
Expand Down
4 changes: 2 additions & 2 deletions .cruft.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"template": "C:\\Users\\56kyl\\source\\repos\\cookiecutter-robust-python",
"commit": "7dad9f1bff1e967b310ac506944085bd6a370b73",
"commit": "3483e9e38f95d0437dc803cfd09db2050ab10194",
"checkout": null,
"context": {
"cookiecutter": {
Expand All @@ -20,7 +20,7 @@
"license": "MIT",
"development_status": "Development Status :: 1 - Planning",
"_template": "C:\\Users\\56kyl\\source\\repos\\cookiecutter-robust-python",
"_commit": "7dad9f1bff1e967b310ac506944085bd6a370b73",
"_commit": "3483e9e38f95d0437dc803cfd09db2050ab10194",
"_min_python_version_minor_int": 10,
"_max_python_version_minor_int": 14,
"python_versions": [
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## v0.39.0 (2025-12-01)

## v0.38.0 (2025-11-24)

## v0.37.0 (2025-11-24)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "robust-python-demo"
version = "0.38.0"
version = "0.39.0"
description = "robust-python-demo"
authors = [
{ name = "Kyle Oliver", email = "56kyleoliver+cookiecutter-robust-python@gmail.com" },
Expand Down
34 changes: 30 additions & 4 deletions scripts/setup-release.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from util import create_release_branch
from util import get_bumped_package_version
from util import get_package_version
from util import require_clean_and_up_to_date_repo


def main() -> None:
Expand All @@ -20,9 +21,9 @@ def main() -> None:


def get_parser() -> argparse.ArgumentParser:
"""Creates the argument parser for prepare-release."""
"""Creates the argument parser for setup-release."""
parser: argparse.ArgumentParser = argparse.ArgumentParser(
prog="prepare-release", usage="python ./scripts/prepare-release.py patch"
prog="setup-release", usage="python ./scripts/setup-release.py patch"
)
parser.add_argument(
"increment",
Expand All @@ -38,13 +39,26 @@ def get_parser() -> argparse.ArgumentParser:
def setup_release(increment: Optional[str] = None) -> None:
"""Prepares a release of the robust-python-demo package.

Sets up a release branch from the branch develop, bumps the version, and creates a release commit. Does not tag the
release or push any changes.
Will try to create the release and push, however will return to pre-existing state on error.
"""
check_dependencies(path=REPO_FOLDER, dependencies=["git"])
require_clean_and_up_to_date_repo()

current_version: str = get_package_version()
new_version: str = get_bumped_package_version(increment=increment)
try:
_setup_release(increment=increment, current_version=current_version, new_version=new_version)
except Exception as error:
_rollback_release(version=new_version)
raise error


def _setup_release(increment: str, current_version: str, new_version: str) -> None:
"""Prepares a release of the robust-python-demo package.

Sets up a release branch from the branch develop, bumps the version, and creates a release commit. Does not tag the
release or push any changes.
"""
create_release_branch(new_version=new_version)
bump_version(increment=increment)

Expand All @@ -58,5 +72,17 @@ def setup_release(increment: Optional[str] = None) -> None:
subprocess.run(command, cwd=REPO_FOLDER, capture_output=True, check=True)


def _rollback_release(version: str) -> None:
"""Rolls back to the pre-existing state on error."""
commands: list[list[str]] = [
["git", "checkout", "develop"],
["git", "checkout", "."],
["git", "branch", "-D", f"release/{version}"],
]

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


if __name__ == "__main__":
main()
18 changes: 18 additions & 0 deletions scripts/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@


REPO_FOLDER: Path = Path(__file__).resolve().parent.parent
MAIN_BRANCH: str = "main"
DEVELOP_BRANCH: str = "develop"


class MissingDependencyError(Exception):
Expand All @@ -34,6 +36,22 @@ def check_dependencies(path: Path, dependencies: list[str]) -> None:
raise MissingDependencyError(path, dependency) from e


def require_clean_and_up_to_date_repo() -> None:
"""Checks if the repo is clean and up to date with any important branches."""
commands: list[list[str]] = [
["git", "fetch"],
["git", "merge-base", "--is-ancestor", MAIN_BRANCH, f"origin/{MAIN_BRANCH}"],
["git", "merge-base", "--is-ancestor", f"origin/{MAIN_BRANCH}", MAIN_BRANCH],
["git", "merge-base", "--is-ancestor", DEVELOP_BRANCH, f"origin/{DEVELOP_BRANCH}"],
["git", "merge-base", "--is-ancestor", f"origin/{DEVELOP_BRANCH}", DEVELOP_BRANCH],
["git", "merge-base", "--is-ancestor", MAIN_BRANCH, DEVELOP_BRANCH],
["git", "status", "--porcelain"],
]

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


def existing_dir(value: str) -> Path:
"""Responsible for validating argparse inputs and returning them as pathlib Path's if they meet criteria."""
path = Path(value).expanduser().resolve()
Expand Down
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.