FaceSWAP / .github /workflows /deploy.yml
aditya-rAj19's picture
Retry HF push on transient failures (Space busy building)
2499381
Raw
History Blame Contribute Delete
1.82 kB
name: Deploy to Hugging Face Spaces
on:
push:
branches: [main]
jobs:
deploy:
name: Push source to Hugging Face Spaces
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Configure git
run: |
git config user.email "adivid198986@gmail.com"
git config user.name "aditya-rAj19"
- name: Push to Hugging Face Spaces
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
HF_USER: aditya-rAj19
HF_SPACE: FaceSWAP
run: |
if [ -z "$HF_TOKEN" ]; then
echo "::error::HF_TOKEN secret is empty or not set."
echo "Add it at: GitHub repo -> Settings -> Secrets and variables -> Actions -> New repository secret"
echo "Name: HF_TOKEN Value: a Hugging Face token with WRITE access (huggingface.co -> Settings -> Access Tokens)"
exit 1
fi
# Token-in-URL auth. Force-push the repo to the Space.
git remote remove hf 2>/dev/null || true
git remote add hf "https://${HF_USER}:${HF_TOKEN}@huggingface.co/spaces/${HF_USER}/${HF_SPACE}"
echo "Pushing to https://huggingface.co/spaces/${HF_USER}/${HF_SPACE} ..."
# HF can transiently reject a push while the Space is still building
# from a previous push — retry a few times before failing.
n=0
until git push hf HEAD:main --force; do
n=$((n+1))
if [ "$n" -ge 4 ]; then
echo "::error::Push to Hugging Face failed after $n attempts."
exit 1
fi
echo "Push attempt $n failed - retrying in 15s..."
sleep 15
done
echo "Pushed to Hugging Face Spaces successfully."