@@ -3,57 +3,66 @@ name: 🚀 Deploy Backend to HF Space
33on :
44 push :
55 branches :
6- - main # or your primary branch
6+ - main
77 paths :
8- - " backend/**" # only trigger when anything under backend/ changes
8+ - " backend/**"
99
1010jobs :
1111 deploy :
1212 runs-on : ubuntu-latest
13+ # set your HF username here (or replace with a secret if you prefer)
14+ env :
15+ HF_USER : Thunder1245
16+ HF_REPO : perspective-backend
17+
1318 steps :
1419 - name : 👉 Checkout code
1520 uses : actions/checkout@v4
1621 with :
1722 fetch-depth : 0
1823
19- - name : 🔒 Install HF CLI
20- run : pip install huggingface_hub
21-
22- - name : 🔑 HF login
23- env :
24- HF_TOKEN : ${{ secrets.HF_TOKEN }}
25- run : huggingface-cli login --token "$HF_TOKEN"
24+ - name : 🔍 Ensure HF_TOKEN is set
25+ run : |
26+ if [ -z "${{ secrets.HF_TOKEN }}" ]; then
27+ echo "ERROR: HF_TOKEN secret is not set. Add it in repository secrets: Settings → Secrets & variables → Actions."
28+ exit 1
29+ fi
2630
27- - name : 📂 Prepare Space repo
31+ - name : 📂 Prepare Space repo (clone)
2832 env :
2933 HF_TOKEN : ${{ secrets.HF_TOKEN }}
3034 run : |
31- rm -rf space-backend
35+ rm -rf space-backend || true
36+ # clone using token in URL (this authenticates the clone)
3237 git clone https://Thunder1245:${HF_TOKEN}@huggingface.co/spaces/Thunder1245/perspective-backend.git space-backend
3338
3439 - name : 📦 Install rsync
3540 run : |
3641 sudo apt-get update
3742 sudo apt-get install -y rsync
3843
39- - name : 📤 Sync backend code
44+ - name : 📤 Sync backend code to Space
4045 env :
4146 HF_TOKEN : ${{ secrets.HF_TOKEN }}
4247 run : |
48+ set -e
49+
4350 cd space-backend
4451
45- # Only remove tracked files (preserve .git and config)
52+ # Remove tracked files while preserving .git and config (ignore failure )
4653 git rm -r . || true
4754 cd ..
4855
49- # Copy new backend files in
56+ # Copy backend files into the cloned space directory
5057 cp -R backend/. space-backend/
5158
52- # Push new code to HF Space
59+ # Commit & push
5360 cd space-backend
5461 git config user.name "github-actions[bot]"
5562 git config user.email "github-actions[bot]@users.noreply.github.com"
5663 git add --all
57- git commit -m "Auto‑ deploy backend: ${{ github.sha }}" || echo "No changes to commit"
64+ git commit -m "Auto- deploy backend: ${{ github.sha }}" || echo "No changes to commit"
5865 git push origin main
5966
67+ - name : ✅ Done
68+ run : echo "Backend deployed to Hugging Face Space: https://huggingface.co/spaces/${HF_USER}/${HF_REPO}"
0 commit comments