-
Notifications
You must be signed in to change notification settings - Fork 2
/
release.py
97 lines (69 loc) · 3.04 KB
/
release.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import os
import shlex
import toml
import subprocess
import argparse
import re
parser = argparse.ArgumentParser("libyal-release")
SEMVER = re.compile(r"(\d)\.(\d).(\d)")
class SemVer:
major: int
minor: int
patch: int
def __init__(self, major, minor, patch):
self.major = major
self.minor = minor
self.patch = patch
def clone(self) -> 'SemVer':
return SemVer(self.major, self.minor, self.patch)
@staticmethod
def from_string(s: str) -> 'SemVer':
major, minor, patch = SEMVER.match(s).groups()
return SemVer(int(major), int(minor), int(patch))
def increment_patch(self):
new = self.clone()
new.patch += 1
return new
def to_string(self) -> str:
return f"{self.major}.{self.minor}.{self.patch}"
LIBYAL_LIBRARIES_DIRECTORIES = ["common", "common-build", "libcerror-sys", "libbfio-sys", "libbfio", "libfsntfs-sys",
"libfsntfs"]
LIBYAL_LIBRARIES_PACKAGES = ["libyal-rs-common", "libyal-rs-common-build", "libcerror-sys", "libbfio-sys",
"libfsntfs-sys", "libbfio-rs", "libfsntfs-rs"]
def main():
for d in LIBYAL_LIBRARIES_DIRECTORIES:
new_config = None
with open(os.path.join(d, "Cargo.toml"), "r") as t:
config = toml.load(t)
current_version = SemVer.from_string(config["package"]["version"])
new_version = current_version.increment_patch().to_string()
package_name = config["package"]["name"]
print(f"Current version of: {package_name} is {current_version.to_string()}, updating to {new_version}")
config["package"]["version"] = new_version
# dependencies are updated in order in `LIBYAL_LIBRARIES_DIRECTORIES`,
# which ensures the dependecy was updated and uploaded beforehand
for dependencies_section in ["dependencies", "build-dependencies", "dev-dependencies"]:
if config.get(dependencies_section):
for dependency in config[dependencies_section]:
if dependency in LIBYAL_LIBRARIES_PACKAGES:
config[dependencies_section][dependency]["version"] = new_version
new_config = config
assert new_config is not None
with open(os.path.join(d, "Cargo.toml"), "w") as t:
toml.dump(new_config, t)
# this will update the lockfiles
s = subprocess.run(shlex.split("cargo check"))
s.check_returncode()
s = subprocess.run(shlex.split("git add --all"))
s.check_returncode()
s = subprocess.run(shlex.split("cargo publish --allow-dirty"), cwd=d,
stderr=subprocess.PIPE)
# ignore already exists
if b"already" not in s.stderr:
s.check_returncode()
s = subprocess.run(shlex.split("git commit -m \"bump version to {}\"".format(new_version)))
s.check_returncode()
print("Pushing")
subprocess.run(shlex.split("git push"))
if __name__ == "__main__":
main()