-
Notifications
You must be signed in to change notification settings - Fork 1
73 lines (66 loc) · 2.66 KB
/
Copy pathdeploy-hf.yml
File metadata and controls
73 lines (66 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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
# Commit small model files as plain git (no LFS) inside the Space repo.
printf '%s\n' '*.h5 -filter -diff -merge text=auto' '*.pkl -filter -diff -merge text=auto' > 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"
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 push -f "$REMOTE" main
echo "✅ Pushed to https://huggingface.co/spaces/${HF_USERNAME}/${HF_SPACE}"