litellm/.github/actions/restore-rust-bridge/action.yml
Kerry Lu b0c734ff6e
ci: reuse Rust bridge builds across PR pushes and refresh the Cargo cache (#52718)
* Reuse PR Rust bridges and refresh main Cargo caches

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* Cache gateway prebuilts on pull requests

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-11-19 01:38:54 +00:00

58 lines
2.7 KiB
YAML

name: "Restore the Rust bridge"
description: >-
Restore the prebuilt Rust bridge keyed on the Rust build and packaging inputs.
The bridge is abi3, so one build serves every supported Python version. A job
whose Rust inputs match main installs the restored wheel and native library
instead of compiling them inside `uv sync`. On a miss the caller builds from
source as before.
The restored `rust-bridge-dist` directory holds the editable litellm wheel, the
optional litellm-proxy gateway wheel, and `litellm/rust_bridge/_native.abi3.so`.
inputs:
gateway:
description: "'true' to restore a bridge with the gateway wheel"
required: false
default: "false"
stale-cost-map:
description: >-
'true' to fall back to a bridge built from the same Rust inputs whose embedded
cost map is older, for a pull request that changes only the cost map
required: false
default: "false"
outputs:
key:
description: "Cache key for the bridge built from this checkout"
value: ${{ steps.key.outputs.key }}
cache-hit:
description: "'true' when the bridge for this exact key was restored"
value: ${{ steps.restore.outputs.cache-hit }}
restored:
description: "'true' when a bridge was restored, by exact key or by the stale cost map fallback"
value: ${{ steps.restore.outputs.cache-matched-key != '' }}
runs:
using: composite
steps:
- name: Define the Rust bridge cache key
id: key
shell: bash
env:
RUST_INPUTS: ${{ runner.os }}-rust-bridge-editable-v2-gateway-${{ inputs.gateway }}-${{ hashFiles('litellm/rust/Cargo.lock', 'litellm/rust/Cargo.toml', 'litellm/rust/rust-toolchain.toml', 'litellm/rust/.cargo/config.toml', 'litellm/rust/crates/*/Cargo.toml', 'litellm/rust/crates/*/src/**', 'litellm/rust/crates/*/build.rs', 'litellm/rust/crates/python-bridge/preflight_contract.json', 'litellm/rust/crates/python-compat/generated/nonprintable.rs', 'litellm/rust/crates/*/.sqlx/*.json', 'litellm/rust/crates/*/migrations/**', 'pyproject.toml', 'litellm/packaging/litellm-proxy/pyproject.toml', '.github/packaging/*.py', '!**/*.md', '!**/tests/**', '!**/benches/**') }}
COST_MAP: ${{ hashFiles('model_prices_and_context_window.json') }}
STALE_COST_MAP: ${{ inputs.stale-cost-map }}
run: |
echo "key=${RUST_INPUTS}-${COST_MAP}" >> "$GITHUB_OUTPUT"
if [ "${STALE_COST_MAP}" = true ]; then
echo "fallback=${RUST_INPUTS}-" >> "$GITHUB_OUTPUT"
fi
- name: Restore the Rust bridge
id: restore
uses: actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
path: rust-bridge-dist
key: ${{ steps.key.outputs.key }}
restore-keys: ${{ steps.key.outputs.fallback }}