name: Deploy to Hugging Face Space

on:
  push:
    branches: [main]
  workflow_dispatch:  # Allow manual triggering

jobs:
  deploy:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      # No write permissions needed for GitHub repo (we're pushing to HF Space)
    
    steps:
      - name: Checkout Repository
        uses: actions/checkout@v4
        with:
          fetch-depth: 0
      
      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: '3.11'
      
      - name: Install dependencies
        run: |
          pip install --upgrade pip
          pip install huggingface-hub
      
      - name: Deploy to Hugging Face Space
        env:
          # Token from secrets (sensitive data)
          HF_TOKEN: ${{ secrets.HF_TOKEN }}
          # Username/Organization from repository variables (non-sensitive)
          HF_USERNAME: ${{ vars.HF_USERNAME }}
          # Space name from repository variables (non-sensitive)
          HF_SPACE_NAME: ${{ vars.HF_SPACE_NAME }}
        run: |
          python .github/scripts/deploy_to_hf_space.py
      
      - name: Verify deployment
        if: success()
        run: |
          echo "✅ Deployment completed successfully!"
          echo "Space URL: https://huggingface.co/spaces/${{ vars.HF_USERNAME }}/${{ vars.HF_SPACE_NAME }}"

