name: Sync Repository to HuggingFace Space # Auto-deploys the repo to the Hugging Face Space on every push to main. # Mirrors the simple, always-triggers approach used by ``lightweight-embeddings``. # # Triggers: # - push (main) → fires immediately when code lands on main. # - workflow_dispatch → manual override (e.g. emergency redeploy). # # Required secret: HF_TOKEN (Hugging Face access token with write scope) # Optional repo variables (Settings → Variables): # HF_USERNAME default: lamhieu # HF_SPACE default: docsifer on: push: branches: [main] workflow_dispatch: concurrency: group: hf-deploy cancel-in-progress: false jobs: sync-to-huggingface: name: Sync code to HuggingFace Space runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@v4 with: fetch-depth: 0 # Fetch all history for all branches and tags lfs: true # Enable Git LFS support - name: Push to HuggingFace Space env: HF_TOKEN: ${{ secrets.HF_TOKEN }} HF_USERNAME: ${{ vars.HF_USERNAME || 'lamhieu' }} HF_SPACE: ${{ vars.HF_SPACE || 'docsifer' }} run: | set -euo pipefail if [ -z "${HF_TOKEN:-}" ]; then echo "::error::HF_TOKEN secret is not configured." exit 1 fi git config user.email "github-actions[bot]@users.noreply.github.com" git config user.name "github-actions[bot]" REMOTE="https://${HF_USERNAME}:${HF_TOKEN}@huggingface.co/spaces/${HF_USERNAME}/${HF_SPACE}" echo "Pushing HEAD to space ${HF_USERNAME}/${HF_SPACE} (main)" # Force-push so the Space mirrors GitHub exactly. The Space history # is treated as a derived artifact, not a source of truth. if ! git push -f "${REMOTE}" HEAD:main; then echo "::error::Failed to sync with HuggingFace Space" exit 1 fi