forked from hakoerber/git-repo-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-cargo-dependencies.py
executable file
·100 lines (82 loc) · 2.56 KB
/
update-cargo-dependencies.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
98
99
100
#!/usr/bin/env python3
import subprocess
import tomlkit
with open("./Cargo.toml", "r") as cargo_config:
cargo = tomlkit.parse(cargo_config.read())
update_necessary = True
for tier in ["dependencies", "dev-dependencies"]:
for name, dependency in cargo[tier].items():
version = dependency["version"].lstrip("=")
args = [
"cargo",
"upgrade",
"--incompatible",
"--pinned",
"--ignore-rust-version",
"--package",
name,
]
subprocess.run(
args,
check=True,
)
with open("./Cargo.toml", "r") as cargo_config:
cargo = tomlkit.parse(cargo_config.read())
new_version = {dep: cfg for dep, cfg in cargo[tier].items() if dep == name}[
name
]["version"].lstrip("=")
subprocess.run(
["cargo", "update", "--recursive", "--package", name],
check=True,
)
if version != new_version:
update_necessary = True
message = f"dep: Update {name} to {new_version}"
cmd = subprocess.run(
[
"git",
"commit",
"--message",
message,
"./Cargo.lock",
"./Cargo.toml",
],
check=True,
)
# If only Cargo.lock changed but not the version of the dependency itself,
# some transitive dependencies were updated
else:
cmd = subprocess.run(
[
"git",
"diff",
"--stat",
"--exit-code",
"./Cargo.lock",
],
)
if cmd.returncode == 1:
message = f"dep: Update dependencies of {name}"
cmd = subprocess.run(
[
"git",
"commit",
"--message",
message,
"./Cargo.lock",
],
check=True,
)
# assert that Cargo.toml is not modified
subprocess.run(
[
"git",
"diff",
"--stat",
"--exit-code",
"./Cargo.toml",
],
check=True,
)
if update_necessary is False:
print("Everything up to date")