Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci(*:skip) Add version bumping script #4205

Merged
merged 16 commits into from
Oct 11, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add check option
  • Loading branch information
charlesbvll committed Sep 13, 2024
commit 8b2a7c2c66517a6301d969c7f89e786c50153f02
11 changes: 8 additions & 3 deletions dev/update_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def _get_next_version(curr_version, increment):
return f"{major}.{minor}.{patch_version}"


def _update_versions(file_patterns, replace_strings, new_version):
def _update_versions(file_patterns, replace_strings, new_version, check):
"""Update the version strings in the specified files."""
for pattern in file_patterns:
files = list(Path(__file__).parents[1].glob(pattern))
Expand All @@ -62,6 +62,8 @@ def _update_versions(file_patterns, replace_strings, new_version):
regex_pattern = re.compile(escaped_s)
content = regex_pattern.sub(s.format(version=new_version), content)
if content != original_content:
if check:
raise ValueError(f"The version in {file_path} seems incorrect")
file_path.write_text(content)
print(f"Updated {file_path}")

Expand All @@ -71,6 +73,9 @@ def _update_versions(file_patterns, replace_strings, new_version):
description="Utility used to bump the version of the package."
)
parser.add_argument("current_version", help="Current version of the package.")
parser.add_argument(
"--check", action="store_true", help="Fails if any file would be modified."
)

group = parser.add_mutually_exclusive_group()
group.add_argument(
Expand All @@ -95,8 +100,8 @@ def _update_versions(file_patterns, replace_strings, new_version):

# Update files with next version
for file_pattern, strings in REPLACE_NEXT_VERSION.items():
_update_versions([file_pattern], strings, next_version)
_update_versions([file_pattern], strings, next_version, args.check)

# Update files with current version
for file_pattern, strings in REPLACE_CURR_VERSION.items():
_update_versions([file_pattern], strings, curr_version)
_update_versions([file_pattern], strings, curr_version, args.check)
Loading