Spaces:
Running
Running
| name: Sync to Hugging Face Space (force-by-default) | |
| on: | |
| push: | |
| branches: ["main", "master"] | |
| # Optional manual trigger | |
| workflow_dispatch: {} | |
| jobs: | |
| sync-to-hub: | |
| runs-on: ubuntu-latest | |
| concurrency: | |
| group: hf-space-sync-canonical | |
| cancel-in-progress: false | |
| # Set these as Repository Variables: | |
| # Settings β Secrets and variables β Actions β Variables | |
| # HF_USERNAME = your HF username (e.g. ruslanmv) | |
| # SPACE_NAME = your Space name (e.g. matrix-ai) | |
| env: | |
| HF_USERNAME: ${{ vars.HF_USERNAME }} | |
| SPACE_NAME: ${{ vars.SPACE_NAME }} | |
| steps: | |
| - name: Checkout (with LFS) | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| lfs: true | |
| - name: Prepare Git + LFS | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git lfs install --local | |
| - name: Force push GitHub HEAD β Space main (GitHub is canonical) | |
| env: | |
| # Add this as a Repository Secret: | |
| # Settings β Secrets and variables β Actions β New repository secret β HF_TOKEN | |
| HF_TOKEN: ${{ secrets.HF_TOKEN }} | |
| run: | | |
| set -e | |
| if [ -z "$HF_USERNAME" ] || [ -z "$SPACE_NAME" ]; then | |
| echo "β Missing HF_USERNAME or SPACE_NAME repo Variables." | |
| echo " Add them under: Settings β Secrets and variables β Actions β Variables." | |
| exit 1 | |
| fi | |
| if [ -z "$HF_TOKEN" ]; then | |
| echo "β Missing HF_TOKEN secret (write token for Spaces)." | |
| echo " Add it under: Settings β Secrets and variables β Actions β New repository secret." | |
| exit 1 | |
| fi | |
| REMOTE_URL="https://${HF_USERNAME}:${HF_TOKEN}@huggingface.co/spaces/${HF_USERNAME}/${SPACE_NAME}" | |
| echo "π Forcing GitHub HEAD β Space main..." | |
| git push --force "$REMOTE_URL" HEAD:main | |
| # Best-effort push for LFS objects (if any) | |
| git lfs push --all "$REMOTE_URL" main || true | |
| echo "β Sync complete: Space 'main' now matches GitHub HEAD." | |