PersonaRag / .github /workflows /push_to_hf_space.yml
github-actions[bot]
Deploy snapshot to HF (binaries stripped)
a0b643a
name: Sync to Hugging Face Space (always strip binaries)
on:
push:
branches: [ "hf-deploy" ]
workflow_dispatch:
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout source
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: hf-deploy
- name: Create clean snapshot (remove .pkl/.faiss no matter what)
run: |
set -euxo pipefail
# Export current commit as plain files (no .git history)
rm -rf /tmp/snapshot
mkdir -p /tmp/snapshot
git archive --format=tar HEAD | tar -x -C /tmp/snapshot
echo "== Files matching .pkl/.faiss BEFORE removal =="
(cd /tmp/snapshot && find . -type f \( -name "*.pkl" -o -name "*.faiss" \) -print) || true
# Always delete these binaries (even if someone committed them)
(cd /tmp/snapshot && find . -type f \( -name "*.pkl" -o -name "*.faiss" \) -print -delete) || true
echo "== Files matching .pkl/.faiss AFTER removal =="
(cd /tmp/snapshot && find . -type f \( -name "*.pkl" -o -name "*.faiss" \) -print) || true
# Ensure they won't be committed into the snapshot repo
printf "\n# Never deploy vectorstore binaries to Spaces\n*.pkl\n*.faiss\n" >> /tmp/snapshot/.gitignore
# Build a new single-commit git repo from the cleaned snapshot
cd /tmp/snapshot
git init
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add -A
git commit -m "Deploy snapshot to HF (binaries stripped)"
- name: Push snapshot to Hugging Face Space (HF main)
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
HF_USERNAME: ritup3 # CHANGE if needed
SPACE_NAME: PersonaRag # CHANGE if needed
run: |
set -euxo pipefail
cd /tmp/snapshot
# Authenticated remote for HF Space
git remote add space https://$HF_USERNAME:$HF_TOKEN@huggingface.co/spaces/$HF_USERNAME/$SPACE_NAME
# Spaces deploy from branch "main"
git branch -M main
git push space main --force