hive-gpu 0.2.0

High-performance GPU acceleration for vector operations with Device Info API (Metal, CUDA, ROCm)
Documentation
name: CI/CD Pipeline

on:
  push:
    branches: [main, develop]
  pull_request:
    branches: [main]
  release:
    types: [published]

env:
  CARGO_TERM_COLOR: always
  RUST_BACKTRACE: 1

jobs:
  # Test on multiple platforms and Rust versions
  test:
    name: Test on ${{ matrix.os }} (Rust ${{ matrix.rust }})
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        include:
          # Test on stable Rust
          - os: ubuntu-latest
            rust: stable
            target: x86_64-unknown-linux-gnu
          - os: windows-latest
            rust: stable
            target: x86_64-pc-windows-msvc
          - os: macos-latest
            rust: stable
            target: x86_64-apple-darwin
          # Test on beta and nightly for compatibility
          - os: ubuntu-latest
            rust: beta
            target: x86_64-unknown-linux-gnu
          - os: ubuntu-latest
            rust: nightly
            target: x86_64-unknown-linux-gnu

    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Install Rust
        uses: dtolnay/rust-toolchain@master
        with:
          toolchain: ${{ matrix.rust }}
          targets: ${{ matrix.target }}
          components: rustfmt, clippy

      - name: Cache cargo registry
        uses: actions/cache@v3
        with:
          path: |

            ~/.cargo/registry
            ~/.cargo/git
            target
          key: ${{ runner.os }}-cargo-${{ matrix.rust }}-${{ hashFiles('**/Cargo.lock') }}
          restore-keys: |

            ${{ runner.os }}-cargo-

      - name: Install system dependencies (Ubuntu)
        if: matrix.os == 'ubuntu-latest'
        run: |

          sudo apt-get update
          sudo apt-get install -y libclang-dev pkg-config

      - name: Install system dependencies (macOS)
        if: matrix.os == 'macos-latest'
        run: |

          brew install pkg-config

      - name: Check formatting
        run: cargo fmt --all -- --check

      # The `cuda` feature needs the CUDA toolkit (cuda.h) at build time and
      # is covered by the dedicated `CUDA Build` workflow. Here we lint with
      # the feature set that does not need a vendor toolchain: rocm uses
      # libloading, intel uses ash + naga (both pure Rust).
      - name: Run clippy (non-cuda feature set)
        run: cargo clippy --all-targets --features rocm,intel -- -D warnings

      - name: Run tests (CPU only)
        run: cargo test --lib --bins --tests --verbose

      - name: Run doctests (macOS only - Metal examples)
        if: matrix.os == 'macos-latest'
        run: cargo test --doc --verbose

      - name: Run tests (Metal on macOS)
        if: matrix.os == 'macos-latest'
        run: cargo test --features metal-native --verbose

      # CUDA test coverage lives in .github/workflows/cuda-build.yml, which
      # runs inside an nvidia/cuda container so `cuda.h` is available.

      - name: Build examples
        run: cargo build --examples --verbose

      - name: Run benchmarks (if available)
        run: cargo bench --verbose || echo "No benchmarks available"

  # Build and test with different feature combinations. The `cuda` feature
  # needs the CUDA toolkit at build time and lives in cuda-build.yml, so it
  # is intentionally not in this matrix. `metal-native` is target-gated to
  # macOS and contributes nothing on ubuntu; it is kept here only to exercise
  # the feature-flag machinery.
  feature-test:
    name: Feature Test - ${{ matrix.name }}
    runs-on: ubuntu-latest
    strategy:
      matrix:
        include:
          - name: "default"
            features: ""
          - name: "metal-native"
            features: "metal-native"
          - name: "rocm"
            features: "rocm"
          - name: "intel"
            features: "intel"
          - name: "rocm-intel"
            features: "rocm,intel"

    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-${{ hashFiles('**/Cargo.lock') }}-${{ hashFiles('Cargo.toml') }}
          restore-keys: |

            ${{ runner.os }}-cargo-

      - name: Install system dependencies
        run: |

          sudo apt-get update
          sudo apt-get install -y libclang-dev pkg-config

      - name: Test with features
        run: |

          if [ -n "${{ matrix.features }}" ]; then
            cargo test --features "${{ matrix.features }}" --verbose
          else
            cargo test --verbose
          fi

      - name: Build with features
        run: |

          if [ -n "${{ matrix.features }}" ]; then
            cargo build --features "${{ matrix.features }}" --verbose
          else
            cargo build --verbose
          fi

  # Security audit
  security:
    name: Security Audit
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable

      - name: Install cargo-audit
        run: cargo install cargo-audit

      - name: Run security audit
        run: cargo audit

  # Documentation
  docs:
    name: Build Documentation
    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-docs-${{ hashFiles('**/Cargo.lock') }}
          restore-keys: |

            ${{ runner.os }}-cargo-

      # `cuda` needs cuda.h at build time and is documented in cuda-build.yml.
      # Every other feature builds cleanly on a stock runner.
      - name: Build documentation
        run: cargo doc --no-deps --features metal-native,rocm,intel

      - name: Deploy documentation
        uses: peaceiris/actions-gh-pages@v3
        if: github.ref == 'refs/heads/main'
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          publish_dir: ./target/doc

  # Publish to crates.io
  publish:
    name: Publish to crates.io
    runs-on: ubuntu-latest
    needs: [test, feature-test, security, docs]
    if: github.event_name == 'release' && github.event.action == 'published'

    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: Check if version exists
        run: |

          VERSION=$(grep '^version = ' Cargo.toml | cut -d'"' -f2)
          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

      - 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

  # Create GitHub release
  release:
    name: Create GitHub Release
    runs-on: ubuntu-latest
    needs: [publish]
    if: github.event_name == 'release' && github.event.action == 'published'

    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Create release notes
        run: |

          VERSION=$(grep '^version = ' Cargo.toml | cut -d'"' -f2)
          echo "## 🚀 Hive-GPU v$VERSION" > release_notes.md
          echo "" >> release_notes.md
          echo "### 📦 Published to crates.io" >> release_notes.md
          echo "- **Crate**: [hive-gpu](https://crates.io/crates/hive-gpu)" >> release_notes.md
          echo "- **Version**: $VERSION" >> release_notes.md
          echo "" >> release_notes.md
          echo "### 🔧 Features" >> release_notes.md
          echo "- Metal Native GPU acceleration (macOS)" >> release_notes.md
          echo "- CUDA support (Linux/Windows)" >> release_notes.md
          echo "- HNSW graph construction and search" >> release_notes.md
          echo "- VRAM monitoring and management" >> release_notes.md
          echo "" >> release_notes.md
          echo "### 📚 Documentation" >> release_notes.md
          echo "- [README](https://github.com/hivellm/hive-gpu#readme)" >> release_notes.md
          echo "- [API Docs](https://docs.rs/hive-gpu)" >> release_notes.md
          echo "- [Examples](https://github.com/hivellm/hive-gpu/tree/main/examples)" >> release_notes.md

      - name: Create GitHub Release
        uses: actions/create-release@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          tag_name: ${{ github.event.release.tag_name }}
          release_name: Hive-GPU ${{ github.event.release.tag_name }}
          body_path: release_notes.md
          draft: false
          prerelease: false