| 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 |
| |
| |
| 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" |
| |
| |
| git checkout --orphan hf-deploy |
| |
| |
| git add -A |
| |
| |
| git commit -m "Deploy to Hugging Face Spaces" |
| |
| |
| |
| |
| |
| |
| 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 |
|
|