name: CI / Deploy to HuggingFace Spaces on: push: branches: [main] pull_request: branches: [main] workflow_dispatch: # allow manual trigger from GitHub UI jobs: # ── Gate: tests + type-check + build must pass before any deploy ────────────── test: runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@v4 - name: Set up Python uses: actions/setup-python@v5 with: python-version: "3.12" cache: pip - name: Install backend dependencies run: | pip install -r backend/requirements.txt # test-only plugins (mirror agents/pyproject.toml [dev]); asyncio_mode=auto # is configured there. Intentionally not in the prod image. pip install pytest pytest-asyncio pytest-mock - name: Run agent test suite working-directory: agents run: python -m pytest tests/ -q - name: Set up Node uses: actions/setup-node@v4 with: node-version: "20" - name: Set up pnpm uses: pnpm/action-setup@v4 with: version: 10 # Run from the workspace root using the repo's own scripts, matching how # the project actually builds locally. The lockfile lives under apps/web, # so a non-frozen install is used to avoid root-lockfile false failures. - name: Install web dependencies run: pnpm install - name: Type-check run: pnpm type-check - name: Build run: pnpm build # ── Deploy: only on push to main, and only after `test` passes ──────────────── deploy: needs: test if: github.event_name == 'push' && github.ref == 'refs/heads/main' runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@v4 with: fetch-depth: 0 lfs: true - name: Push to HuggingFace Space env: HF_TOKEN: ${{ secrets.HF_TOKEN }} # Format: your-hf-username/your-space-name (e.g. harsha/modelforge-backend) HF_SPACE_ID: ${{ secrets.HF_SPACE_ID }} run: | git config --global user.email "github-action@modelforge.ai" git config --global user.name "ModelForge CI" # Create an orphan branch — single flat commit with NO git history. # This avoids the large files that exist in old commits being rejected # by HuggingFace Hub's 10 MB per-file limit. git checkout --orphan hf-deploy # Stage everything from the current working tree git add -A # Remove the legacy data directory (large static files not needed # in the Docker image — they are not referenced by the current code) git rm --cached backend/data/ -r --ignore-unmatch git rm --cached backend/uploads/ -r --ignore-unmatch git rm --cached agents/runs/ -r --ignore-unmatch git rm --cached agents/traces/ -r --ignore-unmatch git commit -m "deploy: $(date '+%Y-%m-%d %H:%M UTC')" git remote add space \ "https://user:${HF_TOKEN}@huggingface.co/spaces/${HF_SPACE_ID}" # Force-push the flat commit — HF Space rebuilds Docker on every push git push space hf-deploy:main --force