Skip to content

Commit 8a53bb1

Browse files
committed
fix hf_token in workflow
1 parent 80bb0d8 commit 8a53bb1

File tree

2 files changed

+208
-5
lines changed

2 files changed

+208
-5
lines changed

TESTING.md

Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
# Testing Guide for deploy_to_hf.sh
2+
3+
## Local Script Testing
4+
5+
### 1. Dry-Run Test (Safest - No Deployment)
6+
7+
Test the script without actually deploying:
8+
9+
```bash
10+
# Test with dry-run (prepares files but doesn't upload)
11+
./scripts/deploy_to_hf.sh echo_env --dry-run
12+
13+
# Verify the staging directory was created
14+
ls -la hf-staging/
15+
16+
# Check the generated files
17+
tree hf-staging/ -L 3
18+
```
19+
20+
**What to verify:**
21+
- ✅ Staging directory created at `hf-staging/<namespace>/<env_name>`
22+
-`Dockerfile` exists and looks correct
23+
-`README.md` exists with correct metadata
24+
-`src/core/` and `src/envs/<env>/` are copied correctly
25+
- ✅ No deployment attempted (no HF API calls)
26+
27+
### 2. Test with Test Namespace
28+
29+
Deploy to your personal test space:
30+
31+
```bash
32+
# Use your HF username and add -test suffix to avoid affecting production
33+
./scripts/deploy_to_hf.sh echo_env \
34+
--hf-namespace $(hf auth whoami | head -n1) \
35+
--space-suffix -test
36+
37+
# Or use positional arguments
38+
./scripts/deploy_to_hf.sh echo_env "" "$(hf auth whoami | head -n1)"
39+
```
40+
41+
**What to verify:**
42+
- ✅ Space created at `https://huggingface.co/spaces/<your-username>/echo_env-test`
43+
- ✅ Files uploaded correctly
44+
- ✅ Space builds successfully (check Space logs)
45+
46+
### 3. Test Different Environments
47+
48+
```bash
49+
# Test smallest environment first (echo_env)
50+
./scripts/deploy_to_hf.sh echo_env --dry-run
51+
52+
# Test with specific base image SHA
53+
./scripts/deploy_to_hf.sh echo_env --base-sha abc123 --dry-run
54+
55+
# Test other environments
56+
./scripts/deploy_to_hf.sh coding_env --dry-run
57+
./scripts/deploy_to_hf.sh chat_env --dry-run
58+
```
59+
60+
### 4. Validate Generated Files
61+
62+
After dry-run, inspect the generated files:
63+
64+
```bash
65+
# Check Dockerfile
66+
cat hf-staging/<namespace>/echo_env/Dockerfile
67+
68+
# Check README
69+
cat hf-staging/<namespace>/echo_env/README.md
70+
71+
# Verify structure
72+
find hf-staging/<namespace>/echo_env -type f
73+
```
74+
75+
## GitHub Actions Testing
76+
77+
### 0. Do I Need to Merge to Main?
78+
79+
**No!** You can test from any branch:
80+
81+
**Option A: Test from feature branch**
82+
1. Push your changes (including workflow file) to your branch
83+
2. Go to GitHub → Actions tab
84+
3. Use the branch dropdown to select your branch
85+
4. Find "Deploy to Hugging Face Environment" workflow
86+
5. Click "Run workflow" → Select your branch → Run
87+
88+
**Option B: Merge to main first** (easier to find)
89+
- Workflows are most visible from the default branch
90+
- After merge, they're easier to access in the Actions tab
91+
92+
**Recommendation:** Test locally first, then test from your branch before merging.
93+
94+
### 1. Manual Workflow Dispatch
95+
96+
1. Go to GitHub → Actions → "Deploy to Hugging Face Environment"
97+
2. Click "Run workflow"
98+
3. Select:
99+
- Environment: `echo_env` (start with smallest)
100+
- Base image SHA: Leave empty (or test with specific SHA)
101+
4. Click "Run workflow"
102+
103+
**What to verify:**
104+
- ✅ Workflow runs without errors
105+
- ✅ HF CLI installs correctly
106+
- ✅ Script executes successfully
107+
- ✅ Space deployed to `openenv/echo_env`
108+
109+
### 2. Test All Environments (Matrix)
110+
111+
1. Run workflow with environment: `all`
112+
2. This will deploy all environments in parallel
113+
3. Monitor all matrix jobs
114+
115+
### 3. Test Automatic Trigger
116+
117+
Make a change to trigger automatic deployment:
118+
119+
```bash
120+
# Make a small change to core
121+
echo "# Test" >> src/core/client_types.py
122+
git add src/core/client_types.py
123+
git commit -m "test: trigger deployment"
124+
git push
125+
```
126+
127+
**What to verify:**
128+
- ✅ Workflow triggers automatically
129+
- ✅ All environments deploy (because core changed)
130+
- ✅ Only changed environments deploy (if only one env changed)
131+
132+
### 4. Check Workflow Logs
133+
134+
After workflow runs:
135+
1. Click on the workflow run
136+
2. Check each job's logs
137+
3. Verify:
138+
- ✅ HF CLI installation succeeded
139+
- ✅ Script executed without errors
140+
- ✅ Deployment succeeded
141+
- ✅ Space URL printed at end
142+
143+
## Verification Checklist
144+
145+
### After Local Dry-Run
146+
- [ ] Staging directory structure correct
147+
- [ ] Dockerfile uses correct base image
148+
- [ ] README.md has correct metadata
149+
- [ ] All source files copied
150+
- [ ] No sensitive files included
151+
152+
### After Local Deployment
153+
- [ ] Space appears on Hugging Face
154+
- [ ] Space builds successfully (check build logs)
155+
- [ ] Space is accessible via web UI
156+
- [ ] API endpoints respond correctly
157+
158+
### After GitHub Actions Deployment
159+
- [ ] All matrix jobs succeeded
160+
- [ ] Spaces deployed to correct namespace (`openenv/`)
161+
- [ ] Spaces build successfully
162+
- [ ] No authentication errors
163+
- [ ] Script output shows success message
164+
165+
## Common Issues & Debugging
166+
167+
### Issue: "hf CLI not found"
168+
```bash
169+
# Install HF CLI locally
170+
curl -LsSf https://hf.co/cli/install.sh | sh
171+
# Reload shell or add to PATH
172+
export PATH="$HOME/.local/bin:$PATH"
173+
```
174+
175+
### Issue: "Authentication failed"
176+
```bash
177+
# Authenticate
178+
hf auth login
179+
# Or set token
180+
export HF_TOKEN=your_token_here
181+
```
182+
183+
### Issue: "Namespace access denied"
184+
- Verify your HF token has access to the target namespace
185+
- For org namespaces, token needs org permissions
186+
- Check: `hf auth whoami`
187+
188+
### Issue: "Script fails in GitHub Actions"
189+
1. Check if `HF_TOKEN` secret is set in repository settings
190+
2. Verify token has correct permissions (write access to spaces)
191+
3. Check workflow logs for detailed error messages
192+
193+
## Testing Checklist
194+
195+
Before merging:
196+
- [ ] Local dry-run works for all environments
197+
- [ ] Local deployment works to test namespace
198+
- [ ] GitHub Actions workflow runs successfully
199+
- [ ] At least one environment deployed via CI
200+
- [ ] Deployed space builds and runs correctly
201+

scripts/deploy_to_hf.sh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -505,12 +505,14 @@ fi
505505

506506
echo "🔑 Ensuring Hugging Face authentication..."
507507

508-
# In GitHub Actions, always use HF_TOKEN if provided
509-
if [ "$IS_GITHUB_ACTIONS" = true ] && [ -n "${HF_TOKEN:-}" ]; then
508+
# In GitHub Actions, HF CLI automatically uses HF_TOKEN env var
509+
if [ "$IS_GITHUB_ACTIONS" = true ]; then
510+
if [ -z "${HF_TOKEN:-}" ]; then
511+
echo "Error: HF_TOKEN secret is required in GitHub Actions" >&2
512+
echo "Please set the HF_TOKEN secret in repository settings" >&2
513+
exit 1
514+
fi
510515
echo "Using HF_TOKEN from GitHub Actions environment"
511-
hf auth login --token "$HF_TOKEN" --add-to-git-credential >/dev/null 2>&1 || {
512-
echo "Warning: Failed to authenticate with HF_TOKEN, continuing anyway..." >&2
513-
}
514516
elif [ -n "${HF_TOKEN:-}" ]; then
515517
# In local environment, try to use HF_TOKEN if set
516518
hf auth login --token "$HF_TOKEN" --add-to-git-credential >/dev/null 2>&1 || true

0 commit comments

Comments
 (0)