Spaces:
Running
Running
| # Sync this GitHub repository to an existing Hugging Face Space. | |
| # | |
| # Configure before use: | |
| # - Create the Hugging Face Space first; this workflow does not create it. | |
| # - Add a GitHub Actions secret named HF_TOKEN with write access to the target | |
| # Hugging Face Space repository. | |
| # - Keep GitHub as the single source of truth. Do not edit files directly on | |
| # the Hugging Face Space, because this workflow force-syncs GitHub to HF. | |
| # - Make sure any required Space variables/secrets, such as MODAL_ANALYZE_URL, | |
| # MODAL_GENERATE_URL, and SNAP2SIM_API_TOKEN, are configured in the Space UI. | |
| name: Sync to Hugging Face Space | |
| on: | |
| push: | |
| branches: | |
| - main | |
| permissions: | |
| contents: read | |
| concurrency: | |
| group: sync-to-hugging-face-space | |
| cancel-in-progress: false | |
| jobs: | |
| sync: | |
| name: Push GitHub main to Hugging Face | |
| runs-on: ubuntu-latest | |
| env: | |
| HF_SPACE_URL: https://huggingface.co/spaces/build-small-hackathon/Snap2Sim | |
| steps: | |
| - name: Checkout full history with LFS | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| lfs: true | |
| - name: Install Git LFS | |
| run: | | |
| git lfs install | |
| git lfs fetch --all | |
| - name: Configure Hugging Face remote | |
| env: | |
| HF_TOKEN: ${{ secrets.HF_TOKEN }} | |
| run: | | |
| if [ -z "$HF_TOKEN" ]; then | |
| echo "GitHub secret HF_TOKEN is not configured." >&2 | |
| exit 1 | |
| fi | |
| git remote remove huggingface 2>/dev/null || true | |
| git remote add huggingface "https://hf:${HF_TOKEN}@${HF_SPACE_URL#https://}" | |
| - name: Push LFS objects to Hugging Face | |
| run: git lfs push huggingface --all | |
| - name: Force-sync main to Hugging Face | |
| run: | | |
| for attempt in 1 2 3 4 5; do | |
| if git push --force huggingface HEAD:main; then | |
| exit 0 | |
| fi | |
| delay=$((attempt * 20)) | |
| echo "Hugging Face push failed on attempt ${attempt}; retrying in ${delay}s..." >&2 | |
| sleep "$delay" | |
| done | |
| echo "Hugging Face push failed after 5 attempts." >&2 | |
| exit 1 | |