Skip to content

Commit 216945f

Browse files
authored
Merge pull request #57 from robust-python/release/0.39.0
Release/0.39.0
2 parents 932cecf + f9bff4e commit 216945f

File tree

7 files changed

+55
-9
lines changed

7 files changed

+55
-9
lines changed

.cookiecutter.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"_commit": "7dad9f1bff1e967b310ac506944085bd6a370b73",
2+
"_commit": "3483e9e38f95d0437dc803cfd09db2050ab10194",
33
"_max_python_version_minor_int": 14,
44
"_min_python_version_minor_int": 10,
55
"_template": "C:\\Users\\56kyl\\source\\repos\\cookiecutter-robust-python",

.cruft.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"template": "C:\\Users\\56kyl\\source\\repos\\cookiecutter-robust-python",
3-
"commit": "7dad9f1bff1e967b310ac506944085bd6a370b73",
3+
"commit": "3483e9e38f95d0437dc803cfd09db2050ab10194",
44
"checkout": null,
55
"context": {
66
"cookiecutter": {
@@ -20,7 +20,7 @@
2020
"license": "MIT",
2121
"development_status": "Development Status :: 1 - Planning",
2222
"_template": "C:\\Users\\56kyl\\source\\repos\\cookiecutter-robust-python",
23-
"_commit": "7dad9f1bff1e967b310ac506944085bd6a370b73",
23+
"_commit": "3483e9e38f95d0437dc803cfd09db2050ab10194",
2424
"_min_python_version_minor_int": 10,
2525
"_max_python_version_minor_int": 14,
2626
"python_versions": [

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
## v0.39.0 (2025-12-01)
2+
13
## v0.38.0 (2025-11-24)
24

35
## v0.37.0 (2025-11-24)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "robust-python-demo"
3-
version = "0.38.0"
3+
version = "0.39.0"
44
description = "robust-python-demo"
55
authors = [
66
{ name = "Kyle Oliver", email = "56kyleoliver+cookiecutter-robust-python@gmail.com" },

scripts/setup-release.py

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from util import create_release_branch
1111
from util import get_bumped_package_version
1212
from util import get_package_version
13+
from util import require_clean_and_up_to_date_repo
1314

1415

1516
def main() -> None:
@@ -20,9 +21,9 @@ def main() -> None:
2021

2122

2223
def get_parser() -> argparse.ArgumentParser:
23-
"""Creates the argument parser for prepare-release."""
24+
"""Creates the argument parser for setup-release."""
2425
parser: argparse.ArgumentParser = argparse.ArgumentParser(
25-
prog="prepare-release", usage="python ./scripts/prepare-release.py patch"
26+
prog="setup-release", usage="python ./scripts/setup-release.py patch"
2627
)
2728
parser.add_argument(
2829
"increment",
@@ -38,13 +39,26 @@ def get_parser() -> argparse.ArgumentParser:
3839
def setup_release(increment: Optional[str] = None) -> None:
3940
"""Prepares a release of the robust-python-demo package.
4041
41-
Sets up a release branch from the branch develop, bumps the version, and creates a release commit. Does not tag the
42-
release or push any changes.
42+
Will try to create the release and push, however will return to pre-existing state on error.
4343
"""
4444
check_dependencies(path=REPO_FOLDER, dependencies=["git"])
45+
require_clean_and_up_to_date_repo()
4546

4647
current_version: str = get_package_version()
4748
new_version: str = get_bumped_package_version(increment=increment)
49+
try:
50+
_setup_release(increment=increment, current_version=current_version, new_version=new_version)
51+
except Exception as error:
52+
_rollback_release(version=new_version)
53+
raise error
54+
55+
56+
def _setup_release(increment: str, current_version: str, new_version: str) -> None:
57+
"""Prepares a release of the robust-python-demo package.
58+
59+
Sets up a release branch from the branch develop, bumps the version, and creates a release commit. Does not tag the
60+
release or push any changes.
61+
"""
4862
create_release_branch(new_version=new_version)
4963
bump_version(increment=increment)
5064

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

6074

75+
def _rollback_release(version: str) -> None:
76+
"""Rolls back to the pre-existing state on error."""
77+
commands: list[list[str]] = [
78+
["git", "checkout", "develop"],
79+
["git", "checkout", "."],
80+
["git", "branch", "-D", f"release/{version}"],
81+
]
82+
83+
for command in commands:
84+
subprocess.run(command, cwd=REPO_FOLDER, check=False)
85+
86+
6187
if __name__ == "__main__":
6288
main()

scripts/util.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111

1212
REPO_FOLDER: Path = Path(__file__).resolve().parent.parent
13+
MAIN_BRANCH: str = "main"
14+
DEVELOP_BRANCH: str = "develop"
1315

1416

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

3638

39+
def require_clean_and_up_to_date_repo() -> None:
40+
"""Checks if the repo is clean and up to date with any important branches."""
41+
commands: list[list[str]] = [
42+
["git", "fetch"],
43+
["git", "merge-base", "--is-ancestor", MAIN_BRANCH, f"origin/{MAIN_BRANCH}"],
44+
["git", "merge-base", "--is-ancestor", f"origin/{MAIN_BRANCH}", MAIN_BRANCH],
45+
["git", "merge-base", "--is-ancestor", DEVELOP_BRANCH, f"origin/{DEVELOP_BRANCH}"],
46+
["git", "merge-base", "--is-ancestor", f"origin/{DEVELOP_BRANCH}", DEVELOP_BRANCH],
47+
["git", "merge-base", "--is-ancestor", MAIN_BRANCH, DEVELOP_BRANCH],
48+
["git", "status", "--porcelain"],
49+
]
50+
51+
for command in commands:
52+
subprocess.run(command, cwd=REPO_FOLDER, check=True)
53+
54+
3755
def existing_dir(value: str) -> Path:
3856
"""Responsible for validating argparse inputs and returning them as pathlib Path's if they meet criteria."""
3957
path = Path(value).expanduser().resolve()

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)