@@ -64,25 +64,31 @@ def update_uv_lock():
64
64
65
65
66
66
def get_current_version ():
67
+ # 优先尝试从 core.__version__ 获取
67
68
try :
68
- from core import __version__
69
+ import core
69
70
70
- return __version__
71
+ importlib .reload (core )
72
+ return core .__version__
71
73
except ImportError :
74
+ # 从 .bumpversion.cfg 获取
72
75
try :
73
76
with open (".bumpversion.cfg" ) as f :
74
77
for line in f :
75
78
if line .startswith ("current_version" ):
76
79
return line .split ("=" )[1 ].strip ()
77
- except Exception :
80
+ except Exception as e :
81
+ print (f"❌ 读取 .bumpversion.cfg 失败: { e } " )
78
82
pass
83
+ # 从 pyproject.toml 获取
79
84
try :
80
85
import tomli
81
86
82
87
with open ("pyproject.toml" , "rb" ) as f :
83
88
data = tomli .load (f )
84
89
return data .get ("project" , {}).get ("version" , "未知" )
85
- except Exception :
90
+ except Exception as e :
91
+ print (f"❌ 读取 pyproject.toml 失败: { e } " )
86
92
return "未知"
87
93
88
94
@@ -104,19 +110,20 @@ def generate_changelog(version: str):
104
110
sys .exit (1 )
105
111
106
112
107
- def git_commit_and_tag (version : str , tag : bool ):
113
+ def git_commit_and_tag (prev_version : str , new_version : str , tag : bool ):
108
114
files = ["pyproject.toml" , "uv.lock" , ".bumpversion.cfg" ]
109
115
if os .path .exists ("core/__init__.py" ):
110
116
files .append ("core/__init__.py" )
111
117
if os .path .exists ("CHANGELOG.md" ):
112
118
files .append ("CHANGELOG.md" )
113
119
114
120
subprocess .run (["git" , "add" ] + files , check = True )
115
- subprocess .run (["git" , "commit" , "-m" , f"bump: v{ version } " ], check = True )
121
+ message = f"chore(release): 版本更新 v{ prev_version } → v{ new_version } "
122
+ subprocess .run (["git" , "commit" , "-m" , message ], check = True )
116
123
117
124
if tag :
118
- subprocess .run (["git" , "tag" , f"v{ version } " ], check = True )
119
- print (f"✅ Git tag v{ version } 已创建" )
125
+ subprocess .run (["git" , "tag" , f"v{ new_version } " ], check = True )
126
+ print (f"✅ Git tag v{ new_version } 已创建" )
120
127
121
128
122
129
def main ():
@@ -171,29 +178,30 @@ def main():
171
178
172
179
check_bumpversion ()
173
180
174
- # 决定是预发布标志还是版本升级
181
+ prev_version = get_current_version ()
182
+
183
+ # 预发布标签处理
175
184
pre_types = ["dev" , "alpha" , "beta" , "rc" , "release" ]
176
185
if args .command in pre_types :
177
- current = get_current_version ()
178
- base = get_base_version (current )
186
+ base = get_base_version (prev_version )
179
187
new_version = base if args .command == "release" else f"{ base } -{ args .command } "
180
188
run_bumpversion ("patch" , new_version = new_version )
181
189
else :
182
190
run_bumpversion (args .command )
183
191
184
- # 更新 uv.lock 中的 version
185
- update_uv_lock ()
192
+ # bump 完成后重新获取新版本号
193
+ new_version = get_current_version ()
186
194
187
- # 获取最新版本号
188
- version = get_current_version ()
195
+ # 更新 uv.lock
196
+ update_uv_lock ()
189
197
190
- # 生成 changelog(可选 )
198
+ # 生成 changelog(如指定 )
191
199
if args .changelog :
192
- generate_changelog (version )
200
+ generate_changelog (new_version )
193
201
194
- # 手动提交(如果指定 --commit )
202
+ # 提交和打 tag(如指定 )
195
203
if args .commit :
196
- git_commit_and_tag (version , tag = args .tag )
204
+ git_commit_and_tag (prev_version , new_version , tag = args .tag )
197
205
198
206
199
207
if __name__ == "__main__" :
0 commit comments