Update Java package version in scripts/update-version.py

This commit is contained in:
Pekka Enberg
2025-10-31 09:34:15 +02:00
parent 331ba14e7c
commit 8ee5b5621e

View File

@@ -1,8 +1,10 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
""" """
Script to update version in Cargo.toml, package.json, and package-lock.json files for the Turso project. Script to update version in Cargo.toml, package.json, package-lock.json, and
gradle.properties files for the Turso project.
This script updates all occurrences of the version in the workspace configuration, This script updates all occurrences of the version in the workspace configuration,
updates the JavaScript and WebAssembly bindings package.json and package-lock.json files, updates the JavaScript and WebAssembly bindings package.json and package-lock.json files,
updates the Java bindings gradle.properties file,
uses cargo update to update Cargo.lock, creates a git commit, and adds a version tag. uses cargo update to update Cargo.lock, creates a git commit, and adds a version tag.
""" """
@@ -36,6 +38,8 @@ NPM_WORKSPACES = [
"bindings/javascript" "bindings/javascript"
] ]
JAVA_GRADLE_PROPERTIES = "bindings/java/gradle.properties"
def parse_args(): def parse_args():
parser = argparse.ArgumentParser(description="Update version in project files") parser = argparse.ArgumentParser(description="Update version in project files")
@@ -169,6 +173,28 @@ def update_all_packages(new_version):
return results return results
def update_gradle_properties(new_version):
"""Update version in gradle.properties file."""
try:
gradle_path = Path(JAVA_GRADLE_PROPERTIES)
if not gradle_path.exists():
print(f"Warning: {JAVA_GRADLE_PROPERTIES} not found, skipping Java version update")
return False
content = gradle_path.read_text()
# Pattern to match projectVersion=x.y.z
pattern = r"(projectVersion\s*=\s*)([^\s]+)"
updated_content = re.sub(pattern, rf"\g<1>{new_version}", content)
gradle_path.write_text(updated_content)
print(f"Updated {JAVA_GRADLE_PROPERTIES} to version {new_version}")
return True
except Exception as e:
print(f"Error updating gradle.properties: {e}")
return False
def run_cargo_update(): def run_cargo_update():
"""Run cargo update to update the Cargo.lock file.""" """Run cargo update to update the Cargo.lock file."""
try: try:
@@ -186,6 +212,10 @@ def create_git_commit_and_tag(version):
# Add files that exist and have changes # Add files that exist and have changes
files_to_add = ["Cargo.toml", "Cargo.lock"] files_to_add = ["Cargo.toml", "Cargo.lock"]
# Add Java gradle.properties if it exists
if os.path.exists(JAVA_GRADLE_PROPERTIES):
files_to_add.append(JAVA_GRADLE_PROPERTIES)
# Add all potential package.json and package-lock.json files # Add all potential package.json and package-lock.json files
for package_path in NPM_PACKAGES: for package_path in NPM_PACKAGES:
package_json = f"{package_path}/package.json" package_json = f"{package_path}/package.json"
@@ -230,6 +260,9 @@ def main():
# Update all npm packages # Update all npm packages
update_all_packages(new_version) update_all_packages(new_version)
# Update Java gradle.properties
update_gradle_properties(new_version)
# Update Cargo.lock using cargo update # Update Cargo.lock using cargo update
run_cargo_update() run_cargo_update()