name: Deploy ke Hugging Face Space env: # Ganti dengan username dan nama Static Space milikmu. Contoh: namauser/chat-pgvector-praktikum HF_SPACE_ID: "GANTI_USERNAME/GANTI_NAMA_SPACE" on: push: branches: [main] workflow_dispatch: permissions: contents: read concurrency: group: deploy-hugging-face-space cancel-in-progress: false jobs: deploy: runs-on: ubuntu-latest timeout-minutes: 10 steps: - name: Ambil kode dari GitHub uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 with: persist-credentials: false - name: Siapkan Python uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0 with: python-version: "3.12" - name: Pasang pustaka Hugging Face run: python -m pip install "huggingface_hub==1.19.0" - name: Unggah enam berkas ke Space env: HF_TOKEN: ${{ secrets.HF_TOKEN }} run: | python - <<'PY' import os from pathlib import Path from huggingface_hub import HfApi repo_id = os.environ["HF_SPACE_ID"].strip() if "GANTI_" in repo_id or repo_id.count("/") != 1: raise SystemExit("Isi HF_SPACE_ID dengan username/nama-space milikmu.") if not os.environ.get("HF_TOKEN"): raise SystemExit("Buat repository secret bernama HF_TOKEN di GitHub.") files = ["README.md", "index.html", "style.css", "app.js", "engine-worker.js", "data.json"] missing = [name for name in files if not Path(name).is_file()] if missing: raise SystemExit("Berkas belum ada di root repo: " + ", ".join(missing)) api = HfApi() if api.space_info(repo_id=repo_id).sdk != "static": raise SystemExit("HF_SPACE_ID harus mengarah ke Static Space yang sudah dibuat.") commit = api.upload_folder( repo_id=repo_id, repo_type="space", folder_path=".", revision="main", allow_patterns=files, commit_message="Deploy dari GitHub " + os.environ["GITHUB_SHA"][:12], ) print("Berkas terkirim:", commit.commit_url) print("Buka tab App:", f"https://huggingface.co/spaces/{repo_id}") PY