1
1
import argparse
2
2
from pathlib import Path
3
- import sys
3
+ import subprocess
4
4
import re
5
5
6
6
VER_PATTERN = re .compile (
12
12
13
13
class Updater :
14
14
component : str = "patch"
15
+ new_version : str = "0.0.0"
15
16
16
17
@staticmethod
17
18
def replace (match : re .Match [str ]) -> str :
@@ -35,6 +36,7 @@ def replace(match: re.Match[str]) -> str:
35
36
rc_str = f"-rc{ ver [3 ]} " if ver [3 ] > 0 else ""
36
37
new_version += rc_str
37
38
print ("new version:" , new_version )
39
+ Updater .new_version = new_version
38
40
return VER_REPLACE % (tuple (ver [:3 ]) + (rc_str ,))
39
41
40
42
@@ -46,9 +48,35 @@ def main():
46
48
doc = cargo_path .read_text (encoding = "utf-8" )
47
49
doc = VER_PATTERN .sub (Updater .replace , doc )
48
50
cargo_path .write_text (doc , encoding = "utf-8" , newline = "\n " )
51
+ subprocess .run (["cargo" , "update" , "--workspace" ], check = True )
49
52
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 (f"Use 'git push origin refs/tags/{ tag } ' to publish a release" )
51
79
52
80
53
81
if __name__ == "__main__" :
54
- sys . exit ( main () )
82
+ main ()
0 commit comments