Add script to update cargo dependencies
This commit is contained in:
7
Justfile
7
Justfile
@@ -14,3 +14,10 @@ install:
|
|||||||
|
|
||||||
test:
|
test:
|
||||||
cargo test --lib --bins
|
cargo test --lib --bins
|
||||||
|
|
||||||
|
update-dependencies:
|
||||||
|
@cd ./depcheck \
|
||||||
|
&& python3 -m venv ./venv \
|
||||||
|
&& . ./venv/bin/activate \
|
||||||
|
&& pip --disable-pip-version-check install -r ./requirements.txt > /dev/null \
|
||||||
|
&& ./update-cargo-dependencies.py
|
||||||
|
|||||||
2
depcheck/.gitignore
vendored
Normal file
2
depcheck/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
/crates.io-index/
|
||||||
|
/venv/
|
||||||
2
depcheck/requirements.txt
Normal file
2
depcheck/requirements.txt
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
semver==2.13.0
|
||||||
|
tomlkit==0.7.2
|
||||||
74
depcheck/update-cargo-dependencies.py
Executable file
74
depcheck/update-cargo-dependencies.py
Executable file
@@ -0,0 +1,74 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import subprocess
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import sys
|
||||||
|
|
||||||
|
import semver
|
||||||
|
import tomlkit
|
||||||
|
|
||||||
|
INDEX_DIR = "crates.io-index"
|
||||||
|
|
||||||
|
if os.path.exists(INDEX_DIR):
|
||||||
|
subprocess.run(
|
||||||
|
["git", "pull", "--depth=1", "origin"],
|
||||||
|
cwd=INDEX_DIR,
|
||||||
|
check=True,
|
||||||
|
capture_output=True,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
subprocess.run(
|
||||||
|
["git", "clone", "--depth=1", "https://github.com/rust-lang/crates.io-index"],
|
||||||
|
check=True,
|
||||||
|
capture_output=False, # to get some git output
|
||||||
|
)
|
||||||
|
|
||||||
|
with open("../Cargo.toml", "r") as cargo_config:
|
||||||
|
cargo = tomlkit.parse(cargo_config.read())
|
||||||
|
|
||||||
|
update_necessary = False
|
||||||
|
|
||||||
|
for tier in ["dependencies", "dev-dependencies"]:
|
||||||
|
for name, dependency in cargo[tier].items():
|
||||||
|
version = dependency["version"]
|
||||||
|
if len(name) >= 4:
|
||||||
|
info_file = f"{INDEX_DIR}/{name[0:2]}/{name[2:4]}/{name}"
|
||||||
|
elif len(name) == 3:
|
||||||
|
info_file = f"{INDEX_DIR}/3/{name[0]}/{name}"
|
||||||
|
elif len(name) == 2:
|
||||||
|
info_file = f"{INDEX_DIR}/2/{name}"
|
||||||
|
elif len(name) == 1:
|
||||||
|
info_file = f"{INDEX_DIR}/1/{name}"
|
||||||
|
|
||||||
|
current_version = semver.VersionInfo.parse(version)
|
||||||
|
|
||||||
|
latest_version = None
|
||||||
|
for version_entry in open(info_file, "r").readlines():
|
||||||
|
version = semver.VersionInfo.parse(json.loads(version_entry)["vers"])
|
||||||
|
if current_version.prerelease == "" and version.prerelease != "":
|
||||||
|
# skip prereleases, except when we are on a prerelease already
|
||||||
|
continue
|
||||||
|
if latest_version is None or version > latest_version:
|
||||||
|
latest_version = version
|
||||||
|
|
||||||
|
if latest_version != current_version:
|
||||||
|
update_necessary = True
|
||||||
|
if latest_version < current_version:
|
||||||
|
print(
|
||||||
|
f"{name}: Your current version is newer than the newest version on crates.io, the hell?"
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
print(
|
||||||
|
f"{name}: New version found: {latest_version} (current {current_version})"
|
||||||
|
)
|
||||||
|
cargo[tier][name]["version"] = str(latest_version)
|
||||||
|
|
||||||
|
|
||||||
|
if update_necessary is True:
|
||||||
|
with open("../Cargo.toml", "w") as cargo_config:
|
||||||
|
cargo_config.write(tomlkit.dumps(cargo))
|
||||||
|
sys.exit(1)
|
||||||
|
else:
|
||||||
|
print("Everything up to date")
|
||||||
|
sys.exit(0)
|
||||||
Reference in New Issue
Block a user