feat: 第三优先级完善 — CI/CD、PyPI、pre-commit、CHANGELOG、贡献指南、基准测试、ADR
CI / Test (Python 3.13) (push) Has been cancelled
CI / Test (Python 3.13) (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
"""版本号管理 — 更新 pyproject.toml 中的 version."""
|
||||
import re
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def bump(part: str) -> str:
|
||||
"""递增版本号.
|
||||
|
||||
Args:
|
||||
part: "major" | "minor" | "patch"
|
||||
|
||||
Returns:
|
||||
新版本号字符串
|
||||
"""
|
||||
pyproject = Path(__file__).parent.parent / "pyproject.toml"
|
||||
content = pyproject.read_text(encoding="utf-8")
|
||||
match = re.search(r'version\s*=\s*"(\d+)\.(\d+)\.(\d+)"', content)
|
||||
if not match:
|
||||
print("错误: 未找到 version 字段", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
major, minor, patch = int(match[1]), int(match[2]), int(match[3])
|
||||
if part == "major":
|
||||
major += 1
|
||||
minor = 0
|
||||
patch = 0
|
||||
elif part == "minor":
|
||||
minor += 1
|
||||
patch = 0
|
||||
elif part == "patch":
|
||||
patch += 1
|
||||
else:
|
||||
print(f"错误: 未知的版本部分 '{part}',可选: major/minor/patch", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
new_version = f"{major}.{minor}.{patch}"
|
||||
new_content = content.replace(match[0], f'version = "{new_version}"')
|
||||
pyproject.write_text(new_content, encoding="utf-8")
|
||||
print(f"版本: {match[1]}.{match[2]}.{match[3]} → {new_version}")
|
||||
return new_version
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) != 2:
|
||||
print("用法: python scripts/bump_version.py <major|minor|patch>")
|
||||
sys.exit(1)
|
||||
bump(sys.argv[1])
|
||||
Reference in New Issue
Block a user