Skip to content

Commit 026b76f

Browse files
committed
chore: manual cruft update
1 parent a1db88d commit 026b76f

File tree

5 files changed

+97
-3
lines changed

5 files changed

+97
-3
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": "2be4c098b5e6b3b35a2b71cdd2484d9aa46a0376",
2+
"_commit": "252149c8d29f972741ea3a7bbf5de824f4bdaabd",
33
"_template": "C:\\Users\\56kyl\\source\\repos\\cookiecutter-robust-python",
44
"add_rust_extension": false,
55
"author": "Kyle Oliver",

.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": "2be4c098b5e6b3b35a2b71cdd2484d9aa46a0376",
3+
"commit": "252149c8d29f972741ea3a7bbf5de824f4bdaabd",
44
"checkout": null,
55
"context": {
66
"cookiecutter": {
@@ -18,7 +18,7 @@
1818
"license": "MIT",
1919
"development_status": "Development Status :: 1 - Planning",
2020
"_template": "C:\\Users\\56kyl\\source\\repos\\cookiecutter-robust-python",
21-
"_commit": "2be4c098b5e6b3b35a2b71cdd2484d9aa46a0376"
21+
"_commit": "252149c8d29f972741ea3a7bbf5de824f4bdaabd"
2222
}
2323
},
2424
"directory": null

noxfile.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,17 @@ def build_container(session: Session) -> None:
193193
session.log(f"Container image {project_image_name}:latest built locally.")
194194

195195

196+
@nox.session(python=None, name="prepare-release", tags=[RELEASE])
197+
def prepare_release(session: Session) -> None:
198+
"""Prepares a release by creating a release branch and bumping the version.
199+
200+
Does not commit or push the release branch. Additionally, does not tag the release.
201+
"""
202+
session.log("Preparing release...")
203+
204+
session.run("python", SCRIPTS_FOLDER / "prepare-release.py", external=True)
205+
206+
196207
@nox.session(python=None, tags=[RELEASE])
197208
def release(session: Session) -> None:
198209
"""Run the release process using Commitizen.

scripts/prepare-release.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
"""Script responsible for preparing a release of the robust-python-demo package."""
2+
3+
import argparse
4+
import re
5+
import shutil
6+
import subprocess
7+
from pathlib import Path
8+
from re import Match
9+
from typing import Literal
10+
from typing import Optional
11+
from typing import Pattern
12+
from typing import TypeAlias
13+
14+
15+
from util import check_dependencies
16+
from util import remove_readonly
17+
from util import REPO_FOLDER
18+
19+
20+
Increment: TypeAlias = Literal["major", "minor", "patch", "prerelease"]
21+
CZ_PATTERN: Pattern[str] = re.compile(r"bump: version (?P<current_version>.*?) → (?P<new_version>.*?)")
22+
23+
24+
def main() -> None:
25+
"""Parses args and passes through to prepare_release."""
26+
parser: argparse.ArgumentParser = get_parser()
27+
args: argparse.Namespace = parser.parse_args()
28+
prepare_release(path=args.path, python_version=args.python_version)
29+
30+
31+
def get_parser() -> argparse.ArgumentParser:
32+
"""Creates the argument parser for prepare-release."""
33+
parser: argparse.ArgumentParser = argparse.ArgumentParser(
34+
prog="prepare-release", usage="python ./scripts/prepare-release.py patch"
35+
)
36+
parser.add_argument(
37+
"increment",
38+
type=str,
39+
help="Increment type to use when preparing the release.",
40+
choices=["major", "minor", "patch", "prerelease"],
41+
)
42+
return parser
43+
44+
45+
def prepare_release(increment: Optional[str] = None) -> None:
46+
"""Prepares a release of the robust-python-demo package.
47+
48+
Sets up a release branch from the branch develop, bumps the version, and creates a release commit. Does not tag the
49+
release or push any changes.
50+
"""
51+
dry_run_cmd: list[str] = ["uvx", "cz", "bump", "--dry-run", "--yes"]
52+
bump_cmd: list[str] = ["uvx", "cz", "bump", "--yes", "--files-only", "--changelog"]
53+
if increment is not None:
54+
dry_run_cmd.extend(["--increment", increment])
55+
bump_cmd.extend(["--increment", increment])
56+
57+
result: subprocess.CompletedProcess = subprocess.run(dry_run_cmd, cwd=REPO_FOLDER, capture_output=True)
58+
match: Match = re.match(CZ_PATTERN, result.stdout)
59+
current_version: str = match.group("current_version")
60+
new_version: str = match.group("new_version")
61+
62+
commands: list[list[str]] = [
63+
["git", "status", "--porcelain"],
64+
["git", "branch", "-b", f"release/{new_version}", "develop"],
65+
["git", "checkout", f"release/{new_version}"],
66+
bump_cmd,
67+
["git", "add", "."],
68+
["git", "commit", "-m", f"bump: version {current_version}{new_version}"]
69+
]
70+
71+
check_dependencies(path=REPO_FOLDER, dependencies=["git", "cz"])
72+
73+
for command in commands:
74+
subprocess.run(command, cwd=REPO_FOLDER, capture_output=True, check=True)
75+
76+
77+
if __name__ == "__main__":
78+
main()
79+
80+

scripts/util.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
from typing import Callable
99

1010

11+
REPO_FOLDER: Path = Path(__file__).resolve().parent.parent
12+
13+
1114
class MissingDependencyError(Exception):
1215
"""Exception raised when a depedency is missing from the system running setup-repo."""
1316

0 commit comments

Comments
 (0)