Spaces:
Sleeping
Sleeping
Ray Chen
commited on
Commit
·
2e621ff
1
Parent(s):
4112a5c
change: get HF username from GitHub Action
Browse files
.github/tools/deploy_to_space.py
CHANGED
|
@@ -5,16 +5,14 @@ import sys
|
|
| 5 |
from config import SPACE_CONFIG
|
| 6 |
from model import Space
|
| 7 |
|
| 8 |
-
DEFAULT_USER = "jy-raychen"
|
| 9 |
|
| 10 |
-
|
| 11 |
-
def force_push_to_remote(space: Space, token: str, branch_name: str):
|
| 12 |
proc = subprocess.run(
|
| 13 |
[
|
| 14 |
"git",
|
| 15 |
"push",
|
| 16 |
"--force",
|
| 17 |
-
f"https://{
|
| 18 |
f"{branch_name}:main",
|
| 19 |
],
|
| 20 |
capture_output=True,
|
|
@@ -32,12 +30,15 @@ def force_push_to_remote(space: Space, token: str, branch_name: str):
|
|
| 32 |
if __name__ == "__main__":
|
| 33 |
parser = argparse.ArgumentParser(description="Deploy to Hugging Face spaces.")
|
| 34 |
parser.add_argument("--branch_name", required=True)
|
|
|
|
| 35 |
parser.add_argument("--user_token", required=True)
|
| 36 |
args = parser.parse_args()
|
| 37 |
|
| 38 |
space = Space(SPACE_CONFIG["default"])
|
| 39 |
|
| 40 |
-
push_result = force_push_to_remote(
|
|
|
|
|
|
|
| 41 |
if not push_result:
|
| 42 |
sys.exit(1)
|
| 43 |
print(push_result)
|
|
|
|
| 5 |
from config import SPACE_CONFIG
|
| 6 |
from model import Space
|
| 7 |
|
|
|
|
| 8 |
|
| 9 |
+
def force_push_to_remote(space: Space, username: str, token: str, branch_name: str):
|
|
|
|
| 10 |
proc = subprocess.run(
|
| 11 |
[
|
| 12 |
"git",
|
| 13 |
"push",
|
| 14 |
"--force",
|
| 15 |
+
f"https://{username}:{token}@huggingface.co/spaces/{space.owner}/{space.name}",
|
| 16 |
f"{branch_name}:main",
|
| 17 |
],
|
| 18 |
capture_output=True,
|
|
|
|
| 30 |
if __name__ == "__main__":
|
| 31 |
parser = argparse.ArgumentParser(description="Deploy to Hugging Face spaces.")
|
| 32 |
parser.add_argument("--branch_name", required=True)
|
| 33 |
+
parser.add_argument("--username", required=True)
|
| 34 |
parser.add_argument("--user_token", required=True)
|
| 35 |
args = parser.parse_args()
|
| 36 |
|
| 37 |
space = Space(SPACE_CONFIG["default"])
|
| 38 |
|
| 39 |
+
push_result = force_push_to_remote(
|
| 40 |
+
space, args.username, args.user_token, args.branch_name
|
| 41 |
+
)
|
| 42 |
if not push_result:
|
| 43 |
sys.exit(1)
|
| 44 |
print(push_result)
|
.github/workflows/deploy-to-space.yaml
CHANGED
|
@@ -30,4 +30,4 @@ jobs:
|
|
| 30 |
git commit -m "[skip ci] update README.md"
|
| 31 |
fi
|
| 32 |
- name: Run deploy tool
|
| 33 |
-
run: python3 .github/tools/deploy_to_space.py --branch_name="${{ github.ref_name }}" --user_token="${{ secrets.HF_TOKEN }}"
|
|
|
|
| 30 |
git commit -m "[skip ci] update README.md"
|
| 31 |
fi
|
| 32 |
- name: Run deploy tool
|
| 33 |
+
run: python3 .github/tools/deploy_to_space.py --branch_name="${{ github.ref_name }}" --username="${{ vars.HF_USERNAME }}" --user_token="${{ secrets.HF_TOKEN }}"
|