File size: 1,879 Bytes
a938ee3
db40fc9
a938ee3
a48496c
 
 
a938ee3
 
 
 
 
 
3a88bbb
a938ee3
 
 
 
 
 
 
 
 
 
 
 
3a88bbb
 
db40fc9
d0be28c
a938ee3
 
 
d0be28c
 
 
 
3a88bbb
 
 
 
 
 
a75acbd
 
 
3a88bbb
 
 
 
 
a75acbd
3a88bbb
 
a75acbd
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
name: Update Space

on:
  push:
    branches:
      main

jobs:
  sync-to-hub:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        space_name: [company-pet-policy, about-mls, shakespeare]  # List your Hugging Face space names here
    steps:
      - name: Checkout repository
        uses: actions/checkout@v2
        with:
          fetch-depth: 0
          lfs: true

      - name: Configure Git
        run: |
          git config --global user.email "[email protected]"
          git config --global user.name "GitHub Actions"

      - name: Install huggingface_hub
        run: pip install huggingface_hub

      - name: Login to Hugging Face (use secret token)
        env:
          HF_TOKEN: ${{ secrets.HF_TOKEN }}
        run: |
          git config --global user.email "[email protected]"
          git config --global user.name "GitHub Actions"
          huggingface-cli login --token ${{ secrets.HF_TOKEN }}
          
      - name: Get Space Name
        id: get_space_name
        run: echo ${{ matrix.space_name }}

      - name: Add Hugging Face Space as remote (loop through each space)
        run: |
          git remote add ${{ steps.get_space_name.outputs.value }} https://huggingface.co/spaces/david-oplatka/${{ steps.get_space_name.outputs.value }}.git
          git config --add remote.${{ steps.get_space_name.outputs.value }}.oauth_token ${{ secrets.HF_TOKEN }}


      - name: Get changed files
        id: changed_files
        run: |
          git diff --name-only origin/main HEAD
      
      - name: Push only changed files (loop through each space)
        run: |
          changed_files=$(echo "${{ steps.changed_files.outputs.value }}")
          for file in $changed_files; do
            git add $file
            git commit -m "Updating $file"
            git push ${{ steps.get_space_name.outputs.value }} main
          done