Spaces:
Runtime error
Runtime error
Ray Chen commited on
Commit ·
31ffb4a
1
Parent(s): 70d8d48
new: push to space by GitHub Actions
Browse filesFiles changed (2)
1234567891011121314151617181920212223242526272829303132333435363738394041import argparseimport subprocessimport sys
DEFAULT_USER = "jy-raychen"DEFAULT_SPACE_OWNER = "jy-raychen"DEFAULT_SPACE_NAME = "example"
def force_push_to_remote(token, branch_name): proc = subprocess.run( [ "git", "push", "--force", f"https://{DEFAULT_USER}:{token}@huggingface.co/spaces/{DEFAULT_SPACE_OWNER}/{DEFAULT_SPACE_NAME}", f"{branch_name}:main", ], capture_output=True, )
if proc.returncode == 0: # NOTE: `git push` output always goes to stderr results = proc.stderr.decode("utf-8") return results
print(f"Failed to push remote: {proc.stderr.decode('utf-8')}") return None
if __name__ == "__main__": parser = argparse.ArgumentParser(description="Deploy to Hugging Face spaces.") parser.add_argument("--branch_name", required=True) parser.add_argument("--user_token", required=True) args = parser.parse_args()
push_result = force_push_to_remote(args.user_token, args.branch_name) if not push_result: sys.exit(1) print(push_result) sys.exit(0)123456789101112131415161718192021222324name: Deploy Spacerun-name: Deploy to space
on: push: branches: - '**'
concurrency: group: ${{ github.workflow }}-${{ github.ref_name }} cancel-in-progress: true
jobs: run_deploy_tool: runs-on: ubuntu-latest permissions: contents: read steps: - name: Check out repository code uses: actions/checkout@v4 with: fetch-depth: '0' - name: Run deploy tool run: python3 .github/tools/deploy_to_space.py --branch_name="${{ github.ref_name }}" --user_token="${{ secrets.HF_TOKEN }}".github/tools/deploy_to_space.pyAdded+41
.github/workflows/deploy-to-space.yamlAdded+24