File size: 1,359 Bytes
8b50706
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
name: Deploy to HuggingFace Spaces

on:
  push:
    branches:
      - hf-space
  workflow_dispatch:

jobs:
  check-secret:
    runs-on: ubuntu-latest
    outputs:
      token-set: ${{ steps.check-key.outputs.defined }}
    steps:
      - id: check-key
        env:
          HF_TOKEN: ${{ secrets.HF_TOKEN }}
        if: "${{ env.HF_TOKEN != '' }}"
        run: echo "defined=true" >> $GITHUB_OUTPUT

  deploy:
    runs-on: ubuntu-latest
    needs: [check-secret]
    if: needs.check-secret.outputs.token-set == 'true'
    env:
      HF_TOKEN: ${{ secrets.HF_TOKEN }}
      HF_USERNAME: ${{ secrets.HF_USERNAME }}
      HF_SPACE_NAME: ${{ secrets.HF_SPACE_NAME }}
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Remove git history
        run: rm -rf .git

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

      - name: Set up Git and push to Space
        run: |
          git init --initial-branch=main
          git lfs track "*.ttf"
          rm demo.gif
          git add .
          git commit -m "GitHub deploy: ${{ github.sha }}"
          git push --force https://${HF_USERNAME}:${HF_TOKEN}@huggingface.co/spaces/${HF_USERNAME}/${HF_SPACE_NAME} main