-
Notifications
You must be signed in to change notification settings - Fork 1
/
tools.py
executable file
·72 lines (54 loc) · 1.94 KB
/
tools.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
#!/usr/bin/python
import toml
import argparse
import os
program = argparse.ArgumentParser()
program.add_argument("--dry", type=bool, help="Only print what is going to be done", default=False)
program.add_argument("--set-version", type=bool, default=False, help="Sets version")
program.add_argument("--publish", type=bool, default=False, help="Publishes packages")
program.add_argument("--tag", type=bool, default=False, help="Creates a tag with current version in git")
parsed = program.parse_args()
VERSION = open("./version.txt").read()
PUBLISHING_ORDER = open("./publish-order.txt").read().splitlines()
if parsed.dry:
print("running in dry mode")
def tag():
run(f"""git commit -a -m "v{VERSION}" """)
run(f"git tag v{VERSION}")
def run(command):
print(f"running {command}")
if not parsed.dry:
os.system(command)
def get_tomls():
data = toml.load("./Cargo.toml")
packages = []
for member in data["workspace"]["members"]:
packages.append(f"{member}/Cargo.toml")
return packages
def set_version(file: str):
data = toml.load(file)
data["package"]["version"] = VERSION
for dependency in data["dependencies"]:
if dependency.startswith("enalang"):
data["dependencies"][dependency]["version"] = VERSION
if not parsed.dry:
toml.dump(data, open(file, "w"), encoder=toml.TomlArraySeparatorEncoder(preserve=True, separator=""))
def set_versions():
for toml in get_tomls():
print(f"setting version v{VERSION} for {toml}")
set_version(toml)
def publish():
for package in PUBLISHING_ORDER:
print(f"publishing {package}")
run(f"cargo publish -p {package}")
def main():
if parsed.set_version:
set_versions()
if parsed.tag:
tag()
if parsed.publish:
publish()
if not parsed.tag and not parsed.publish and not parsed.set_version:
print("nothing to do :(")
if __name__ == "__main__":
main()