openoperator / .github /workflows /deploy-huggingface-space.yml
OpenOperator Deployer
Deploy source revision ef73a4b421f2d1ececca20f99c9118f4621c5e28
6918275
Raw History Blame Contribute Delete
2.85 kB
name: Deploy Main Snapshot To Hugging Face Space
on:
push:
branches:
- main
workflow_dispatch:
concurrency:
group: huggingface-space-leon4gr45-openoperator
cancel-in-progress: true
permissions:
contents: read
jobs:
sync:
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- name: Check out main
uses: actions/checkout@v4
with:
# The Space receives a clean deployment snapshot, not GitHub history.
# Historical blobs in this repository exceed Hugging Face's limits.
fetch-depth: 1
- name: Validate Hugging Face token
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
run: |
if [[ -z "$HF_TOKEN" ]]; then
echo "::error::Add a write-scoped HF_TOKEN repository secret."
exit 1
fi
- name: Create clean Space snapshot
env:
SOURCE_SHA: ${{ github.sha }}
run: |
snapshot="$RUNNER_TEMP/huggingface-space"
mkdir -p "$snapshot"
git archive --format=tar HEAD | tar -xf - -C "$snapshot"
# Hugging Face reads Space configuration from README frontmatter. Add
# it only to the deployment snapshot so upstream README updates do
# not conflict with this deployment branch.
python3 - "$snapshot/README.md" <<'PY'
from pathlib import Path
import sys
import json
import os
readme = Path(sys.argv[1])
content = readme.read_text(encoding="utf-8")
(readme.parent / "openoperator-build.json").write_text(
json.dumps({"repository": "JsonLord/agent-zero", "branch": "main",
"source_sha": os.environ["SOURCE_SHA"]}) + "\n", encoding="utf-8")
metadata = """---
title: Agent Zero
emoji: 🤖
colorFrom: indigo
colorTo: blue
sdk: docker
app_port: 7860
pinned: false
---
"""
readme.write_text(metadata + content, encoding="utf-8")
PY
git -C "$snapshot" init --initial-branch=main
git -C "$snapshot" config user.name "github-actions[bot]"
git -C "$snapshot" config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git -C "$snapshot" add --all
git -C "$snapshot" commit -m "Deploy GitHub main at ${SOURCE_SHA}"
- name: Push snapshot to the Docker Space
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
run: |
snapshot="$RUNNER_TEMP/huggingface-space"
git -C "$snapshot" remote add huggingface "https://huggingface.co/spaces/Leon4gr45/openoperator"
git -C "$snapshot" -c "http.extraHeader=Authorization: Bearer ${HF_TOKEN}" push --force huggingface main:main