Skip to content

improved tests for hf api #48

improved tests for hf api

improved tests for hf api #48

Workflow file for this run

name: Deploy API to Hugging Face Spaces
on:
push:
branches: [main]
paths:
- "api/**"
pull_request:
branches: [main]
paths:
- "api/**"
workflow_dispatch:
jobs:
test:
runs-on: ubuntu-latest
defaults:
run:
working-directory: api
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: "pip"
- name: Install dependencies
run: |
pip install uv
uv pip install --system --no-cache-dir .
- name: Run tests
env:
# Use actual secrets when available, fallback to test values
AWS_S3_BUCKET_NAME: ${{ secrets.AWS_S3_BUCKET_NAME || 'test-bucket' }}
AWS_REGION: ${{ secrets.AWS_REGION || 'us-east-1' }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID || 'test-key' }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY || 'test-secret' }}
DATABASE_URL: ${{ secrets.DATABASE_URL || 'postgresql://test:test@localhost:5432/test' }}
GOOGLE_API_KEY: ${{ secrets.GOOGLE_API_KEY || 'test-key' }}
run: |
python -m pytest tests/ -v -m "not database" --tb=short
deploy:
needs: test
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
runs-on: ubuntu-latest
defaults:
run:
working-directory: api
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: "pip"
- name: Install dependencies
run: |
pip install uv
uv pip install --system --no-cache-dir .
- name: Install HF CLI
run: |
python -m pip install --upgrade pip
pip install --upgrade huggingface_hub
- name: Deploy to Hugging Face Spaces
run: |
git init
git config user.name "GitHub Actions"
git config user.email "[email protected]"
git add .
git commit -m "Deploy to HF Spaces: $(date -u +'%Y-%m-%d %H:%M:%S UTC')"
git branch -M main
- name: Push to existing Space
if: github.ref == 'refs/heads/main'
env:
HF_USERNAME: ${{ secrets.HF_USERNAME }}
HF_TOKEN: ${{ secrets.HF_TOKEN }}
HF_SPACE_NAME: ${{ secrets.HF_SPACE_NAME }}
run: |
set -e
# Build tokenized remote URL
HF_SPACE_URL="https://user:${HF_TOKEN}@huggingface.co/spaces/${HF_USERNAME}/${HF_SPACE_NAME}.git"
# Add or update the remote and push local main -> remote main
git remote add origin "$HF_SPACE_URL" 2>/dev/null || git remote set-url origin "$HF_SPACE_URL"
git push -f origin main