Spaces:
Running
Running
| name: Deploy to HF Space | |
| on: | |
| push: | |
| branches: [main] | |
| jobs: | |
| deploy: | |
| name: Deploy to HF Space | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install huggingface_hub | |
| run: pip install huggingface_hub -q | |
| - name: Upload to HF Space | |
| env: | |
| HF_TOKEN: ${{ secrets.HF_TOKEN }} | |
| run: | | |
| python3 - <<'EOF' | |
| from huggingface_hub import HfApi | |
| import os, pathlib, tempfile | |
| api = HfApi(token=os.environ["HF_TOKEN"]) | |
| repo_id = "amaljoe88/vision-coder-openenv" | |
| sha = os.environ.get("GITHUB_SHA", "")[:8] | |
| raw_base = "https://raw.githubusercontent.com/amaljoe/vision-coder-openenv/main/" | |
| # Upload everything except blog.md and binary PNGs. | |
| # delete_patterns removes HF files that no longer exist in GitHub. | |
| api.upload_folder( | |
| folder_path=".", | |
| repo_id=repo_id, | |
| repo_type="space", | |
| ignore_patterns=["assets/*.png", "*.png", "__pycache__", "*.pyc", | |
| ".git", "checkpoints/", "*.log", "blog.md"], | |
| delete_patterns=["*.py", "*.md", "*.sh", "*.yaml", "*.yml", | |
| "*.txt", "*.toml", "*.lock", "*.json", "*.jsonl"], | |
| commit_message=f"deploy: sync {sha} from GitHub Actions", | |
| ) | |
| # Upload blog.md with local asset paths replaced by GitHub raw URLs | |
| content = pathlib.Path("blog.md").read_text() | |
| content = content.replace("assets/", raw_base + "assets/") | |
| tmp = pathlib.Path(tempfile.mktemp(suffix=".md")) | |
| tmp.write_text(content) | |
| api.upload_file( | |
| path_or_fileobj=str(tmp), | |
| path_in_repo="blog.md", | |
| repo_id=repo_id, | |
| repo_type="space", | |
| commit_message=f"deploy: blog.md with GitHub raw URLs ({sha})", | |
| ) | |
| tmp.unlink() | |
| # Upload docs/data.json with image paths replaced by GitHub raw URLs | |
| import json | |
| raw_docs = raw_base + "docs/" | |
| data = json.loads(pathlib.Path("docs/data.json").read_text()) | |
| for case in data: | |
| case["reference_image"] = raw_docs + case["reference_image"] | |
| for variant in case["variants"]: | |
| variant["image"] = raw_docs + variant["image"] | |
| tmp = pathlib.Path(tempfile.mktemp(suffix=".json")) | |
| tmp.write_text(json.dumps(data)) | |
| api.upload_file( | |
| path_or_fileobj=str(tmp), | |
| path_in_repo="docs/data.json", | |
| repo_id=repo_id, | |
| repo_type="space", | |
| commit_message=f"deploy: docs/data.json with GitHub raw image URLs ({sha})", | |
| ) | |
| tmp.unlink() | |
| print(f"Deployed to https://huggingface.co/spaces/{repo_id}") | |
| EOF | |