11import argparse
22from pathlib import Path
3- import sys
3+ import subprocess
44import re
55
66VER_PATTERN = re .compile (
1212
1313class Updater :
1414 component : str = "patch"
15+ new_version : str = "0.0.0"
1516
1617 @staticmethod
1718 def replace (match : re .Match [str ]) -> str :
@@ -35,6 +36,7 @@ def replace(match: re.Match[str]) -> str:
3536 rc_str = f"-rc{ ver [3 ]} " if ver [3 ] > 0 else ""
3637 new_version += rc_str
3738 print ("new version:" , new_version )
39+ Updater .new_version = new_version
3840 return VER_REPLACE % (tuple (ver [:3 ]) + (rc_str ,))
3941
4042
@@ -46,9 +48,35 @@ def main():
4648 doc = cargo_path .read_text (encoding = "utf-8" )
4749 doc = VER_PATTERN .sub (Updater .replace , doc )
4850 cargo_path .write_text (doc , encoding = "utf-8" , newline = "\n " )
51+ subprocess .run (["cargo" , "update" ], check = True )
4952 print ("Updated version in Cargo.toml" )
50- return 0
53+ subprocess .run (
54+ [
55+ "yarn" ,
56+ "version" ,
57+ "--new-version" ,
58+ Updater .new_version ,
59+ "--no-git-tag-version" ,
60+ ],
61+ cwd = "node-binding" ,
62+ check = True ,
63+ )
64+ print ("Updated version in node-binding/**package.json" )
65+ tag = "v" + Updater .new_version
66+ subprocess .run (["git" , "add" , "--all" ], check = True )
67+ subprocess .run (["git" , "commit" , "-m" , f"bump version to { tag } " ], check = True )
68+ try :
69+ subprocess .run (["git" , "push" ], check = True )
70+ except subprocess .CalledProcessError as exc :
71+ raise RuntimeError ("Failed to push commit for version bump" ) from exc
72+ print ("Pushed commit to 'bump version to" , tag , "'" )
73+ try :
74+ subprocess .run (["git" , "tag" , tag ], check = True )
75+ except subprocess .CalledProcessError as exc :
76+ raise RuntimeError ("Failed to create tag for commit" ) from exc
77+ print ("Created tag" , tag )
78+ print ("Use 'git push --tag" , tag , "' to publish a release" )
5179
5280
5381if __name__ == "__main__" :
54- sys . exit ( main () )
82+ main ()
0 commit comments