Spaces:
Sleeping
Sleeping
| name: Deploy to HuggingFace Spaces | |
| on: | |
| push: | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| inputs: | |
| reason: | |
| description: 'Deployment reason' | |
| required: false | |
| default: 'Manual deployment' | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| lfs: true | |
| fetch-depth: 0 | |
| - name: Setup Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.10' | |
| - name: Install HuggingFace Hub | |
| run: | | |
| pip install --upgrade huggingface_hub[cli] | |
| echo "β HuggingFace Hub installed" | |
| - name: Debug - Check HF_TOKEN | |
| env: | |
| HF_TOKEN: ${{ secrets.HF_TOKEN }} | |
| run: | | |
| # Check if token is set (without revealing it) | |
| if [ -z "$HF_TOKEN" ]; then | |
| echo "β ERROR: HF_TOKEN is not set!" | |
| exit 1 | |
| else | |
| echo "β HF_TOKEN is set (length: ${#HF_TOKEN} chars)" | |
| fi | |
| - name: Prepare deployment files | |
| run: | | |
| echo "Preparing files for HuggingFace Spaces deployment..." | |
| # Create temporary deployment directory | |
| mkdir -p hf-deploy | |
| # Copy all necessary files | |
| cp -r backend/ hf-deploy/ | |
| cp -r frontend/ hf-deploy/ | |
| cp requirements.txt hf-deploy/ | |
| cp huggingface/Dockerfile hf-deploy/Dockerfile | |
| cp huggingface/README.md hf-deploy/README.md | |
| cp huggingface/nginx.conf hf-deploy/ | |
| cp huggingface/supervisord.conf hf-deploy/ | |
| # Copy .dockerignore if it exists | |
| if [ -f "huggingface/.dockerignore" ]; then | |
| cp huggingface/.dockerignore hf-deploy/.dockerignore | |
| echo "β .dockerignore copied" | |
| fi | |
| echo "β Files prepared in hf-deploy/" | |
| - name: Upload to HuggingFace Space | |
| env: | |
| HF_TOKEN: ${{ secrets.HF_TOKEN }} | |
| run: | | |
| echo "Uploading to HuggingFace Space: Hwandji/saap" | |
| # Create Python script for upload | |
| cat > upload_to_hf.py << 'EOF' | |
| import os | |
| from pathlib import Path | |
| from huggingface_hub import HfApi, login, create_repo | |
| # Login with token | |
| token = os.environ.get('HF_TOKEN') | |
| if not token: | |
| raise ValueError("HF_TOKEN not found in environment") | |
| login(token=token) | |
| print("β Successfully logged in to HuggingFace") | |
| # Initialize API | |
| api = HfApi() | |
| # Create or get Space repository | |
| repo_id = "Hwandji/saap" | |
| print(f"Creating or accessing Space: {repo_id}...") | |
| try: | |
| # Try to create the Space (will succeed if doesn't exist, harmless if exists) | |
| create_repo( | |
| repo_id=repo_id, | |
| repo_type="space", | |
| space_sdk="docker", | |
| exist_ok=True, # Don't error if already exists | |
| private=False | |
| ) | |
| print(f"β Space {repo_id} is ready") | |
| except Exception as e: | |
| print(f"β οΈ Note: {e}") | |
| print("Continuing with upload...") | |
| # Upload directory | |
| print(f"Uploading files to {repo_id}...") | |
| api.upload_folder( | |
| folder_path="./hf-deploy", | |
| repo_id=repo_id, | |
| repo_type="space", | |
| commit_message="π Deploy from GitHub Actions", | |
| ignore_patterns=[".git", ".github", "__pycache__", "*.pyc"] | |
| ) | |
| print("β Successfully deployed to HuggingFace Spaces") | |
| print(f"π Space URL: https://huggingface.co/spaces/{repo_id}") | |
| print(f"π App URL: https://{repo_id.replace('/', '-')}.hf.space") | |
| EOF | |
| # Run the upload script | |
| python upload_to_hf.py | |
| - name: Deployment summary | |
| if: success() | |
| run: | | |
| echo "## π Deployment Successful!" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "**Space URL:** https://huggingface.co/spaces/Hwandji/saap" >> $GITHUB_STEP_SUMMARY | |
| echo "**App URL:** https://Hwandji-saap.hf.space" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "β±οΈ The space may take 2-3 minutes to build and start." >> $GITHUB_STEP_SUMMARY | |
| - name: Notify on failure | |
| if: failure() | |
| run: | | |
| echo "## β Deployment Failed!" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "Please check the logs above for error details." >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "**Common issues:**" >> $GITHUB_STEP_SUMMARY | |
| echo "- HF_TOKEN not configured in repository secrets" >> $GITHUB_STEP_SUMMARY | |
| echo "- Token lacks WRITE permissions for Spaces" >> $GITHUB_STEP_SUMMARY | |
| echo "- Token creator is not a member of 'satware' organization" >> $GITHUB_STEP_SUMMARY | |
| echo "- Space 'Hwandji/saap' does not exist or is not accessible" >> $GITHUB_STEP_SUMMARY | |