Deploy HF Environments workflow (huggingface/OpenEnv)
The Deploy HF Environments workflow from huggingface/OpenEnv, explained and optimized by Latchkey.
CI health: C - fair
Point runs-on at Latchkey and get caching, job timeouts, self-healing for flaky steps, and up to 58% lower cost, applied automatically.
What it does
This is the Deploy HF Environments workflow from the huggingface/OpenEnv repository, a real project running GitHub Actions. It is shown here with attribution under its BSD-3-Clause license.
Below, Latchkey shows a faster, safer version produced by its optimization engine.
The workflow
name: Deploy HF Environments
on:
workflow_dispatch:
inputs:
envs_csv:
description: "Comma-separated env names (empty means all deployable envs)"
required: false
type: string
default: ""
openenv_version:
description: "Release version used for suffix and pinning (e.g. 0.2.1)"
required: false
type: string
default: "0.2.0"
hf_namespace:
description: "Hugging Face namespace"
required: false
type: string
default: "openenv"
private:
description: "Deploy version-suffixed spaces as private"
required: false
type: boolean
default: true
skip_collection:
description: "Skip collection updates"
required: false
type: boolean
default: false
dry_run:
description: "Run staging-only dry run"
required: false
type: boolean
default: false
collection_namespace:
description: "Collection owner namespace"
required: false
type: string
default: "openenv"
jobs:
deploy:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v7
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.12"
- name: Install Hugging Face CLI
run: |
curl -LsSf https://hf.co/cli/install.sh | bash
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
- name: Install collection manager dependency
run: |
python -m pip install --upgrade pip
pip install "huggingface-hub>=0.24.0"
- name: Deploy selected environments
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
ENVS_CSV_INPUT: ${{ github.event.inputs.envs_csv }}
run: |
set -euo pipefail
chmod +x scripts/prepare_hf_deployment.sh
cmd=(scripts/prepare_hf_deployment.sh
--hf-namespace "${{ github.event.inputs.hf_namespace }}"
--openenv-version "${{ github.event.inputs.openenv_version }}"
--collection-namespace "${{ github.event.inputs.collection_namespace }}"
)
if [ "${{ github.event.inputs.private }}" = "true" ]; then
cmd+=(--private)
else
cmd+=(--public)
fi
if [ "${{ github.event.inputs.skip_collection }}" = "true" ]; then
cmd+=(--skip-collection)
fi
if [ "${{ github.event.inputs.dry_run }}" = "true" ]; then
cmd+=(--dry-run)
fi
if [ -n "$ENVS_CSV_INPUT" ]; then
IFS=',' read -r -a envs <<< "$ENVS_CSV_INPUT"
for env_name in "${envs[@]}"; do
trimmed="$(echo "$env_name" | xargs)"
if [ -n "$trimmed" ]; then
cmd+=(--env "$trimmed")
fi
done
else
cmd+=(--all)
fi
echo "Running: ${cmd[*]}"
"${cmd[@]}"
The same workflow, on Latchkey
Estimated ~20% faster on cache hits, plus fewer wasted runs and a safer supply chain. Added and changed lines are highlighted.
name: Deploy HF Environments on: workflow_dispatch: inputs: envs_csv: description: "Comma-separated env names (empty means all deployable envs)" required: false type: string default: "" openenv_version: description: "Release version used for suffix and pinning (e.g. 0.2.1)" required: false type: string default: "0.2.0" hf_namespace: description: "Hugging Face namespace" required: false type: string default: "openenv" private: description: "Deploy version-suffixed spaces as private" required: false type: boolean default: true skip_collection: description: "Skip collection updates" required: false type: boolean default: false dry_run: description: "Run staging-only dry run" required: false type: boolean default: false collection_namespace: description: "Collection owner namespace" required: false type: string default: "openenv" jobs: deploy: timeout-minutes: 30 runs-on: latchkey-small permissions: contents: read steps: - name: Checkout repository uses: actions/checkout@v7 - name: Set up Python uses: actions/setup-python@v6 with: cache: 'pip' python-version: "3.12" - name: Install Hugging Face CLI run: | curl -LsSf https://hf.co/cli/install.sh | bash echo "$HOME/.local/bin" >> "$GITHUB_PATH" - name: Install collection manager dependency run: | python -m pip install --upgrade pip pip install "huggingface-hub>=0.24.0" - name: Deploy selected environments env: HF_TOKEN: ${{ secrets.HF_TOKEN }} ENVS_CSV_INPUT: ${{ github.event.inputs.envs_csv }} run: | set -euo pipefail chmod +x scripts/prepare_hf_deployment.sh cmd=(scripts/prepare_hf_deployment.sh --hf-namespace "${{ github.event.inputs.hf_namespace }}" --openenv-version "${{ github.event.inputs.openenv_version }}" --collection-namespace "${{ github.event.inputs.collection_namespace }}" ) if [ "${{ github.event.inputs.private }}" = "true" ]; then cmd+=(--private) else cmd+=(--public) fi if [ "${{ github.event.inputs.skip_collection }}" = "true" ]; then cmd+=(--skip-collection) fi if [ "${{ github.event.inputs.dry_run }}" = "true" ]; then cmd+=(--dry-run) fi if [ -n "$ENVS_CSV_INPUT" ]; then IFS=',' read -r -a envs <<< "$ENVS_CSV_INPUT" for env_name in "${envs[@]}"; do trimmed="$(echo "$env_name" | xargs)" if [ -n "$trimmed" ]; then cmd+=(--env "$trimmed") fi done else cmd+=(--all) fi echo "Running: ${cmd[*]}" "${cmd[@]}"
What changed
- Run on Latchkey managed runners with one line (
runs-on), which apply the fixes below automatically and self-heal transient failures. This example useslatchkey-small; pick the runner size that fits the job. - Cache dependency installs on the setup step so they are served from cache.
- Add a job timeout so a hung step cannot burn hours of runner time.
What Latchkey heals here
This workflow has steps that commonly fail on transient issues (network, registries, flaky browsers). On Latchkey managed runners they are detected, retried, and self-healed instead of failing your build:
- Dependency installs
- Network fetches
This workflow runs 1 job per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.