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
102 changes: 102 additions & 0 deletions cicd/bump-version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#!/usr/bin/env python3

from __future__ import annotations

import os
import re
import sys
from pathlib import Path
from typing import Optional


def validate_version(version: str) -> bool:
"""
Validate that the version string follows basic semver format (X.Y.Z).
"""
pattern: str = r"^\d+\.\d+\.\d+$"
return bool(re.match(pattern, version))


def update_pyproject_version(new_version: str) -> None:
"""
Update version in pyproject.toml.
"""
pyproject_path: Path = Path("pyproject.toml")
if not pyproject_path.exists():
raise FileNotFoundError("pyproject.toml not found")

content: str = pyproject_path.read_text()

# Use regex to replace the version line under [project]
pattern: str = r'^(version\s*=\s*")[^"]+(")'
match: Optional[re.Match[str]] = re.search(pattern, content, flags=re.MULTILINE)

if not match:
raise ValueError("Could not find version field in pyproject.toml")

new_content: str = re.sub(pattern, rf"\g<1>{new_version}\g<2>", content, flags=re.MULTILINE)
pyproject_path.write_text(new_content)
print(f"Updated pyproject.toml: version = \"{new_version}\"")


def update_init_version(new_version: str) -> None:
"""
Update version in memorylake/__init__.py.
"""
init_path: Path = Path("memorylake/__init__.py")
if not init_path.exists():
raise FileNotFoundError("memorylake/__init__.py not found")

content: str = init_path.read_text()

# Use regex to replace the __version__ line
pattern: str = r'^(__version__\s*:\s*str\s*=\s*")[^"]+(")$'
match: Optional[re.Match[str]] = re.search(pattern, content, flags=re.MULTILINE)

if not match:
raise ValueError("Could not find __version__ field in memorylake/__init__.py")

new_content: str = re.sub(pattern, rf"\g<1>{new_version}\g<2>", content, flags=re.MULTILINE)
init_path.write_text(new_content)
print(f"Updated memorylake/__init__.py: __version__ = \"{new_version}\"")


def main() -> int:
"""
Bump version in pyproject.toml and memorylake/__init__.py.
"""
if len(sys.argv) != 2:
print("Usage: bump-version.py <version>")
print("Example: bump-version.py 1.2.3")
return 1

new_version: str = sys.argv[1]

# Validate version format
if not validate_version(new_version):
print(f"ERROR: Invalid version format: {new_version!r}")
print("Version must follow semver format (e.g., 0.1.1, 1.0.0)")
return 1

# Change to repository root
repo_dir: Path = Path(__file__).parent.parent
os.chdir(repo_dir)

print(f"Bumping version to {new_version!r}...")
print()

# Update files
try:
update_pyproject_version(new_version)
update_init_version(new_version)
except Exception as e:
print(f"ERROR: {e}")
return 1

print()
print(f"Successfully bumped version to {new_version!r}")
return 0


if __name__ == "__main__":
exit(main())
2 changes: 1 addition & 1 deletion memorylake/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__: str = "0.1.0"
__version__: str = "0.1.1"
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "memorylake"
version = "0.1.0"
version = "0.1.1"
description = "MemoryLake"
authors = [
{name = "Powerdrill Authors", email = "info@powerdrill.ai"}
Expand Down