chore: add script to bump all versions

This commit is contained in:
鲁树人
2025-03-31 08:53:19 +09:00
parent a971855f1e
commit 4d71f26d8b
4 changed files with 59 additions and 0 deletions

2
.gitignore vendored
View File

@@ -4,3 +4,5 @@ pkg-*/
node_modules/
.pnpm-store
*.local
venv
.venv

View File

@@ -1,5 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="EMPTY_MODULE" version="4">
<component name="FacetManager">
<facet type="Python" name="Python facet">
<configuration sdkName="Python 3.12 (lib_um_crypto_rust)" />
</facet>
</component>
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/um_wasm/src" isTestSource="false" />
@@ -20,8 +25,10 @@
<excludeFolder url="file://$MODULE_DIR$/target" />
<excludeFolder url="file://$MODULE_DIR$/um_wasm_loader/dist" />
<excludeFolder url="file://$MODULE_DIR$/um_wasm_loader/pkg" />
<excludeFolder url="file://$MODULE_DIR$/.venv" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Python 3.12 (lib_um_crypto_rust) interpreter library" level="application" />
</component>
</module>

6
.idea/misc.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Black">
<option name="sdkName" value="Python 3.12 (lib_um_crypto_rust)" />
</component>
</project>

44
bump_versions.py Normal file
View File

@@ -0,0 +1,44 @@
import argparse
import glob
import re
from typing import Generator
def parse_version(text: str) -> str:
re_version = re.compile(r'^\d+\.\d+\.\d+(-[-a-zA-Z\d]*)?$')
if not re_version.match(text):
raise argparse.ArgumentTypeError(f"Invalid version format: '{text}'")
return text
def iter_cargo_toml_paths() -> Generator[str, None, None]:
yield "um_audio/Cargo.toml"
yield "um_wasm/Cargo.toml"
yield "um_cli/Cargo.toml"
for p in glob.iglob("um_crypto/*/Cargo.toml", recursive=False):
yield p
def re_replace_file(path: str, regex: re.Pattern, replacement: str) -> None:
print(f"Bumping {path}...")
with open(path, "r", encoding='utf-8') as f:
content = f.read()
content = regex.sub(replacement, content, 1)
with open(path, "w", encoding='utf-8', newline='\n') as f:
f.write(content)
def main():
parser = argparse.ArgumentParser (description="Bump versions")
parser.add_argument("version", type=parse_version, help="Version to bump to")
args = parser.parse_args()
re_toml_version = re.compile(r'^\s*(version|"version"|\'version\')\s*=\s*.*$', re.MULTILINE)
re_json_version = re.compile(r'^(\s*)"version"\s*:\s*".*?"\s*(,)?\s*$', re.MULTILINE)
for path in iter_cargo_toml_paths():
re_replace_file(path, re_toml_version, f'version = "{args.version}"')
re_replace_file("um_wasm_loader/package.json", re_json_version, fr'\1"version": "{args.version}"\2')
if __name__ == "__main__":
main()