-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathbump-version.py
83 lines (67 loc) · 2 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env python3
# usage:
# bump-version <new-version-string> <previous-release-tag>
import os
import re
import sys
from pathlib import Path
from typing import Callable
v = sys.argv[1]
tag = sys.argv[2]
our_crates = [
"crates/chia-bls",
"crates/clvm-traits",
"crates/chia-traits",
"crates/chia_py_streamable_macro",
"crates/chia_streamable_macro",
"crates/chia-protocol",
"crates/chia-tools",
"crates/clvm-utils",
"crates/clvm-derive",
"crates/chia-puzzle-types",
"crates/chia-client",
"crates/chia-ssl",
"crates/chia-consensus",
"crates/chia-consensus/fuzz",
"crates/chia-puzzle-types/fuzz",
"crates/clvm-utils/fuzz",
]
def crates_with_changes() -> set[str]:
ret = set()
for c in our_crates:
diff = os.popen(f"git diff {tag} -- {c}").read().strip()
if len(diff) > 0:
ret.add(c)
# the python wheel is the top-level build target, we always want to bump its
# version
ret.add("wheel")
return ret
def update_cargo(name: str, crates: set[str]) -> None:
subst = ""
with open(f"{name}/Cargo.toml") as f:
for line in f:
split = line.split()
if split == []:
subst += line
continue
if split[0] == "version" and name in crates:
line = f'version = "{v}"\n'
elif split[0] in crates and line.startswith(split[0] + " = "):
line = re.sub(
'version = "([>=^]?)\d+\.\d+\.\d+"', f'version = "\\g<1>{v}"', line
)
subst += line
with open(f"{name}/Cargo.toml", "w") as f:
f.write(subst)
crates = crates_with_changes()
# always update the root crate (chia)
crates.add(".")
crates.add("chia")
crate_names = set([Path(n).name for n in crates])
print("bumping version of crates:")
for c in crate_names:
print(f" - {c}")
for c in our_crates:
update_cargo(c, crate_names)
update_cargo(".", crate_names)
update_cargo("wheel", crate_names)