GitHub Actions
Deploy to Hugging Face Spaces
9a22bb5
name: CI/CD to Hugging Face
on:
push:
branches: [ main ]
workflow_dispatch:
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8
- name: Lint with flake8
# We allow it to fail for now if there are many pre-existing issues,
# but ideally we should keep it clean.
run: |
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
deploy:
needs: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Deploy to Hugging Face
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
run: |
git config --global user.email "actions@github.com"
git config --global user.name "GitHub Actions"
# Create an orphan branch for deployment to keep the HF history clean
git checkout --orphan hf-deploy
# Add all files
git add -A
# Commit
git commit -m "Deploy to Hugging Face Spaces"
# Push to HF (Update with your username/space-name)
# Format: https://<username>:<token>@huggingface.co/spaces/<username>/<space-name>
# We'll use a placeholder for the space name - user needs to update this or I can try to help.
# For now, I'll use a generic pattern or ask the user.
# Note: The push requires the full URL with credentials.
git push -f https://rixxabh:${HF_TOKEN}@huggingface.co/spaces/rixxabh/imageup hf-deploy:main
monitor:
needs: deploy
runs-on: ubuntu-latest
steps:
- name: Wait for deployment to be ready
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
run: |
echo "Monitoring deployment for rixxabh/imageup..."
MAX_RETRIES=40
RETRY_COUNT=0
while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do
STATUS=$(curl -s "https://huggingface.co/api/spaces/rixxabh/imageup" | jq -r '.runtime.stage')
echo "Current status: $STATUS"
if [ "$STATUS" == "RUNNING" ]; then
echo "Deployment is LIVE and RUNNING!"
exit 0
fi
if [ "$STATUS" == "BUILD_ERROR" ] || [ "$STATUS" == "RUNTIME_ERROR" ]; then
echo "Deployment failed with status: $STATUS"
echo "Fetching logs..."
curl -s -H "Authorization: Bearer $HF_TOKEN" "https://huggingface.co/api/spaces/rixxabh/imageup/logs" | tail -n 50
exit 1
fi
RETRY_COUNT=$((RETRY_COUNT + 1))
sleep 15
done
echo "Timed out waiting for deployment."
exit 1