1515 - ' chat_env'
1616 - ' atari_env'
1717 - ' openspiel_env'
18+ custom_environment :
19+ description : ' Custom environment to deploy (leave empty for none)'
20+ required : false
21+ type : string
22+ default : ' '
1823 base_image_sha :
1924 description : ' SHA for openenv-base image (leave empty for latest)'
2025 required : false
2126 type : string
2227 default : ' '
23-
24- env :
25- HF_USERNAME : openenv
28+ hf_namespace :
29+ description : ' Hugging Face namespace to deploy to (leave empty for openenv)'
30+ required : false
31+ type : string
32+ default : ' openenv'
33+ private :
34+ description : ' Deploy the space as private (default: public)'
35+ required : false
36+ type : boolean
37+ default : false
38+ space_suffix :
39+ description : ' Suffix to add to space name (e.g., "-test" for test spaces)'
40+ required : false
41+ type : string
42+ default : ' '
2643
2744jobs :
2845 # Job to determine which environments to deploy
@@ -101,73 +118,23 @@ jobs:
101118 - name : Checkout repository
102119 uses : actions/checkout@v4
103120
104- - name : Set up Git
121+ - name : Install Hugging Face CLI
105122 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 || '' }}"
123+ curl -LsSf https://hf.co/cli/install.sh | bash
124+ echo "$HOME/.local/bin" >> $GITHUB_PATH
113125
114126 - name : Deploy to Hugging Face Space
115127 env :
116128 HF_TOKEN : ${{ secrets.HF_TOKEN }}
117- HF_USERNAME : openenv
129+ HF_NAMESPACE : ${{ github.event.inputs.hf_namespace }}
130+ HF_USERNAME : ${{ github.event.inputs.hf_namespace }}
118131 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:[email protected] /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
132+ chmod +x scripts/deploy_to_hf.sh
133+ if [ -n "${{ github.event.inputs.base_image_sha }}" ]; then
134+ ./scripts/deploy_to_hf.sh --env "${{ matrix.environment }}" --base-sha "${{ github.event.inputs.base_image_sha }}"
163135 else
164- echo "ℹ️ No changes to deploy "
136+ ./scripts/deploy_to_hf.sh --env "${{ matrix.environment }} "
165137 fi
166-
167- # Cleanup
168- cd ..
169- rm -rf hf-space
170- rm -rf hf-staging_$ENV_NAME
171138
172139 # Job to deploy single environment
173140 deploy-single :
@@ -184,70 +151,20 @@ jobs:
184151 - name : Checkout repository
185152 uses : actions/checkout@v4
186153
187- - name : Set up Git
154+ - name : Install Hugging Face CLI
188155 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 || '' }}"
156+ curl -LsSf https://hf.co/cli/install.sh | bash
157+ echo "$HOME/.local/bin" >> $GITHUB_PATH
196158
197159 - name : Deploy to Hugging Face Space
198160 env :
199161 HF_TOKEN : ${{ secrets.HF_TOKEN }}
200- HF_USERNAME : openenv
162+ HF_NAMESPACE : ${{ github.event.inputs.hf_namespace }}
163+ HF_USERNAME : ${{ github.event.inputs.hf_namespace }}
201164 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:[email protected] /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..."
165+ chmod +x scripts/deploy_to_hf.sh
166+ if [ -n "${{ github.event.inputs.base_image_sha }}" ]; then
167+ ./scripts/deploy_to_hf.sh --env "${{ matrix.environment }}" --base-sha "${{ github.event.inputs.base_image_sha }}"
213168 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 ..
169+ ./scripts/deploy_to_hf.sh --env "${{ matrix.environment }}"
220170 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
0 commit comments