mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-14 09:03:16 +00:00
81 lines
3.5 KiB
YAML
81 lines
3.5 KiB
YAML
name: Cost map guard
|
|
|
|
on:
|
|
pull_request:
|
|
branches:
|
|
- main
|
|
- "litellm_**"
|
|
|
|
permissions:
|
|
contents: read
|
|
pull-requests: read
|
|
|
|
concurrency:
|
|
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
|
|
cancel-in-progress: true
|
|
|
|
jobs:
|
|
cost-map-guard:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0
|
|
with:
|
|
ref: ${{ github.event.pull_request.base.sha }}
|
|
persist-credentials: false
|
|
- name: Check out the base branch tip and fetch the pull request head and its merge base
|
|
id: revisions
|
|
env:
|
|
GH_TOKEN: ${{ github.token }}
|
|
PR_NUMBER: ${{ github.event.pull_request.number }}
|
|
EVENT_BASE_REF: ${{ github.event.pull_request.base.ref }}
|
|
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
|
|
run: |
|
|
base_ref="$(gh api "repos/${GITHUB_REPOSITORY}/branches/${EVENT_BASE_REF}" --jq .name)" || base_ref="$(gh api "repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}" --jq .base.ref)"
|
|
target="$(gh api "repos/${GITHUB_REPOSITORY}/branches/${base_ref}" --jq '.commit.sha')"
|
|
merge_base="$(gh api "repos/${GITHUB_REPOSITORY}/compare/${target}...${HEAD_SHA}" --jq '.merge_base_commit.sha')"
|
|
git fetch --no-tags --depth=1 origin "$merge_base" "$HEAD_SHA" "$target"
|
|
git checkout -q --detach "$target"
|
|
echo "merge_base=$merge_base" >> "$GITHUB_OUTPUT"
|
|
echo "target=$target" >> "$GITHUB_OUTPUT"
|
|
- name: Set up uv
|
|
uses: ./.github/actions/setup-uv-with-retries
|
|
with:
|
|
version: "0.10.9"
|
|
- name: Run the guard
|
|
env:
|
|
MERGE_BASE: ${{ steps.revisions.outputs.merge_base }}
|
|
COST_MAP_GUARD_TARGET: ${{ steps.revisions.outputs.target }}
|
|
COST_MAP_GUARD_AUTHOR_TYPE: ${{ github.event.pull_request.user.type }}
|
|
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
|
|
HEAD_REF: ${{ github.event.pull_request.head.ref }}
|
|
run: |
|
|
guard=litellm/scripts/ci_cd/cost_map_guard.py
|
|
# TODO: Drop the legacy path after this lands on main.
|
|
if [ ! -f "$guard" ]; then
|
|
guard=scripts/ci_cd/cost_map_guard.py
|
|
fi
|
|
if [ ! -f "$guard" ]; then
|
|
guard=ci_cd/cost_map_guard.py
|
|
fi
|
|
uv run --no-project python "$guard" --base "$MERGE_BASE" --head "$HEAD_SHA" --head-ref "$HEAD_REF"
|
|
- name: Check whether the pull request changes the cost map
|
|
id: changed
|
|
env:
|
|
MERGE_BASE: ${{ steps.revisions.outputs.merge_base }}
|
|
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
|
|
run: |
|
|
if git diff --quiet "$MERGE_BASE" "$HEAD_SHA" -- model_prices_and_context_window.json; then
|
|
echo "cost_map=false" >> "$GITHUB_OUTPUT"
|
|
else
|
|
echo "cost_map=true" >> "$GITHUB_OUTPUT"
|
|
fi
|
|
- if: steps.changed.outputs.cost_map == 'true'
|
|
run: rustup toolchain install --no-self-update
|
|
- name: Load the cost map through model-catalog
|
|
if: steps.changed.outputs.cost_map == 'true'
|
|
env:
|
|
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
|
|
run: |
|
|
git show "${HEAD_SHA}:model_prices_and_context_window.json" > "$RUNNER_TEMP/model_prices_and_context_window.json"
|
|
cargo run --locked --quiet --manifest-path litellm/rust/Cargo.toml -p litellm-model-catalog --bin check-registry \
|
|
-- "$RUNNER_TEMP/model_prices_and_context_window.json"
|