Spaces:
Sleeping

shakauthossain commited on
Commit
8faac43
·
1 Parent(s): 8d8c5d0
Files changed (1) hide show
  1. .github/workflows/ci.yml +27 -19
.github/workflows/ci.yml CHANGED
@@ -54,41 +54,49 @@ jobs:
54
  steps:
55
  - name: Checkout code
56
  uses: actions/checkout@v4
57
-
58
  - name: Set up Python
59
  uses: actions/setup-python@v4
60
  with:
61
  python-version: '3.10'
62
-
63
  - name: Install dependencies
64
  run: |
65
  python -m pip install --upgrade pip
66
- pip install huggingface_hub
67
-
68
  - name: Push to Hugging Face Spaces
69
  env:
70
  HF_TOKEN: ${{ secrets.HF_TOKEN }}
71
  HF_USERNAME: ${{ secrets.HF_USERNAME }}
72
  HF_SPACE_NAME: ${{ secrets.HF_SPACE_NAME }}
73
  run: |
74
- python -m pip install -U "huggingface_hub" # provides the `hf` CLI
75
-
76
- # 1) Create the Space if it doesn't exist (SDK = docker for FastAPI apps)
77
- hf repo create "${HF_USERNAME}/${HF_SPACE_NAME}" \
78
- --repo-type space --space-sdk docker --exist-ok --token "${HF_TOKEN}"
79
-
80
- # 2) Configure Git user for CI commits
81
  git config --global user.email "github-actions@github.com"
82
  git config --global user.name "github-actions"
83
-
84
- # 3) Add the HF remote using token-in-URL auth (note the empty user before the colon)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
  git remote remove space 2>/dev/null || true
86
- git remote add space "https://:${HF_TOKEN}@huggingface.co/spaces/${HF_USERNAME}/${HF_SPACE_NAME}.git"
87
-
88
- # 4) Prepare local branch and push
89
  git fetch space || true
90
  git checkout -B main
91
  git add .
92
- git commit -m "Deploy to Hugging Face Spaces" || true
93
- # First-time sync is often a force push
94
- git push space main --force
 
 
54
  steps:
55
  - name: Checkout code
56
  uses: actions/checkout@v4
 
57
  - name: Set up Python
58
  uses: actions/setup-python@v4
59
  with:
60
  python-version: '3.10'
 
61
  - name: Install dependencies
62
  run: |
63
  python -m pip install --upgrade pip
64
+ pip install -U "huggingface_hub[cli]"
 
65
  - name: Push to Hugging Face Spaces
66
  env:
67
  HF_TOKEN: ${{ secrets.HF_TOKEN }}
68
  HF_USERNAME: ${{ secrets.HF_USERNAME }}
69
  HF_SPACE_NAME: ${{ secrets.HF_SPACE_NAME }}
70
  run: |
71
+ # Configure Git user for CI commits
 
 
 
 
 
 
72
  git config --global user.email "github-actions@github.com"
73
  git config --global user.name "github-actions"
74
+
75
+ # Create the Space if it doesn't exist using Python API
76
+ python << EOF
77
+ from huggingface_hub import HfApi
78
+ api = HfApi(token="${HF_TOKEN}")
79
+ try:
80
+ api.create_repo(
81
+ repo_id="${HF_USERNAME}/${HF_SPACE_NAME}",
82
+ repo_type="space",
83
+ space_sdk="docker",
84
+ exist_ok=True
85
+ )
86
+ print("Space created or already exists")
87
+ except Exception as e:
88
+ print(f"Error creating space: {e}")
89
+ EOF
90
+
91
+ # Add the HF remote using token-in-URL auth
92
  git remote remove space 2>/dev/null || true
93
+ git remote add space "https://user:${HF_TOKEN}@huggingface.co/spaces/${HF_USERNAME}/${HF_SPACE_NAME}.git"
94
+
95
+ # Prepare local branch and push
96
  git fetch space || true
97
  git checkout -B main
98
  git add .
99
+ git commit -m "Deploy to Hugging Face Spaces [skip ci]" || true
100
+
101
+ # Push to Hugging Face Spaces
102
+ git push space main