Skip to content

Commit 2646184

Browse files
committed
ci: replace broken katyo/publish-crates with a native cargo publish step
The katyo/publish-crates action no longer publishes anything: the Release Rust workflow ran on the push that bumped lsps-types to 0.7.0 and did not publish it. The new step publishes each crate only when its Cargo.toml version is newer than the highest version on crates.io, in dependency order (cln-rpc, cln-grpc, cln-plugin, lsps-types). Cap the job at 30 minutes and give the crates.io index request a 30 second timeout so a hung network call cannot stall the release.
1 parent 1112b47 commit 2646184

1 file changed

Lines changed: 47 additions & 20 deletions

File tree

‎.github/workflows/crate-io.yml‎

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,56 @@ on:
66
branches:
77
- "master"
88

9+
permissions:
10+
contents: read
11+
912
jobs:
1013
release_rust:
1114
runs-on: ubuntu-22.04
15+
timeout-minutes: 30
1216
steps:
1317
- uses: actions/checkout@v6
1418
- uses: dtolnay/rust-toolchain@stable
15-
- uses: katyo/publish-crates@v2
16-
with:
17-
path: './cln-rpc'
18-
registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}
19-
ignore-unpublished-changes: true
20-
- uses: katyo/publish-crates@v2
21-
with:
22-
path: './plugins'
23-
registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}
24-
ignore-unpublished-changes: true
25-
- uses: katyo/publish-crates@v2
26-
with:
27-
path: './cln-grpc'
28-
registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}
29-
ignore-unpublished-changes: true
30-
- uses: katyo/publish-crates@v2
31-
with:
32-
path: './lsps-types'
33-
registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}
34-
ignore-unpublished-changes: true
19+
- name: Publish crates whose git version is newer than crates.io
20+
env:
21+
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
22+
run: |
23+
set -euo pipefail
24+
# Dependency order: each crate comes after the in-repo crates it depends on.
25+
for dir in cln-rpc cln-grpc plugins lsps-types; do
26+
metadata=$(cargo metadata --no-deps --format-version 1 --manifest-path "$dir/Cargo.toml")
27+
pkg=$(jq -r --arg m "$PWD/$dir/Cargo.toml" \
28+
'.packages[] | select(.manifest_path == $m) | "\(.name) \(.version)"' <<< "$metadata")
29+
name=${pkg% *}
30+
version=${pkg#* }
31+
decision=$(python3 - "$name" "$version" <<'EOF'
32+
import json, sys, urllib.error, urllib.request
33+
34+
def semver_key(v):
35+
core, _, pre = v.split("+")[0].partition("-")
36+
nums = tuple(int(x) for x in core.split("."))
37+
if not pre:
38+
return nums, 1, ()
39+
ids = tuple((0, int(i), "") if i.isdigit() else (1, 0, i) for i in pre.split("."))
40+
return nums, 0, ids
41+
42+
name, local = sys.argv[1], sys.argv[2]
43+
url = f"https://index.crates.io/{name[:2]}/{name[2:4]}/{name}"
44+
try:
45+
with urllib.request.urlopen(url, timeout=30) as resp:
46+
published = [json.loads(line)["vers"] for line in resp.read().decode().splitlines() if line]
47+
except urllib.error.HTTPError as err:
48+
if err.code != 404:
49+
raise
50+
published = []
51+
newer = not published or semver_key(local) > max(semver_key(v) for v in published)
52+
print("publish" if newer else "skip")
53+
EOF
54+
)
55+
if [ "$decision" = "publish" ]; then
56+
echo "Publishing $name $version from $dir"
57+
cargo publish --manifest-path "$dir/Cargo.toml"
58+
else
59+
echo "Skipping $name $version: crates.io already has an equal or newer version"
60+
fi
61+
done

0 commit comments

Comments
 (0)