Spaces:
Sleeping

curium-intel / .github /workflows /deploy-space.yml
Piers Lyon
Claude Opus 4.7 (1M context)
Add deploy-to-Space workflow β€” manual trigger, no auto-deploy
482374c
Raw History Blame Contribute Delete
4.75 kB
name: Deploy to HF Space
# Manual-trigger deploy of the repo to the live HF Space. Triggered
# explicitly so a push to main never silently ships to production β€”
# you click "Run workflow" when you want the Space updated.
#
# Once you've watched a few runs and trust it, flip the trigger to
# `push: branches: [main]` to make every commit auto-deploy.
on:
workflow_dispatch:
inputs:
commit_message:
description: 'Commit message to use on the Space'
required: false
default: 'Sync from GitHub main'
type: string
permissions:
contents: read
concurrency:
# Only one deploy at a time β€” avoid Space-side race conditions
group: deploy-space
cancel-in-progress: false
jobs:
deploy:
runs-on: ubuntu-latest
timeout-minutes: 15
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
SPACE_REPO_ID: 'mipwr-admin/curium-intel'
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install huggingface_hub
run: pip install --quiet huggingface_hub
- name: Sanity-check secrets
run: |
if [ -z "$HF_TOKEN" ]; then
echo "❌ HF_TOKEN secret is not set on this repository"
exit 1
fi
if [ -z "$SPACE_REPO_ID" ]; then
echo "❌ SPACE_REPO_ID not set in workflow env"
exit 1
fi
# Sanity-check that no .env file is about to be uploaded
if [ -f .env ]; then
echo "❌ .env present in checkout β€” refusing to deploy"
exit 1
fi
# And no obvious secrets in tracked files
if git ls-files | xargs grep -l "ANTHROPIC_API_KEY\s*=\s*sk-" 2>/dev/null; then
echo "❌ Detected an API key literal in tracked files β€” refusing to deploy"
exit 1
fi
echo "βœ… Secrets present, no committed credentials detected"
- name: Upload to HF Space
env:
MSG: ${{ github.event.inputs.commit_message }}
SHA: ${{ github.sha }}
run: |
python <<'PY'
import os, sys
from huggingface_hub import HfApi
api = HfApi(token=os.environ["HF_TOKEN"])
repo_id = os.environ["SPACE_REPO_ID"]
msg = (os.environ.get("MSG") or "Sync from GitHub main").strip()
sha = os.environ.get("SHA", "")[:7]
if sha:
msg = f"{msg} ({sha})"
print(f"Uploading repo β†’ Space {repo_id} (commit: {msg!r})")
# ignore_patterns: paths we never want in the Space's repo.
# Comprehensive list because a leaked secret here would be live
# in seconds. Anything not in this list ships verbatim.
api.upload_folder(
folder_path=".",
repo_id=repo_id,
repo_type="space",
commit_message=msg,
ignore_patterns=[
# VCS / CI metadata
".git/**", ".github/**", ".gitignore", ".gitattributes",
# Python build artefacts
"**/__pycache__/**", "*.pyc", ".pytest_cache/**",
# Virtualenvs
"venv/**", ".venv/**", "env/**",
# Local secrets + state
".env", ".env.*", ".envrc",
"leads.db", "leads.db-*", "sales_signals.db", "*.db-journal",
"data/**", "logs/**",
# Local working files
"*.xlsx", "*.csv", "*.tsv", "IWD_Outreach_Tracker_*",
# Editor / OS
".vscode/**", ".idea/**", ".DS_Store",
# Claude / agent state
".claude/**", "memory/**",
# Docs that don't need to ship
"DEPLOY.md", "HF_DEPLOY.md",
],
)
print("βœ… Upload complete")
PY
- name: Verify Space is responding
run: |
# Wait a bit for the Space to start the rebuild, then probe.
sleep 15
for i in 1 2 3 4 5; do
stage=$(curl -s "https://huggingface.co/api/spaces/${SPACE_REPO_ID}" \
| python -c 'import sys,json; print(json.load(sys.stdin).get("runtime",{}).get("stage","?"))')
echo "Space stage: $stage"
case "$stage" in
RUNNING) echo "βœ… Space is running"; exit 0 ;;
BUILDING|RUNTIME_ERROR|STOPPED) echo "Stage: $stage β€” continuing to poll" ;;
esac
sleep 20
done
echo "⚠️ Space hasn't reported RUNNING after polling β€” check the Space logs in the HF UI"