Skip to content

Commit 8929ce4

Browse files
committed
remove push and use validate
1 parent fcf996d commit 8929ce4

File tree

1 file changed

+37
-133
lines changed

1 file changed

+37
-133
lines changed

.github/workflows/pr-new-env.yml

Lines changed: 37 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,13 @@ jobs:
9494
echo "new_envs_json=${NEW_ENVS_JSON}" >> "$GITHUB_OUTPUT"
9595
9696
deploy-and-health-check:
97-
name: Deploy and Validate New Environments
97+
name: Validate New Environments
9898
needs: detect-new-envs
9999
if: needs.detect-new-envs.outputs.has_new_envs == 'true'
100100
runs-on: ubuntu-latest
101101
strategy:
102102
matrix:
103103
environment: ${{ fromJSON(needs.detect-new-envs.outputs.new_envs_json) }}
104-
env:
105-
HF_TOKEN: ${{ secrets.HF_PR_TOKEN }}
106-
HF_PR_TOKEN: ${{ secrets.HF_PR_TOKEN }}
107-
HF_NAMESPACE: ${{ vars.HF_PR_NAMESPACE }}
108-
SPACE_SUFFIX: -pr-${{ github.event.number }}
109104
steps:
110105
- name: Checkout PR code
111106
uses: actions/checkout@v4
@@ -115,19 +110,6 @@ jobs:
115110
fetch-depth: 0
116111
persist-credentials: false
117112

118-
- name: Default Hugging Face namespace
119-
if: env.HF_NAMESPACE == ''
120-
shell: bash
121-
run: echo "HF_NAMESPACE=openenv-testing" >> "$GITHUB_ENV"
122-
123-
- name: Verify Hugging Face token
124-
shell: bash
125-
run: |
126-
if [ -z "${HF_TOKEN:-}" ]; then
127-
echo "HF_TOKEN secret is required for deployment." >&2
128-
exit 1
129-
fi
130-
131113
- name: Set up Python
132114
uses: actions/setup-python@v5
133115
with:
@@ -140,117 +122,71 @@ jobs:
140122
python -m pip install --upgrade pip
141123
pip install .
142124
143-
- name: Deploy environment with OpenEnv CLI
125+
- name: Run openenv validate --verbose
126+
id: validate
144127
shell: bash
145128
run: |
146-
set -euo pipefail
147-
repo_id="${HF_NAMESPACE}/${{ matrix.environment }}${SPACE_SUFFIX}"
129+
set -u -o pipefail
148130
env_dir="src/envs/${{ matrix.environment }}"
149131
150132
if [ ! -d "$env_dir" ]; then
151133
echo "Environment directory not found: $env_dir" >&2
134+
echo "status=failure" >> "$GITHUB_OUTPUT"
135+
printf "details<<EOF\n%s\nEOF\n" "Environment directory not found" >> "$GITHUB_OUTPUT"
152136
exit 1
153137
fi
154138
155-
openenv push --directory "$env_dir" --repo-id "$repo_id"
156-
157-
- name: Wait for deployment to stabilize
158-
shell: bash
159-
run: sleep 180
160-
161-
- name: Compute Space URLs
162-
id: urls
163-
shell: bash
164-
run: |
165-
set -euo pipefail
139+
cd "$env_dir"
140+
echo "Running openenv validate --verbose in $(pwd)"
166141
167-
if [ -z "${HF_NAMESPACE:-}" ]; then
168-
echo "HF_NAMESPACE is not configured; unable to compute space URLs." >&2
169-
exit 1
142+
output_file="$(mktemp)"
143+
if openenv validate --verbose | tee "$output_file"; then
144+
status="success"
145+
exit_code=0
146+
else
147+
status="failure"
148+
exit_code=$?
170149
fi
171150
172-
namespace_slug=$(echo "${HF_NAMESPACE}" | tr '[:upper:]' '[:lower:]' | tr '_' '-')
173-
space_name="${{ matrix.environment }}${SPACE_SUFFIX}"
174-
space_slug=$(echo "${space_name}" | tr '[:upper:]' '[:lower:]' | tr '_' '-')
175-
health_url="https://${namespace_slug}-${space_slug}.hf.space/health"
176-
live_url="https://${namespace_slug}-${space_slug}.hf.space"
177-
space_repo_url="https://huggingface.co/spaces/${HF_NAMESPACE}/${space_name}"
178-
space_repo_id="${HF_NAMESPACE}/${space_name}"
179-
180-
echo "namespace_slug=${namespace_slug}" >> "$GITHUB_OUTPUT"
181-
echo "space_name=${space_name}" >> "$GITHUB_OUTPUT"
182-
echo "space_slug=${space_slug}" >> "$GITHUB_OUTPUT"
183-
echo "health_url=${health_url}" >> "$GITHUB_OUTPUT"
184-
echo "live_url=${live_url}" >> "$GITHUB_OUTPUT"
185-
echo "space_repo_url=${space_repo_url}" >> "$GITHUB_OUTPUT"
186-
echo "space_repo_id=${space_repo_id}" >> "$GITHUB_OUTPUT"
187-
188-
- name: Perform environment health check
189-
id: health_check
190-
continue-on-error: true
191-
shell: bash
192-
env:
193-
HEALTH_URL: ${{ steps.urls.outputs.health_url }}
194-
SPACE_NAME: ${{ steps.urls.outputs.space_name }}
195-
run: |
196-
set -euo pipefail
151+
log_contents="$(cat "$output_file")"
152+
rm -f "$output_file"
197153
198-
if [ -z "${HEALTH_URL:-}" ]; then
199-
echo "HEALTH_URL not provided; cannot perform health check." >&2
200-
exit 1
201-
fi
154+
echo "status=${status}" >> "$GITHUB_OUTPUT"
155+
printf "details<<EOF\n%s\nEOF\n" "$log_contents" >> "$GITHUB_OUTPUT"
202156
203-
echo "Checking health for ${SPACE_NAME} at ${HEALTH_URL}"
204-
205-
success=0
206-
for attempt in {1..5}; do
207-
status=$(curl -sS -o response.json -w "%{http_code}" "$HEALTH_URL" || echo "000")
208-
if [ "$status" = "200" ]; then
209-
echo "Health check passed for ${SPACE_NAME}"
210-
cat response.json
211-
success=1
212-
break
213-
fi
214-
echo "Attempt ${attempt} returned status ${status}. Retrying in 30 seconds..."
215-
sleep 30
216-
done
217-
218-
if [ $success -ne 1 ]; then
219-
echo "Health check failed for ${SPACE_NAME}" >&2
220-
if [ -f response.json ]; then
221-
echo "Last response payload:"
222-
cat response.json
223-
fi
224-
exit 1
225-
fi
157+
exit "$exit_code"
226158
227159
- name: Comment on PR with deployment status
228160
if: always()
229161
uses: actions/github-script@v7
230162
env:
231-
HEALTH_CONCLUSION: ${{ steps.health_check.conclusion }}
232-
SPACE_NAME: ${{ steps.urls.outputs.space_name }}
233-
LIVE_URL: ${{ steps.urls.outputs.live_url }}
234-
SPACE_REPO_URL: ${{ steps.urls.outputs.space_repo_url }}
235-
SPACE_REPO_ID: ${{ steps.urls.outputs.space_repo_id }}
163+
VALIDATION_STATUS: ${{ steps.validate.outputs.status }}
164+
VALIDATION_LOG: ${{ steps.validate.outputs.details }}
236165
ENV_NAME: ${{ matrix.environment }}
237166
COMMENT_TAG: "<!-- openenv-pr-preview -->"
238167
with:
239168
github-token: ${{ secrets.GITHUB_TOKEN }}
240169
script: |
241-
const status = process.env.HEALTH_CONCLUSION || 'failure';
170+
const status = (process.env.VALIDATION_STATUS || '').toLowerCase() === 'success' ? 'success' : 'failure';
242171
const envName = process.env.ENV_NAME;
243172
const marker = process.env.COMMENT_TAG;
244173
245174
const header = status === 'success'
246-
? `✅ Deployment to Hugging Face succeeded for \`${envName}\``
247-
: `⚠️ Deployment Hugging Face failed for \`${envName}\``;
175+
? `✅ Validation succeeded for \`${envName}\``
176+
: `⚠️ Validation failed for \`${envName}\``;
248177
249178
const summary = status === 'success'
250-
? 'Nice work! Wait for a code review and we\'re ready to go. You can test it with the CLI:'
251-
: 'Please resolve your environment and test it with the CLI:';
179+
? 'Nice work! Validation passed. Re-run locally with:'
180+
: 'Validation reported issues. Review the log and re-run locally:';
252181
253182
const envDir = 'src/envs/' + envName;
183+
const rawLog = process.env.VALIDATION_LOG || '';
184+
const trimmedLog = rawLog.trim();
185+
const maxLength = 6000;
186+
let displayLog = trimmedLog;
187+
if (displayLog.length > maxLength) {
188+
displayLog = displayLog.slice(0, maxLength) + '\n... (truncated)';
189+
}
254190
255191
const bodyLines = [
256192
marker,
@@ -260,7 +196,9 @@ jobs:
260196
'',
261197
summary,
262198
'',
263-
'- `openenv push --directory ' + envDir + ' --repo-id <your-username>/' + envName + '`',
199+
'- `openenv validate --verbose ' + envDir + '`',
200+
'',
201+
'```\n' + displayLog + '\n```',
264202
];
265203
266204
const {owner, repo} = context.repo;
@@ -304,37 +242,3 @@ jobs:
304242
body: bodyText,
305243
});
306244
}
307-
308-
- name: Delete preview space on Hugging Face
309-
if: always()
310-
continue-on-error: true
311-
shell: bash
312-
env:
313-
SPACE_REPO_ID: ${{ steps.urls.outputs.space_repo_id }}
314-
run: |
315-
set -euo pipefail
316-
if [ -z "${SPACE_REPO_ID:-}" ]; then
317-
echo "No space repo id; skipping deletion"
318-
exit 0
319-
fi
320-
321-
TOKEN="${HF_TOKEN:-${HF_PR_TOKEN:-}}"
322-
if [ -z "$TOKEN" ]; then
323-
echo "HF token not available; cannot delete space"
324-
exit 0
325-
fi
326-
327-
set +e
328-
hf repo delete "$SPACE_REPO_ID" --repo-type space --yes --token "$TOKEN"
329-
status=$?
330-
set -e
331-
332-
if [ $status -eq 0 ]; then
333-
echo "Deleted preview space $SPACE_REPO_ID"
334-
else
335-
echo "Failed to delete space $SPACE_REPO_ID (exit $status)"
336-
fi
337-
338-
- name: Fail job if health check failed
339-
if: steps.health_check.conclusion == 'failure'
340-
run: exit 1

0 commit comments

Comments
 (0)