TriSenti AI v1.0 #4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy backend to Hugging Face Space | |
| # Auto-sync the backend to the HF Space on every push to main that touches | |
| # backend files. You can also run it manually from the Actions tab. | |
| on: | |
| push: | |
| branches: [main] | |
| paths: | |
| - "api/**" | |
| - "preprocessing/**" | |
| - "models/**" | |
| - "Dockerfile" | |
| - "requirements-backend.txt" | |
| - "deploy/huggingface/README.md" | |
| - ".github/workflows/deploy-hf.yml" | |
| workflow_dispatch: {} # allow manual runs | |
| # Avoid overlapping deploys if you push twice quickly. | |
| concurrency: | |
| group: deploy-hf | |
| cancel-in-progress: true | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout project | |
| uses: actions/checkout@v4 | |
| with: | |
| lfs: false | |
| - name: Assemble Space files into a clean folder | |
| run: | | |
| set -e | |
| rm -rf space_build | |
| mkdir -p space_build | |
| cp Dockerfile space_build/ | |
| cp requirements-backend.txt space_build/ | |
| # The Space README MUST be the one with HF frontmatter: | |
| cp deploy/huggingface/README.md space_build/README.md | |
| cp -r api space_build/api | |
| cp -r preprocessing space_build/preprocessing | |
| cp -r models space_build/models | |
| # Drop caches / backups that shouldn't ship. | |
| find space_build -type d -name "__pycache__" -prune -exec rm -rf {} + | |
| rm -rf space_build/models/backup_* || true | |
| # HF requires binary files (.h5 / .pkl) to be tracked with git-LFS. | |
| printf '%s\n' '*.h5 filter=lfs diff=lfs merge=lfs -text' '*.pkl filter=lfs diff=lfs merge=lfs -text' > space_build/.gitattributes | |
| - name: Push to Hugging Face Space | |
| env: | |
| HF_TOKEN: ${{ secrets.HF_TOKEN }} | |
| HF_USERNAME: ${{ secrets.HF_USERNAME }} | |
| HF_SPACE: ${{ secrets.HF_SPACE }} | |
| run: | | |
| set -e | |
| if [ -z "$HF_TOKEN" ] || [ -z "$HF_USERNAME" ] || [ -z "$HF_SPACE" ]; then | |
| echo "::error::Missing secrets. Set HF_TOKEN, HF_USERNAME and HF_SPACE in repo Settings → Secrets → Actions." | |
| exit 1 | |
| fi | |
| cd space_build | |
| git init -q | |
| git checkout -q -b main | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| # HF requires model binaries via git-LFS. Initialise LFS and track the | |
| # binary extensions BEFORE adding files so they're stored as LFS objects. | |
| git lfs install --local | |
| git lfs track "*.h5" "*.pkl" | |
| git add . | |
| git commit -q -m "Sync backend from ${GITHUB_SHA::7}" | |
| REMOTE="https://${HF_USERNAME}:${HF_TOKEN}@huggingface.co/spaces/${HF_USERNAME}/${HF_SPACE}" | |
| # Force-push: the Space mirrors the backend subset of this repo. | |
| git lfs push --all "$REMOTE" main || true | |
| git push -f "$REMOTE" main | |
| echo "✅ Pushed to https://huggingface.co/spaces/${HF_USERNAME}/${HF_SPACE}" |