name: Deploy to HF Spaces on: push: branches: [main] # Non-sensitive config — hardcoded here so the only required GitHub secret # is HF_TOKEN. Edit these in-place if your endpoint URL or model changes. env: HF_USERNAME: Hydr473 ENV_SPACE: Hydr473/stocker-env TRAIN_SPACE: Hydr473/stocker-train API_BASE_URL: https://at0e6z2u64774tc7.us-east-1.aws.endpoints.huggingface.cloud/v1 MODEL_NAME: ggml-org/gemma-4-26B-A4B-it-GGUF RESULTS_REPO: Hydr473/stocker-results STOCKER_CACHE_REPO: Hydr473/stocker-cache jobs: deploy-env-space: name: Deploy environment Space runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: fetch-depth: 0 lfs: true - name: Ensure Space exists + set secrets env: HF_TOKEN: ${{ secrets.HF_TOKEN }} run: | pip install --quiet "huggingface_hub>=1.10" python - <<'PY' import os from huggingface_hub import HfApi api = HfApi(token=os.environ["HF_TOKEN"]) repo = os.environ["ENV_SPACE"] api.create_repo(repo_id=repo, repo_type="space", space_sdk="docker", exist_ok=True) # Optional — env Space only needs LLM creds if /inference is hit for k in ("HF_TOKEN", "API_BASE_URL", "MODEL_NAME", "STOCKER_CACHE_REPO"): v = os.environ.get(k, "") if v: api.add_space_secret(repo_id=repo, key=k, value=v) print(f" [{repo}] set secret {k}") PY - name: Push to env Space env: HF_TOKEN: ${{ secrets.HF_TOKEN }} run: | git remote add hf-space \ https://${HF_USERNAME}:${HF_TOKEN}@huggingface.co/spaces/${ENV_SPACE} git push hf-space main --force deploy-train-space: name: Deploy training Space Dockerfile runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Ensure Space exists + set secrets env: HF_TOKEN: ${{ secrets.HF_TOKEN }} run: | pip install --quiet "huggingface_hub>=1.10" python - <<'PY' import os from huggingface_hub import HfApi api = HfApi(token=os.environ["HF_TOKEN"]) repo = os.environ["TRAIN_SPACE"] api.create_repo(repo_id=repo, repo_type="space", space_sdk="docker", exist_ok=True) for k in ("HF_TOKEN", "API_BASE_URL", "MODEL_NAME", "RESULTS_REPO"): v = os.environ.get(k, "") if v: api.add_space_secret(repo_id=repo, key=k, value=v) print(f" [{repo}] set secret {k}") PY - name: Push Dockerfile to train Space env: HF_TOKEN: ${{ secrets.HF_TOKEN }} run: | git clone \ https://${HF_USERNAME}:${HF_TOKEN}@huggingface.co/spaces/${TRAIN_SPACE} \ /tmp/train-space cp spaces/train/Dockerfile /tmp/train-space/Dockerfile cp spaces/train/app.py /tmp/train-space/app.py cd /tmp/train-space git config user.email "ci@github.com" git config user.name "GitHub Actions" git add Dockerfile app.py git diff --staged --quiet || git commit -m "ci: sync from stocker@${{ github.sha }}" git push