name: Release SDK Rust (crates.io)
on:
push:
tags:
- "[0-9]+.[0-9]+.[0-9]+"
workflow_dispatch:
permissions:
contents: read
jobs:
publish:
name: cargo publish
runs-on: macos-26
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Install stable Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Validate tag matches Cargo.toml version
run: |
TAG="${GITHUB_REF#refs/tags/}"
CRATE_VERSION=$(grep '^version' Cargo.toml | head -1 | sed 's/version = "//;s/"//')
echo "Tag: $TAG"
echo "Crate: $CRATE_VERSION"
if [ "$TAG" != "$CRATE_VERSION" ]; then
echo "error: tag $TAG does not match Cargo.toml version $CRATE_VERSION"
exit 1
fi
- name: Swap git deps to crates.io versions
run: |
python3 - <<'EOF'
import re
with open("Cargo.toml", "r") as f:
src = f.read()
replacements = [
# mistralrs with metal feature (iOS, tvOS, visionOS, watchOS, macOS)
(
r'mistralrs = \{ git = "[^"]+", branch = "[^"]+", features = \["metal"\] \}',
'mistralrs = { version = "0.8.1", features = ["metal"] }',
),
# mistralrs-core with metal feature
(
r'mistralrs-core = \{ git = "[^"]+", branch = "[^"]+", features = \["metal"\] \}',
'mistralrs-core = { version = "0.8.1", features = ["metal"] }',
),
# mistralrs with no features (Android)
(
r'mistralrs = \{ git = "[^"]+", branch = "[^"]+", features = \[\] \}',
'mistralrs = { version = "0.8.1", features = [] }',
),
# mistralrs-core with no features (Android)
(
r'mistralrs-core = \{ git = "[^"]+", branch = "[^"]+", features = \[\] \}',
'mistralrs-core = { version = "0.8.1", features = [] }',
),
# mistralrs with no features at all (Windows, Linux)
(
r'mistralrs = \{ git = "[^"]+", branch = "[^"]+" \}',
'mistralrs = { version = "0.8.1" }',
),
]
for pattern, replacement in replacements:
before = src
src = re.sub(pattern, replacement, src)
count = len(re.findall(pattern, before))
if count:
print(f" replaced {count}x: {replacement}")
with open("Cargo.toml", "w") as f:
f.write(src)
print("Done.")
EOF
- name: Show modified Cargo.toml deps (sanity check)
run: grep -E 'mistralrs' Cargo.toml
- name: cargo publish
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: cargo publish --allow-dirty