|
6 | 6 | branches: |
7 | 7 | - "master" |
8 | 8 |
|
| 9 | +permissions: |
| 10 | + contents: read |
| 11 | + |
9 | 12 | jobs: |
10 | 13 | release_rust: |
11 | 14 | runs-on: ubuntu-22.04 |
| 15 | + timeout-minutes: 30 |
12 | 16 | steps: |
13 | 17 | - uses: actions/checkout@v6 |
14 | 18 | - 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