mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-24 22:09:56 +00:00
69 lines
2.9 KiB
YAML
69 lines
2.9 KiB
YAML
name: Cost map guard
|
|
|
|
on:
|
|
pull_request:
|
|
branches:
|
|
- main
|
|
- "litellm_**"
|
|
|
|
permissions:
|
|
contents: 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: Fetch the pull request head, its merge base, and the base branch tip
|
|
id: revisions
|
|
env:
|
|
GH_TOKEN: ${{ github.token }}
|
|
BASE_REF: ${{ github.event.pull_request.base.ref }}
|
|
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
|
|
run: |
|
|
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"
|
|
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: |
|
|
uv run --no-project python ci_cd/cost_map_guard.py --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"
|