Deploy versioned space artifact to Hugging Face #17
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 versioned space artifact to Hugging Face | |
| # Publishes Universal Brain chat UI (universal_brain_chat) via scripts/build_space_artifact.py. | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: "Version number (e.g. 1, 2, 3)" | |
| required: true | |
| default: "1" | |
| namespace: | |
| description: "Hugging Face namespace (user or org)" | |
| required: true | |
| default: "HyperlinksSpace" | |
| model_id: | |
| description: "HF classifier repo for the Space encoder (--encoder), e.g. HyperlinksSpace/TinyModel1" | |
| required: true | |
| default: "" | |
| jobs: | |
| deploy-space: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| - name: Setup Python | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: "3.11" | |
| - name: Unit tests (stdlib, tests/) | |
| uses: ./.github/actions/stdlib-unittest | |
| - name: Install dependencies | |
| run: pip install --upgrade huggingface_hub | |
| - name: Verify Hugging Face token (preflight) | |
| env: | |
| HF_TOKEN: ${{ secrets.HF_TOKEN }} | |
| run: | | |
| python - <<'PY' | |
| import os | |
| import sys | |
| token = (os.environ.get("HF_TOKEN") or "").strip() | |
| if not token: | |
| print( | |
| "::error::Missing GitHub secret HF_TOKEN. " | |
| "Add it under Settings → Secrets and variables → Actions " | |
| "(a Hugging Face token with write access to the target namespace).", | |
| file=sys.stderr, | |
| ) | |
| sys.exit(1) | |
| from huggingface_hub import HfApi | |
| from huggingface_hub.errors import HfHubHTTPError | |
| try: | |
| info = HfApi(token=token).whoami() | |
| except HfHubHTTPError as exc: | |
| print(f"::error::HF_TOKEN rejected by Hugging Face ({exc}). Renew the token and scopes.", file=sys.stderr) | |
| sys.exit(1) | |
| name = info.get("name") if isinstance(info, dict) else str(info) | |
| print(f"Hugging Face auth OK (logged in as {name}).") | |
| PY | |
| - name: Build versioned Space folder | |
| run: | | |
| python scripts/build_space_artifact.py \ | |
| --namespace "${{ github.event.inputs.namespace }}" \ | |
| --version "${{ github.event.inputs.version }}" \ | |
| --model-id "${{ github.event.inputs.model_id }}" \ | |
| --output-dir ".tmp/TinyModel${{ github.event.inputs.version }}Space" | |
| - name: Publish TinyModel{version}Space | |
| env: | |
| HF_TOKEN: ${{ secrets.HF_TOKEN }} | |
| run: | | |
| python scripts/publish_hf_artifact.py \ | |
| --namespace "${{ github.event.inputs.namespace }}" \ | |
| --name "TinyModel${{ github.event.inputs.version }}Space" \ | |
| --repo-type space \ | |
| --source-dir ".tmp/TinyModel${{ github.event.inputs.version }}Space" |