Deploy to Hugging Face Spaces #27
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy to Hugging Face Spaces | |
| on: | |
| workflow_run: | |
| workflows: ["Build & Publish Docker Image"] | |
| types: [completed] | |
| workflow_dispatch: | |
| jobs: | |
| deploy: | |
| if: > | |
| github.event_name == 'workflow_dispatch' || | |
| (github.event.workflow_run.conclusion == 'success' && | |
| github.event.workflow_run.event == 'push' && | |
| github.event.workflow_run.head_branch == 'master') | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.event_name == 'workflow_run' && github.event.workflow_run.head_sha || github.sha }} | |
| fetch-depth: 1 | |
| - name: Prepare Space repo (pull prebuilt GHCR image) | |
| run: | | |
| set -euo pipefail | |
| IMAGE_TAG="latest" | |
| rm -rf /tmp/hf-space | |
| mkdir -p /tmp/hf-space | |
| cp README.md /tmp/hf-space/README.md | |
| cat > /tmp/hf-space/Dockerfile <<EOF | |
| FROM ghcr.io/duoan/torchcode:${IMAGE_TAG} | |
| EOF | |
| - name: Push generated Space to Hugging Face | |
| env: | |
| HF_TOKEN: ${{ secrets.HF_TOKEN }} | |
| run: | | |
| set -euo pipefail | |
| cd /tmp/hf-space | |
| git init | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add README.md Dockerfile | |
| git commit -m "Deploy prebuilt image ${GITHUB_SHA}" | |
| git branch -M main | |
| git remote add origin https://duoan:$HF_TOKEN@huggingface.co/spaces/duoan/TorchCode | |
| git push origin main --force |