Skip to content

Commit 5d25dca

Browse files
authored
CI: Use more efficient crates.io API endpoint (#282)
Instead of listing all versions, try to query the info about the respective version directly.
1 parent 769a15e commit 5d25dca

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

scripts/ci-release.py

+11-12
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,26 @@
66
crate_version = cargo_toml["package"]["version"]
77
print("Detected crate version " + crate_version)
88

9-
api_url = "https://crates.io/api/v1/crates/x86_64/versions"
10-
crates_io_versions = requests.get(api_url).json()
9+
api_url = "https://crates.io/api/v1/crates/x86_64/" + crate_version
10+
released_version = requests.get(api_url).json()
1111

12-
new_version = True
13-
for version in crates_io_versions["versions"]:
12+
if "version" in released_version:
13+
version = released_version["version"]
1414
assert (version["crate"] == "x86_64")
15-
if version["num"] == crate_version:
16-
new_version = False
17-
break
15+
assert (version["num"] == crate_version)
16+
print("Version " + crate_version + " already exists on crates.io")
1817

19-
if new_version:
20-
print("Could not find version " + crate_version + " on crates.io; creating a new release")
18+
else:
19+
print("Could not find version " + crate_version +
20+
" on crates.io; creating a new release")
2121

2222
print(" Running `cargo publish`")
2323
subprocess.run(["cargo", "publish"], check=True)
2424

2525
tag_name = "v" + crate_version
2626
print(" Tagging commit as " + tag_name)
27-
sha = subprocess.run(["git", "rev-parse", "HEAD"], check=True, stdout=subprocess.PIPE).stdout.decode("utf-8").strip()
27+
sha = subprocess.run(["git", "rev-parse", "HEAD"], check=True,
28+
stdout=subprocess.PIPE).stdout.decode("utf-8").strip()
2829
subprocess.run([
2930
"gh", "api", "/repos/rust-osdev/x86_64/git/refs",
3031
"-X", "POST", "-H", "Accept: application/vnd.github.v3+json",
@@ -33,5 +34,3 @@
3334
])
3435

3536
print(" Done")
36-
else:
37-
print("Version " + crate_version + " already exists on crates.io")

0 commit comments

Comments
 (0)