Skip to content

Commit ffb7acf

Browse files
committed
make gh action compatible with deploy script
1 parent 10518ed commit ffb7acf

File tree

1 file changed

+12
-122
lines changed

1 file changed

+12
-122
lines changed

.github/workflows/deploy-hf-env.yml

Lines changed: 12 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -101,73 +101,18 @@ jobs:
101101
- name: Checkout repository
102102
uses: actions/checkout@v4
103103

104-
- name: Set up Git
104+
- name: Install Hugging Face CLI
105105
run: |
106-
git config --global user.email "github-actions[bot]@users.noreply.github.com"
107-
git config --global user.name "github-actions[bot]"
108-
109-
- name: Prepare files for HF Space
110-
run: |
111-
chmod +x scripts/prepare_hf_deployment.sh
112-
./scripts/prepare_hf_deployment.sh "${{ matrix.environment }}" "${{ github.event.inputs.base_image_sha || '' }}"
106+
curl -LsSf https://hf.co/cli/install.sh | bash
107+
echo "$HOME/.local/bin" >> $GITHUB_PATH
113108
114109
- name: Deploy to Hugging Face Space
115110
env:
116111
HF_TOKEN: ${{ secrets.HF_TOKEN }}
117-
HF_USERNAME: openenv
112+
HF_NAMESPACE: ${{ env.HF_USERNAME }}
118113
run: |
119-
ENV_NAME="${{ matrix.environment }}"
120-
SPACE_NAME="$ENV_NAME"
121-
122-
echo "Deploying $ENV_NAME environment to HF Space: $SPACE_NAME"
123-
124-
# Clone the target space
125-
HF_SPACE_URL="https://$HF_USERNAME:$HF_TOKEN@huggingface.co/spaces/$HF_USERNAME/$SPACE_NAME"
126-
echo "Cloning HF Space..."
127-
128-
if git clone $HF_SPACE_URL hf-space 2>/dev/null; then
129-
echo "Space exists, updating..."
130-
else
131-
echo "Space doesn't exist, will be created on first push"
132-
mkdir -p hf-space
133-
cd hf-space
134-
git init
135-
git remote add origin $HF_SPACE_URL
136-
cd ..
137-
fi
138-
139-
cd hf-space
140-
141-
# Clear existing files (except .git)
142-
find . -mindepth 1 -maxdepth 1 ! -name '.git' -exec rm -rf {} +
143-
144-
# Copy prepared files
145-
cp -r ../hf-staging_$ENV_NAME/* .
146-
147-
# Set the correct remote URL
148-
git remote set-url origin $HF_SPACE_URL
149-
150-
# Check if there are changes
151-
if [ -n "$(git status --porcelain)" ]; then
152-
echo "Committing changes..."
153-
git add .
154-
git commit -m "🤖 Deploy $ENV_NAME environment - $(date +'%Y-%m-%d %H:%M:%S')"
155-
156-
echo "Pushing to Hugging Face..."
157-
if git push origin main 2>/dev/null || git push origin master 2>/dev/null; then
158-
echo "✅ Successfully deployed to https://huggingface.co/spaces/$HF_USERNAME/$SPACE_NAME"
159-
else
160-
echo "❌ Failed to push to Hugging Face. Check your credentials and permissions."
161-
exit 1
162-
fi
163-
else
164-
echo "ℹ️ No changes to deploy"
165-
fi
166-
167-
# Cleanup
168-
cd ..
169-
rm -rf hf-space
170-
rm -rf hf-staging_$ENV_NAME
114+
chmod +x scripts/deploy_to_hf.sh
115+
./scripts/deploy_to_hf.sh "${{ matrix.environment }}" "${{ github.event.inputs.base_image_sha || '' }}"
171116
172117
# Job to deploy single environment
173118
deploy-single:
@@ -184,70 +129,15 @@ jobs:
184129
- name: Checkout repository
185130
uses: actions/checkout@v4
186131

187-
- name: Set up Git
132+
- name: Install Hugging Face CLI
188133
run: |
189-
git config --global user.email "github-actions[bot]@users.noreply.github.com"
190-
git config --global user.name "github-actions[bot]"
191-
192-
- name: Prepare files for HF Space
193-
run: |
194-
chmod +x scripts/prepare_hf_deployment.sh
195-
./scripts/prepare_hf_deployment.sh "${{ matrix.environment }}" "${{ github.event.inputs.base_image_sha || '' }}"
134+
curl -LsSf https://hf.co/cli/install.sh | bash
135+
echo "$HOME/.local/bin" >> $GITHUB_PATH
196136
197137
- name: Deploy to Hugging Face Space
198138
env:
199139
HF_TOKEN: ${{ secrets.HF_TOKEN }}
200-
HF_USERNAME: openenv
140+
HF_NAMESPACE: ${{ env.HF_USERNAME }}
201141
run: |
202-
ENV_NAME="${{ matrix.environment }}"
203-
SPACE_NAME="$ENV_NAME"
204-
205-
echo "Deploying $ENV_NAME environment to HF Space: $SPACE_NAME"
206-
207-
# Clone the target space
208-
HF_SPACE_URL="https://$HF_USERNAME:$HF_TOKEN@huggingface.co/spaces/$HF_USERNAME/$SPACE_NAME"
209-
echo "Cloning HF Space..."
210-
211-
if git clone $HF_SPACE_URL hf-space 2>/dev/null; then
212-
echo "Space exists, updating..."
213-
else
214-
echo "Space doesn't exist, will be created on first push"
215-
mkdir -p hf-space
216-
cd hf-space
217-
git init
218-
git remote add origin $HF_SPACE_URL
219-
cd ..
220-
fi
221-
222-
cd hf-space
223-
224-
# Clear existing files (except .git)
225-
find . -mindepth 1 -maxdepth 1 ! -name '.git' -exec rm -rf {} +
226-
227-
# Copy prepared files
228-
cp -r ../hf-staging_$ENV_NAME/* .
229-
230-
# Set the correct remote URL
231-
git remote set-url origin $HF_SPACE_URL
232-
233-
# Check if there are changes
234-
if [ -n "$(git status --porcelain)" ]; then
235-
echo "Committing changes..."
236-
git add .
237-
git commit -m "🤖 Deploy $ENV_NAME environment - $(date +'%Y-%m-%d %H:%M:%S')"
238-
239-
echo "Pushing to Hugging Face..."
240-
if git push origin main 2>/dev/null || git push origin master 2>/dev/null; then
241-
echo "✅ Successfully deployed to https://huggingface.co/spaces/$HF_USERNAME/$SPACE_NAME"
242-
else
243-
echo "❌ Failed to push to Hugging Face. Check your credentials and permissions."
244-
exit 1
245-
fi
246-
else
247-
echo "ℹ️ No changes to deploy"
248-
fi
249-
250-
# Cleanup
251-
cd ..
252-
rm -rf hf-space
253-
rm -rf hf-staging_$ENV_NAME
142+
chmod +x scripts/deploy_to_hf.sh
143+
./scripts/deploy_to_hf.sh "${{ matrix.environment }}" "${{ github.event.inputs.base_image_sha || '' }}"

0 commit comments

Comments
 (0)