diff --git a/scripts/release_scripts/increment_version.py b/scripts/release_scripts/increment_version.py index 30c073a7..02c85fcc 100644 --- a/scripts/release_scripts/increment_version.py +++ b/scripts/release_scripts/increment_version.py @@ -17,10 +17,19 @@ def get_current_version(file_path: str) -> str: def get_last_version_from_changelog(file_path: str) -> str: """Extract the last version noted in the CHANGELOG.MD file.""" - with open(file_path, "r") as file: - content = file.read() - match = re.search(r"\[(\d+\.\d+\.\d+)\] - \d{4}-\d{2}-\d{2}", content) - return match.group(1) if match else None + try: + with open(file_path, "r") as file: + content = file.read() + except FileNotFoundError: + raise FileNotFoundError(f"Changelog file not found: {file_path}") + except IOError as e: + raise IOError(f"Error reading changelog file: {e}") + + # More strict regex pattern for semantic versioning + match = re.search(r"\[(\d+\.\d+\.\d+)\] - (?:\d{4})-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])", content) + if not match: + raise ValueError("No valid version entry found in changelog") + return match.group(1) def increment_version(version: str, bump_type: str) -> str: