From b9d5e933e8b2e130179566c48e95ccba56509087 Mon Sep 17 00:00:00 2001 From: quincyforbes Date: Wed, 23 Oct 2024 16:35:55 -0400 Subject: [PATCH] Update scripts/release_scripts/increment_version.py Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- scripts/release_scripts/increment_version.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) 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: