ci: replace broken katyo/publish-crates with a native cargo publish step
What changed, and why it matters
This commit updates the project's automated release workflow for publishing Rust crates to crates.io. It replaces a third-party GitHub Action that had stopped working with a custom shell script that checks whether each crate's local version is newer than what is already published before running the official cargo publish command. The change also adds a 30-minute job timeout and a 30-second network timeout for checking crates.io. There is no direct security vulnerability in the diff, but any change to a release pipeline that handles a secret publishing token deserves a routine security review.
Review the new workflow in a test environment before using it for a real release. Verify that the semver comparison correctly handles pre-release versions and that the crates.io index URL format matches the sparse registry layout. Confirm the CARGO_REGISTRY_TOKEN secret scope is limited to publishing only. No urgent security patch is required.
Security signals we found
Workflow handles CARGO_REGISTRY_TOKEN secret
Third-party action removed, reducing supply-chain exposure
Network request timeout added (30s) to limit hang risk
Job timeout added (30 minutes)
No input sanitization issues visible in the diff
No direct vulnerability introduced in project code
Evidence from the diff
The commit modifies .github/workflows/crate-io.yml. It removes four invocations of katyo/publish-crates@v2 and replaces them with a single step that runs cargo metadata, parses versions with jq, compares local versions against the crates.io sparse index using a Python helper, and conditionally runs cargo publish –manifest-path for each of cln-rpc, cln-grpc, plugins (cln-plugin), and lsps-types. It adds permissions: contents: read, timeout-minutes: 30, and a 30-second urllib timeout. The secret CARGO_REGISTRY_TOKEN is still passed via env. The script uses set -euo pipefail and a local semver comparison. No code in the project’s binaries or libraries is changed.
Changed components
.github/workflows/crate-io.ymlInspect captured patch +47 / −20
### .github/workflows/crate-io.yml
@@ -6,29 +6,56 @@ on:
branches:
- "master"
+permissions:
+ contents: read
+
jobs:
release_rust:
runs-on: ubuntu-22.04
+ timeout-minutes: 30
steps:
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@stable
- - uses: katyo/publish-crates@v2
- with:
- path: './cln-rpc'
- registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}
- ignore-unpublished-changes: true
- - uses: katyo/publish-crates@v2
- with:
- path: './plugins'
- registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}
- ignore-unpublished-changes: true
- - uses: katyo/publish-crates@v2
- with:
- path: './cln-grpc'
- registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}
- ignore-unpublished-changes: true
- - uses: katyo/publish-crates@v2
- with:
- path: './lsps-types'
- registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}
- ignore-unpublished-changes: true
+ - name: Publish crates whose git version is newer than crates.io
+ env:
+ CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
+ run: |
+ set -euo pipefail
+ # Dependency order: each crate comes after the in-repo crates it depends on.
+ for dir in cln-rpc cln-grpc plugins lsps-types; do
+ metadata=$(cargo metadata --no-deps --format-version 1 --manifest-path "$dir/Cargo.toml")
+ pkg=$(jq -r --arg m "$PWD/$dir/Cargo.toml" \
+ '.packages[] | select(.manifest_path == $m) | "\(.name) \(.version)"' <<< "$metadata")
+ name=${pkg% *}
+ version=${pkg#* }
+ decision=$(python3 - "$name" "$version" <<'EOF'
+ import json, sys, urllib.error, urllib.request
+
+ def semver_key(v):
+ core, _, pre = v.split("+")[0].partition("-")
+ nums = tuple(int(x) for x in core.split("."))
+ if not pre:
+ return nums, 1, ()
+ ids = tuple((0, int(i), "") if i.isdigit() else (1, 0, i) for i in pre.split("."))
+ return nums, 0, ids
+
+ name, local = sys.argv[1], sys.argv[2]
+ url = f"https://index.crates.io/{name[:2]}/{name[2:4]}/{name}"
+ try:
+ with urllib.request.urlopen(url, timeout=30) as resp:
+ published = [json.loads(line)["vers"] for line in resp.read().decode().splitlines() if line]
+ except urllib.error.HTTPError as err:
+ if err.code != 404:
+ raise
+ published = []
+ newer = not published or semver_key(local) > max(semver_key(v) for v in published)
+ print("publish" if newer else "skip")
+ EOF
+ )
+ if [ "$decision" = "publish" ]; then
+ echo "Publishing $name $version from $dir"
+ cargo publish --manifest-path "$dir/Cargo.toml"
+ else
+ echo "Skipping $name $version: crates.io already has an equal or newer version"
+ fi
+ doneWhy this scored 20/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.