| name: Deploy To Hugging Face Space | |
| on: | |
| push: | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Validate required secrets | |
| shell: bash | |
| run: | | |
| test -n "${{ secrets.HF_TOKEN }}" || (echo "HF_TOKEN is missing" && exit 1) | |
| test -n "${{ secrets.HF_SPACE_REPO_ID }}" || (echo "HF_SPACE_REPO_ID is missing" && exit 1) | |
| - name: Configure git user | |
| run: | | |
| git config --global user.name "github-actions[bot]" | |
| git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
| - name: Push repository to Hugging Face Space | |
| env: | |
| HF_TOKEN: ${{ secrets.HF_TOKEN }} | |
| HF_SPACE_REPO_ID: ${{ secrets.HF_SPACE_REPO_ID }} | |
| shell: bash | |
| run: | | |
| HF_URL="https://oauth2:${HF_TOKEN}@huggingface.co/spaces/${HF_SPACE_REPO_ID}" | |
| git remote remove hf 2>/dev/null || true | |
| git remote add hf "${HF_URL}" | |
| git push hf HEAD:main --force | |