Skip to content

Commit d472889

Browse files
committed
feat: Add GitHub Actions workflow to auto-sync with Hugging Face Spaces
1 parent 3218957 commit d472889

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

.github/workflows/huggingface.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Sync to Hugging Face Space
2+
3+
on:
4+
push:
5+
branches: [main]
6+
# Allows you to run this workflow manually from the Actions tab
7+
workflow_dispatch:
8+
9+
jobs:
10+
sync-to-hub:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
with:
15+
fetch-depth: 0
16+
lfs: true
17+
18+
- name: Push to Hugging Face Hub
19+
env:
20+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
21+
HF_USERNAME: ${{ secrets.HF_USERNAME }}
22+
HF_SPACE_NAME: ${{ secrets.HF_SPACE_NAME }}
23+
run: |
24+
if [ -z "$HF_TOKEN" ] || [ -z "$HF_USERNAME" ] || [ -z "$HF_SPACE_NAME" ]; then
25+
echo "Error: Missing Hugging Face Secrets. Please add HF_TOKEN, HF_USERNAME, and HF_SPACE_NAME to GitHub Secrets."
26+
exit 1
27+
fi
28+
29+
# Rename the specific Dockerfile for Hugging Face
30+
cp Dockerfile.hf Dockerfile
31+
32+
git config --global user.email "github-actions@github.com"
33+
git config --global user.name "GitHub Actions Sync Bot"
34+
35+
# Add the HF remote and push
36+
git remote add hf https://$HF_USERNAME:$HF_TOKEN@huggingface.co/spaces/$HF_USERNAME/$HF_SPACE_NAME
37+
38+
# Push the main branch to Hugging Face (force push to ensure it matches GitHub exactly)
39+
git push --force hf main:main

0 commit comments

Comments
 (0)