Skip to content

Hugging Face Sync Workflow

This workflow automates the deployment of our core logic to a Hugging Face Space. It acts as a one-way synchronization mirror, ensuring that the code hosting the space is always identical to the code in our GitHub repository.

Workflow Configuration

View Workflow Configuration
name: Push folder to Hugging Face space
on:
  push:
    branches:
      - main
      - Milestone-*
    paths:
      - turing/**
      - requirements.txt
jobs:
  push-folder:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4    
      - name: Push changes
        env:
          HF_TOKEN: ${{ secrets.HF_TOKEN }}
          HF_USERNAME: turing-team
          SPACE_NAME: turing-space
        run: |
          git clone --depth 1 https://$HF_USERNAME:$HF_TOKEN@huggingface.co/spaces/$HF_USERNAME/$SPACE_NAME hf_sync_repo
          rm -rf hf_sync_repo/turing
          rm -rf hf_sync_repo/requirements.txt
          cp -r turing hf_sync_repo/
          cp requirements.txt hf_sync_repo/

          cd hf_sync_repo

          git config --global user.name "github-actions[bot]"
          git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"

          git add -A
          if [ -n "$(git status --porcelain)" ]; then
            git commit -m "Sync turing folder from GitHub"
            git push origin main
          else
            echo "No changes to commit"
          fi    

Detailed Explanation

1. Triggers (on)

The workflow listens for push events to the main branch (or release branches).

Optimization: It uses a paths filter for turing/** and requirements.txt. This means the sync only runs if you modify files inside the turing/ folder and requirements.txt file.

2. The Sync Job

The logic is executed in a straightforward bash script that performs a Delete & Replace Sync.

Environment Variables:

  • HF_TOKEN: A secret API token allowing write access to the Hugging Face account.

  • HF_USERNAME: The owner of the space (Adexandria).

  • SPACE_NAME: The specific repository name (turing-space).

The Sync Logic:

  1. Clone: It pulls the current state of the Hugging Face repository into a temporary folder hf_sync_repo.

  2. Clean:

    rm -rf hf_sync_repo/turing
    rm -rf hf_sync_repo/requirements.txt
    
    It deletes the existing code in the destination and prevents a merge conflict.

  3. Copy: It copies the fresh turing/ folder and requirements.txt from GitHub to the sync folder.

  4. Push: It commits the changes as the github-actions[bot] user.