Skip to content

Commit 6fd33f2

Browse files
committed
Add nox session for creating releases
Signed-off-by: Travis F. Collins <travis.collins@analog.com>
1 parent 09e574c commit 6fd33f2

2 files changed

Lines changed: 54 additions & 3 deletions

File tree

noxfile.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,57 @@ def release(session: Session) -> None:
294294
session.run("uv", "build")
295295

296296

297+
@nox.session(python=main_python, venv_backend="none")
298+
def create_release(session: Session) -> None:
299+
"""Bump version, commit, tag, and push. Usage: nox -s create_release -- [patch|minor|major]"""
300+
import re
301+
302+
bump_type = (session.posargs or ["patch"])[0]
303+
if bump_type not in ("patch", "minor", "major"):
304+
session.error(f"Invalid bump type '{bump_type}'. Use patch, minor, or major.")
305+
306+
with open("pyproject.toml") as f:
307+
toml_content = f.read()
308+
309+
match = re.search(r'^version = "(\d+)\.(\d+)\.(\d+)"', toml_content, re.MULTILINE)
310+
if not match:
311+
session.error("Could not find version in pyproject.toml")
312+
313+
major, minor, patch = int(match.group(1)), int(match.group(2)), int(match.group(3))
314+
315+
if bump_type == "major":
316+
major, minor, patch = major + 1, 0, 0
317+
elif bump_type == "minor":
318+
minor, patch = minor + 1, 0
319+
else:
320+
patch += 1
321+
322+
old_version = f"{match.group(1)}.{match.group(2)}.{match.group(3)}"
323+
new_version = f"{major}.{minor}.{patch}"
324+
print(f"Bumping {bump_type}: {old_version} -> {new_version}")
325+
326+
with open("pyproject.toml", "w") as f:
327+
f.write(toml_content.replace(f'version = "{old_version}"', f'version = "{new_version}"', 1))
328+
329+
with open("adijif/__init__.py") as f:
330+
init_content = f.read()
331+
with open("adijif/__init__.py", "w") as f:
332+
f.write(init_content.replace(f'__version__ = "{old_version}"', f'__version__ = "{new_version}"', 1))
333+
334+
with open("setup.cfg") as f:
335+
cfg_content = f.read()
336+
with open("setup.cfg", "w") as f:
337+
f.write(cfg_content.replace(f"current_version = {old_version}", f"current_version = {new_version}", 1))
338+
339+
tag = f"v{new_version}"
340+
session.run("git", "add", "pyproject.toml", "adijif/__init__.py", "setup.cfg", external=True)
341+
session.run("git", "commit", "-m", f"Bump version: {old_version} -> {new_version}", external=True)
342+
session.run("git", "tag", tag, external=True)
343+
session.run("git", "push", external=True)
344+
session.run("git", "push", "--tags", external=True)
345+
print(f"Released {tag}")
346+
347+
297348
@nox.session(python=main_python)
298349
def teste2e(session: Session) -> None:
299350
"""Run E2E tests with Playwright."""

setup.cfg

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ current_version = 0.1.4
33
commit = True
44
tag = True
55

6-
[bumpversion:file:setup.py]
7-
search = version='{current_version}'
8-
replace = version='{new_version}'
6+
[bumpversion:file:pyproject.toml]
7+
search = version = "{current_version}"
8+
replace = version = "{new_version}"
99

1010
[bumpversion:file:adijif/__init__.py]
1111
search = __version__ = '{current_version}'

0 commit comments

Comments
 (0)