Retry Hugging Face deploy on transient errors #2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy HF Space | |
| on: | |
| push: | |
| branches: ["main"] | |
| workflow_dispatch: | |
| inputs: | |
| repo_id: | |
| description: "Hugging Face repo id (username/space-name). Leave blank to use repo variable HF_SPACE_REPO_ID." | |
| required: false | |
| type: string | |
| private: | |
| description: "Create or update the target Space as private" | |
| required: false | |
| default: false | |
| type: boolean | |
| create_pr: | |
| description: "Upload via Pull Request instead of direct push" | |
| required: false | |
| default: false | |
| type: boolean | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 30 | |
| env: | |
| HF_TOKEN: ${{ secrets.HF_TOKEN }} | |
| HF_SPACE_REPO_ID: ${{ inputs.repo_id || vars.HF_SPACE_REPO_ID || 'Rohan556/openenv-code-review-arena' }} | |
| steps: | |
| - uses: actions/checkout@v6.0.2 | |
| - uses: actions/setup-python@v6.2.0 | |
| with: | |
| python-version: "3.11" | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v8.0.0 | |
| - name: Check deployment configuration | |
| id: config | |
| run: | | |
| if [ -z "${HF_TOKEN}" ]; then | |
| echo "deploy_enabled=false" >> "$GITHUB_OUTPUT" | |
| echo "HF_TOKEN is not configured; skipping deploy." | |
| exit 0 | |
| fi | |
| if [ -z "${HF_SPACE_REPO_ID}" ]; then | |
| echo "::error::Missing workflow input repo_id and repository variable HF_SPACE_REPO_ID" | |
| exit 1 | |
| fi | |
| echo "deploy_enabled=true" >> "$GITHUB_OUTPUT" | |
| echo "Deploying to ${HF_SPACE_REPO_ID}" | |
| - name: Validate local environment structure | |
| if: steps.config.outputs.deploy_enabled == 'true' | |
| run: uvx --from git+https://github.com/meta-pytorch/OpenEnv.git openenv validate --verbose | |
| - name: Push to Hugging Face Space | |
| if: steps.config.outputs.deploy_enabled == 'true' | |
| run: | | |
| args=(. --repo-id "${HF_SPACE_REPO_ID}") | |
| if [ "${{ inputs.private }}" = "true" ]; then | |
| args+=(--private) | |
| fi | |
| if [ "${{ inputs.create_pr }}" = "true" ]; then | |
| args+=(--create-pr) | |
| fi | |
| for attempt in 1 2 3; do | |
| echo "Hugging Face push attempt ${attempt}/3" | |
| if uvx --from git+https://github.com/meta-pytorch/OpenEnv.git openenv push "${args[@]}"; then | |
| exit 0 | |
| fi | |
| if [ "${attempt}" -lt 3 ]; then | |
| echo "Push failed, retrying after backoff..." | |
| sleep $((attempt * 20)) | |
| fi | |
| done | |
| echo "::error::Failed to push to Hugging Face Space after 3 attempts" | |
| exit 1 |