Spaces:
Build error
Build error
| name: CI/CD Pipeline | |
| on: | |
| push: | |
| branches: [main] | |
| pull_request: | |
| branches: [main] | |
| permissions: | |
| contents: read | |
| env: | |
| FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true | |
| jobs: | |
| lint: | |
| name: Lint & Syntax Check | |
| 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: | | |
| pip install --upgrade pip | |
| pip install flake8 | |
| pip install -r requirements.txt | |
| - name: Lint with flake8 | |
| run: | | |
| # Stop build on syntax errors or undefined names | |
| flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics --exclude=.venv,__pycache__,models | |
| # Warnings (non-blocking) | |
| flake8 . --count --exit-zero --max-complexity=10 --max-line-length=140 --statistics --exclude=.venv,__pycache__,models | |
| - name: Verify imports | |
| run: python -c "from core.parsers import process_file; from core.analytics import run_analytics_pipeline; from core.llm_service import generate_report; print('All imports OK')" | |
| deploy: | |
| name: Deploy to Hugging Face | |
| runs-on: ubuntu-latest | |
| needs: lint | |
| if: github.ref == 'refs/heads/main' && github.event_name == 'push' | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| lfs: true | |
| - name: Push to Hugging Face Spaces | |
| env: | |
| HF_TOKEN: ${{ secrets.HF_TOKEN }} | |
| run: | | |
| set -ex | |
| git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
| git config --global user.name "github-actions[bot]" | |
| # Create a clean orphan branch with no history | |
| # This ensures we don't accidentally push historical binary files. | |
| git checkout --orphan hf-deploy | |
| git rm -rf --cached . | |
| # Add current files | |
| git add -A | |
| # Hugging Face Spaces rejects binary files in git pushes. | |
| # Remove binaries from staging before we make the commit. | |
| git rm --cached static/favicon.png || true | |
| git rm --cached .gitattributes || true | |
| git commit -m "deploy: HF sync (Run $GITHUB_RUN_NUMBER)" | |
| # Use a dedicated remote for Hugging Face | |
| git remote add hf https://rixxabh:${{ secrets.HF_TOKEN }}@huggingface.co/spaces/rixxabh/the-algorithm | |
| echo "Initiating forced push to Hugging Face Space..." | |
| git push --force hf hf-deploy:main | |
| - name: Monitor Deployment Status | |
| env: | |
| HF_TOKEN: ${{ secrets.HF_TOKEN }} | |
| run: | | |
| SPACE_ID="rixxabh/the-algorithm" | |
| echo "Monitoring deployment for $SPACE_ID..." | |
| # Poll every 15 seconds for up to 120 times (30 minutes) | |
| for i in {1..120}; do | |
| RESPONSE=$(curl -s https://huggingface.co/api/spaces/$SPACE_ID) | |
| STATE=$(echo $RESPONSE | jq -r '.runtime.stage' | tr '[:lower:]' '[:upper:]') | |
| echo "Attempt $i: Current HF Space State: $STATE" | |
| case $STATE in | |
| "RUNNING") | |
| echo "✅ Deployment Successful! Space is live." | |
| exit 0 | |
| ;; | |
| "BUILDING"|"RUNNING_BUILDING"|"STARTING"|"RUNNING_APP_STARTING"|"INITIALIZING"|"QUEUED") | |
| echo "...waiting for deployment to complete..." | |
| sleep 15 | |
| ;; | |
| *) | |
| echo "❌ Deployment failed or unexpected state: $STATE" | |
| echo "Fetching Build Logs (10s snapshot)..." | |
| timeout 10s curl -s -N -H "Authorization: Bearer $HF_TOKEN" https://huggingface.co/api/spaces/$SPACE_ID/logs/build | tail -n 50 || true | |
| echo "" | |
| echo "Fetching Container Logs (10s snapshot)..." | |
| timeout 10s curl -s -N -H "Authorization: Bearer $HF_TOKEN" https://huggingface.co/api/spaces/$SPACE_ID/logs/run | tail -n 50 || true | |
| exit 1 | |
| ;; | |
| esac | |
| done | |
| echo "⚠️ Deployment timed out after 30 minutes." | |
| exit 1 | |