-
Notifications
You must be signed in to change notification settings - Fork 1
/
bump_version.py
43 lines (37 loc) · 1.38 KB
/
bump_version.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from __future__ import annotations
import re
import subprocess
import sys
how = sys.argv[1]
with open("pyproject.toml", encoding="utf-8") as f:
content = f.read()
old_version = re.search(r'version = "(.*)"', content).group(1)
version = old_version.split(".")
if how == "patch":
version = ".".join(version[:-1] + [str(int(version[-1]) + 1)])
elif how == "minor":
version = ".".join(version[:-2] + [str(int(version[-2]) + 1), "0"])
elif how == "major":
version = ".".join([str(int(version[0]) + 1), "0", "0"])
content = content.replace(f'version = "{old_version}"', f'version = "{version}"')
with open("pyproject.toml", "w", encoding="utf-8") as f:
f.write(content)
with open("polars_upgrade/__init__.py", encoding="utf-8") as f:
content = f.read()
content = content.replace(
f'__version__ = "{old_version}"',
f'__version__ = "{version}"',
)
with open("polars_upgrade/__init__.py", "w", encoding="utf-8") as f:
f.write(content)
with open("README.md", encoding="utf-8") as f:
content = f.read()
content = content.replace(
f"rev: {old_version}",
f"rev: {version}",
)
with open("README.md", "w", encoding="utf-8") as f:
f.write(content)
subprocess.run(["git", "commit", "-a", "-m", f"Bump version to {version}"], check=False)
subprocess.run(["git", "tag", "-a", version, "-m", version], check=False)
subprocess.run(["git", "push", "--follow-tags"], check=False)