| name: Deploy to Hugging Face Space |
|
|
| on: |
| push: |
| branches: |
| - main |
| workflow_dispatch: |
|
|
| jobs: |
| deploy: |
| runs-on: ubuntu-latest |
|
|
| steps: |
| - name: Checkout repository |
| uses: actions/checkout@v4 |
| with: |
| fetch-depth: 0 |
|
|
| - name: Push to Hugging Face Space |
| env: |
| HF_USERNAME: Udasri |
| HF_SPACE_NAME: uh.info |
| HF_TOKEN: ${{ secrets.HF_TOKEN }} |
| run: | |
| if [ -z "$HF_TOKEN" ]; then |
| echo "HF_TOKEN secret is missing." |
| exit 1 |
| fi |
| |
| git config --global user.name "github-actions[bot]" |
| git config --global user.email "github-actions[bot]@users.noreply.github.com" |
|
|
| |
| HF_TOKEN_CLEAN="$(printf '%s' "$HF_TOKEN" | tr -d '\r\n' | xargs)" |
|
|
| if [ -z "$HF_TOKEN_CLEAN" ]; then |
| echo "HF_TOKEN is empty after sanitization." |
| exit 1 |
| fi |
|
|
| |
| HF_TOKEN_ENC="$(python -c 'import urllib.parse, sys; print(urllib.parse.quote(sys.argv[1], safe=""))' "$HF_TOKEN_CLEAN")" |
|
|
| git remote remove space 2>/dev/null || true |
| git remote add space "https://${HF_USERNAME}:${HF_TOKEN_ENC}@huggingface.co/spaces/${HF_USERNAME}/${HF_SPACE_NAME}" |
| git push --force space HEAD:main |
|
|