name: Publish to crates.io
on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
version:
description: "Version to publish (e.g., v0.1.0)"
required: true
type: string
env:
CARGO_TERM_COLOR: always
jobs:
publish:
name: Publish to crates.io
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Cache cargo registry
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-publish-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y libclang-dev pkg-config
- name: Configure git
run: |
git config --global user.name "GitHub Actions"
git config --global user.email "actions@github.com"
- name: Extract version from tag
id: version
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
VERSION="${{ github.event.inputs.version }}"
else
VERSION="${{ github.ref_name }}"
fi
# Remove 'v' prefix if present
VERSION=${VERSION#v}
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Extracted version: $VERSION"
- name: Update Cargo.toml version
run: |
VERSION="${{ steps.version.outputs.version }}"
sed -i "s/^version = .*/version = \"$VERSION\"/" Cargo.toml
echo "Updated Cargo.toml to version $VERSION"
- name: Check if version exists on crates.io
run: |
VERSION="${{ steps.version.outputs.version }}"
echo "Checking if version $VERSION already exists on crates.io..."
if cargo search hive-gpu --limit 1 | grep -q "hive-gpu = \"$VERSION\""; then
echo "Version $VERSION already exists on crates.io"
exit 1
fi
echo "Version $VERSION is available for publishing"
- name: Run tests before publishing
run: |
cargo test --verbose
cargo test --features metal-native --verbose || echo "Metal tests skipped (not on macOS)"
cargo test --features cuda --verbose || echo "CUDA tests skipped (not on Linux with CUDA)"
- name: Build all features
run: |
cargo build --all-features --verbose
- name: Check package
run: |
cargo check --all-features
cargo package --verbose
- name: Login to crates.io
run: echo ${{ secrets.CARGO_REGISTRY_TOKEN }} | cargo login
- name: Publish to crates.io
run: cargo publish --verbose
- name: Verify publication
run: |
sleep 30 # Wait for crates.io to update
cargo search hive-gpu --limit 1
echo "✅ Successfully published hive-gpu to crates.io!"
- name: Create GitHub Release
if: github.event_name == 'push'
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref_name }}
release_name: Hive-GPU ${{ github.ref_name }}
body: |
## 🚀 Hive-GPU ${{ github.ref_name }}
### 📦 Published to crates.io
- **Crate**: [hive-gpu](https://crates.io/crates/hive-gpu)
- **Version**: ${{ steps.version.outputs.version }}
### 🔧 Features
- Metal Native GPU acceleration (macOS)
- CUDA support (Linux/Windows)
- HNSW graph construction and search
- VRAM monitoring and management
- Batch operations and optimization
- Comprehensive error handling
### 📚 Documentation
- [README](https://github.com/hivellm/hive-gpu#readme)
- [API Docs](https://docs.rs/hive-gpu)
- [Examples](https://github.com/hivellm/hive-gpu/tree/main/examples)
### 🚀 Installation
```toml
[dependencies]
hive-gpu = "${{ steps.version.outputs.version }}"
```
### 🔧 Usage
```rust
use hive_gpu::metal::context::MetalNativeContext;
use hive_gpu::traits::{GpuContext, GpuVectorStorage};
// Create context
let context = MetalNativeContext::new()?;
// Create storage
let mut storage = context.create_storage(128, GpuDistanceMetric::Cosine)?;
// Add vectors
let vectors = vec![/* your vectors */];
storage.add_vectors(&vectors)?;
// Search
let results = storage.search(&query, 10)?;
```
draft: false
prerelease: false