name: Dependency Review

on:
  schedule:
    - cron: '0 9 * * 1'  # Weekly on Monday 9am UTC
  workflow_dispatch:  # Manual trigger

permissions:
  contents: read

jobs:
  check-crates:
    name: Check Rust Crates
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

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

      - name: Install cargo-outdated
        run: cargo install cargo-outdated

      - name: Check outdated crates
        run: |
          echo "## Outdated Crates" >> $GITHUB_STEP_SUMMARY
          echo '```' >> $GITHUB_STEP_SUMMARY
          cargo outdated --root-deps-only 2>&1 | tee -a $GITHUB_STEP_SUMMARY
          echo '```' >> $GITHUB_STEP_SUMMARY

  check-model:
    name: Check Embedding Model
    runs-on: ubuntu-latest
    steps:
      - name: Check E5-base-v2 model
        run: |
          echo "## Embedding Model" >> $GITHUB_STEP_SUMMARY

          # Check HuggingFace API for model info
          MODEL_INFO=$(curl -s https://huggingface.co/api/models/intfloat/e5-base-v2)
          LAST_MODIFIED=$(echo "$MODEL_INFO" | jq -r '.lastModified // "unknown"')

          echo "Model: **intfloat/e5-base-v2**" >> $GITHUB_STEP_SUMMARY
          echo "Last modified: **$LAST_MODIFIED**" >> $GITHUB_STEP_SUMMARY

          # Check if there's a newer version
          MODELS=$(curl -s "https://huggingface.co/api/models?author=intfloat&search=e5")
          echo "" >> $GITHUB_STEP_SUMMARY
          echo "Available E5 embedding models:" >> $GITHUB_STEP_SUMMARY
          echo '```' >> $GITHUB_STEP_SUMMARY
          echo "$MODELS" | jq -r '.[].id' | grep -i e5 | head -5 >> $GITHUB_STEP_SUMMARY
          echo '```' >> $GITHUB_STEP_SUMMARY
