shakauthossain commited on
Commit
3f9f52c
Β·
unverified Β·
1 Parent(s): d9d280b

Enhance CI workflow with secret checks and error handling

Browse files

Added debugging steps to check if Hugging Face secrets are set and improved error handling for space accessibility.

Files changed (1) hide show
  1. .github/workflows/ci.yml +106 -48
.github/workflows/ci.yml CHANGED
@@ -1,5 +1,4 @@
1
  name: Backend CI
2
-
3
  on:
4
  push:
5
  branches: [ main, develop ]
@@ -7,7 +6,6 @@ on:
7
  branches: [ main ]
8
 
9
  jobs:
10
-
11
  backend:
12
  runs-on: ubuntu-latest
13
  strategy:
@@ -55,7 +53,29 @@ jobs:
55
  - name: Checkout code
56
  uses: actions/checkout@v4
57
  with:
58
- lfs: true # Enable Git LFS if needed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
 
60
  - name: Verify Space Configuration
61
  env:
@@ -63,67 +83,87 @@ jobs:
63
  HF_USERNAME: ${{ secrets.HF_USERNAME }}
64
  HF_SPACE_NAME: ${{ secrets.HF_SPACE_NAME }}
65
  run: |
66
- echo "=== Debugging Space Configuration ==="
 
 
67
 
68
  # Check if variables are set
69
  if [ -z "$HF_USERNAME" ]; then
70
- echo "ERROR: HF_USERNAME is empty or not set!"
 
71
  exit 1
72
  fi
73
 
74
  if [ -z "$HF_SPACE_NAME" ]; then
75
- echo "ERROR: HF_SPACE_NAME is empty or not set!"
 
76
  exit 1
77
  fi
78
 
79
  if [ -z "$HF_TOKEN" ]; then
80
- echo "ERROR: HF_TOKEN is empty or not set!"
 
81
  exit 1
82
  fi
83
 
84
- # Show lengths (not masked)
85
- echo "HF_USERNAME length: ${#HF_USERNAME}"
86
- echo "HF_SPACE_NAME length: ${#HF_SPACE_NAME}"
87
- echo "HF_TOKEN length: ${#HF_TOKEN}"
88
-
89
- # Show first and last characters (to detect spaces/special chars)
90
  echo ""
91
- echo "First char of HF_USERNAME: '$(echo -n "${HF_USERNAME}" | cut -c1)'"
92
- echo "Last char of HF_USERNAME: '$(echo -n "${HF_USERNAME}" | tail -c1)'"
93
- echo "First char of HF_SPACE_NAME: '$(echo -n "${HF_SPACE_NAME}" | cut -c1)'"
94
- echo "Last char of HF_SPACE_NAME: '$(echo -n "${HF_SPACE_NAME}" | tail -c1)'"
95
-
96
- # Check for whitespace
97
  echo ""
98
- if [[ "$HF_USERNAME" =~ [[:space:]] ]]; then
99
- echo "WARNING: HF_USERNAME contains whitespace!"
 
 
100
  fi
101
- if [[ "$HF_SPACE_NAME" =~ [[:space:]] ]]; then
102
- echo "WARNING: HF_SPACE_NAME contains whitespace!"
 
103
  fi
104
 
105
- # Try to access the space via API
106
  echo ""
107
- echo "Testing space accessibility..."
108
- RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" \
 
109
  "https://huggingface.co/api/spaces/${HF_USERNAME}/${HF_SPACE_NAME}")
110
- echo "API Response Code: $RESPONSE"
111
-
112
- if [ "$RESPONSE" == "200" ]; then
113
- echo "βœ“ Space exists and is accessible!"
114
- elif [ "$RESPONSE" == "404" ]; then
115
- echo "βœ— Space not found (404). Please check:"
116
- echo " 1. Space exists at https://huggingface.co/spaces/${HF_USERNAME}/${HF_SPACE_NAME}"
117
- echo " 2. HF_USERNAME and HF_SPACE_NAME secrets are correct"
118
- elif [ "$RESPONSE" == "401" ] || [ "$RESPONSE" == "403" ]; then
119
- echo "βœ— Access denied ($RESPONSE). Check if space is private and token has access"
120
- else
121
- echo "βœ— Unexpected response: $RESPONSE"
122
- fi
123
-
124
- echo "====================================="
125
 
126
- - name: Push to Hugging Face Space
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
127
  env:
128
  HF_TOKEN: ${{ secrets.HF_TOKEN }}
129
  HF_USERNAME: ${{ secrets.HF_USERNAME }}
@@ -142,12 +182,30 @@ jobs:
142
  # Add the Hugging Face Space as a remote
143
  git remote add space "${SPACE_URL}"
144
 
145
- # Try to fetch from the space (non-fatal if it fails)
146
  echo "Fetching from Hugging Face Space..."
147
- git fetch space || echo "Could not fetch from space (this is OK for first push)"
 
 
 
 
 
 
 
 
 
 
 
148
 
149
  # Push to the space
150
- echo "Pushing to Hugging Face Space: ${HF_USERNAME}/${HF_SPACE_NAME}"
151
- git push space HEAD:main --force
152
-
153
- echo "βœ“ Successfully deployed to https://huggingface.co/spaces/${HF_USERNAME}/${HF_SPACE_NAME}"
 
 
 
 
 
 
 
 
1
  name: Backend CI
 
2
  on:
3
  push:
4
  branches: [ main, develop ]
 
6
  branches: [ main ]
7
 
8
  jobs:
 
9
  backend:
10
  runs-on: ubuntu-latest
11
  strategy:
 
53
  - name: Checkout code
54
  uses: actions/checkout@v4
55
  with:
56
+ fetch-depth: 0
57
+ lfs: true
58
+
59
+ - name: Debug - Check secrets are set
60
+ run: |
61
+ echo "Checking if secrets are available..."
62
+ if [ -z "${{ secrets.HF_TOKEN }}" ]; then
63
+ echo "❌ HF_TOKEN is NOT set!"
64
+ else
65
+ echo "βœ… HF_TOKEN is set (length: ${{ secrets.HF_TOKEN != '' && 'yes' || 'no' }})"
66
+ fi
67
+
68
+ if [ -z "${{ secrets.HF_USERNAME }}" ]; then
69
+ echo "❌ HF_USERNAME is NOT set!"
70
+ else
71
+ echo "βœ… HF_USERNAME is set"
72
+ fi
73
+
74
+ if [ -z "${{ secrets.HF_SPACE_NAME }}" ]; then
75
+ echo "❌ HF_SPACE_NAME is NOT set!"
76
+ else
77
+ echo "βœ… HF_SPACE_NAME is set"
78
+ fi
79
 
80
  - name: Verify Space Configuration
81
  env:
 
83
  HF_USERNAME: ${{ secrets.HF_USERNAME }}
84
  HF_SPACE_NAME: ${{ secrets.HF_SPACE_NAME }}
85
  run: |
86
+ set +e # Don't exit on error in this step
87
+
88
+ echo "=== Space Configuration Check ==="
89
 
90
  # Check if variables are set
91
  if [ -z "$HF_USERNAME" ]; then
92
+ echo "❌ ERROR: HF_USERNAME is empty!"
93
+ echo "Please add HF_USERNAME secret in GitHub Settings > Secrets > Actions"
94
  exit 1
95
  fi
96
 
97
  if [ -z "$HF_SPACE_NAME" ]; then
98
+ echo "❌ ERROR: HF_SPACE_NAME is empty!"
99
+ echo "Please add HF_SPACE_NAME secret in GitHub Settings > Secrets > Actions"
100
  exit 1
101
  fi
102
 
103
  if [ -z "$HF_TOKEN" ]; then
104
+ echo "❌ ERROR: HF_TOKEN is empty!"
105
+ echo "Please add HF_TOKEN secret in GitHub Settings > Secrets > Actions"
106
  exit 1
107
  fi
108
 
109
+ echo "βœ… All secrets are set"
 
 
 
 
 
110
  echo ""
111
+ echo "String lengths:"
112
+ echo " HF_USERNAME: ${#HF_USERNAME} characters"
113
+ echo " HF_SPACE_NAME: ${#HF_SPACE_NAME} characters"
114
+ echo " HF_TOKEN: ${#HF_TOKEN} characters"
 
 
115
  echo ""
116
+
117
+ # Check for common issues
118
+ if [[ "$HF_USERNAME" =~ ^[[:space:]] ]] || [[ "$HF_USERNAME" =~ [[:space:]]$ ]]; then
119
+ echo "⚠️ WARNING: HF_USERNAME has leading or trailing spaces!"
120
  fi
121
+
122
+ if [[ "$HF_SPACE_NAME" =~ ^[[:space:]] ]] || [[ "$HF_SPACE_NAME" =~ [[:space:]]$ ]]; then
123
+ echo "⚠️ WARNING: HF_SPACE_NAME has leading or trailing spaces!"
124
  fi
125
 
126
+ # Test API access
127
  echo ""
128
+ echo "Testing Hugging Face API access..."
129
+ HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" \
130
+ -H "Authorization: Bearer ${HF_TOKEN}" \
131
  "https://huggingface.co/api/spaces/${HF_USERNAME}/${HF_SPACE_NAME}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132
 
133
+ echo "API Response: $HTTP_CODE"
134
+
135
+ case $HTTP_CODE in
136
+ 200)
137
+ echo "βœ… Space found and accessible!"
138
+ ;;
139
+ 404)
140
+ echo "❌ Space not found (404)"
141
+ echo ""
142
+ echo "Troubleshooting steps:"
143
+ echo "1. Verify your space exists on Hugging Face"
144
+ echo "2. Check the URL format: https://huggingface.co/spaces/USERNAME/SPACE-NAME"
145
+ echo "3. Ensure HF_USERNAME matches your Hugging Face username exactly (case-sensitive)"
146
+ echo "4. Ensure HF_SPACE_NAME matches your space name exactly (case-sensitive)"
147
+ exit 1
148
+ ;;
149
+ 401|403)
150
+ echo "❌ Authentication failed ($HTTP_CODE)"
151
+ echo ""
152
+ echo "Token may be invalid or expired. Please:"
153
+ echo "1. Go to https://huggingface.co/settings/tokens"
154
+ echo "2. Create a new token with 'write' permissions"
155
+ echo "3. Update the HF_TOKEN secret in GitHub"
156
+ exit 1
157
+ ;;
158
+ *)
159
+ echo "⚠️ Unexpected response: $HTTP_CODE"
160
+ echo "Proceeding anyway..."
161
+ ;;
162
+ esac
163
+
164
+ echo "===================================="
165
+
166
+ - name: Deploy to Hugging Face Space
167
  env:
168
  HF_TOKEN: ${{ secrets.HF_TOKEN }}
169
  HF_USERNAME: ${{ secrets.HF_USERNAME }}
 
182
  # Add the Hugging Face Space as a remote
183
  git remote add space "${SPACE_URL}"
184
 
185
+ # Try to fetch from the space
186
  echo "Fetching from Hugging Face Space..."
187
+ if git fetch space 2>&1 | tee /tmp/fetch_output.txt; then
188
+ echo "βœ… Fetch successful"
189
+ else
190
+ if grep -q "Repository not found" /tmp/fetch_output.txt; then
191
+ echo "❌ Repository not found - this usually means:"
192
+ echo " 1. The space doesn't exist"
193
+ echo " 2. The username or space name is incorrect"
194
+ echo " 3. The space is private and the token doesn't have access"
195
+ exit 1
196
+ fi
197
+ echo "⚠️ Fetch failed, but continuing (may be first push)"
198
+ fi
199
 
200
  # Push to the space
201
+ echo ""
202
+ echo "Pushing to Hugging Face Space..."
203
+ if git push space HEAD:main --force; then
204
+ echo ""
205
+ echo "βœ… Successfully deployed!"
206
+ echo "πŸš€ View your space at: https://huggingface.co/spaces/${HF_USERNAME}/${HF_SPACE_NAME}"
207
+ else
208
+ echo ""
209
+ echo "❌ Push failed!"
210
+ exit 1
211
+ fi