From ca37e169ca58b17929190a68fe7a82254ae6265b Mon Sep 17 00:00:00 2001 From: cobra91 Date: Mon, 23 Nov 2026 18:53:03 +0100 Subject: [PATCH] ci(pricing): refuse to publish when bundled prices are behind LiteLLM Bundled prices override LiteLLM at runtime, so a bundle that is behind LiteLLM publishes wrong costs. scripts/sync-pricing.ts existed since April but nothing ran it, and 30 bundled prices were stale when this was written. - release.yaml runs 'pnpm sync-pricing --check' in publish-core before publishing. The release fails when a bundled price differs from LiteLLM or a bundle copy differs from the canonical file. Missing LiteLLM data only warns, so a network problem cannot block a release on its own; a tooling failure does fail. - pricing-check.yaml and .github/actions/pricing-check run the same check on pull requests touching pricing files and on demand, so it is exercised before it first matters at release time. The sync itself stays a reviewed commit (#61), so the published package still matches its tag. --- .github/actions/pricing-check/action.yml | 39 ++++++++++++++++++++++++ .github/workflows/pricing-check.yaml | 30 ++++++++++++++++++ .github/workflows/release.yaml | 6 ++++ 3 files changed, 75 insertions(+) create mode 100644 .github/actions/pricing-check/action.yml create mode 100644 .github/workflows/pricing-check.yaml diff --git a/.github/actions/pricing-check/action.yml b/.github/actions/pricing-check/action.yml new file mode 100644 index 0000000..a820e0b --- /dev/null +++ b/.github/actions/pricing-check/action.yml @@ -0,0 +1,39 @@ +name: Pricing freshness check +description: >- + Fails when a price bundled in model_prices_and_context_window.json is behind + LiteLLM, or when a bundle copy differs from the canonical file. Requires pnpm + dependencies to be installed and Bun to be available. Missing LiteLLM data + only warns, so an unreachable host cannot block a release by itself. +runs: + using: composite + steps: + - name: Check bundled prices against LiteLLM + shell: bash + run: | + log="$RUNNER_TEMP/pricing-check.log" + code=0 + pnpm sync-pricing --check > "$log" 2>&1 || code=$? + cat "$log" + case "$code" in + 0) verdict="Bundled prices are up to date with LiteLLM." ;; + 1) verdict="Pricing check failed: bundled prices are behind LiteLLM, or a bundle copy differs from the canonical file. Details below." ;; + 2) verdict="LiteLLM data was not usable, bundled prices were not verified." ;; + *) verdict="The pricing check did not run (exit code $code). This is a tooling failure, not a pricing result." ;; + esac + { + echo "### Pricing freshness" + echo + echo "$verdict" + echo + echo '```' + grep '^\[sync-pricing\]' "$log" || true + echo '```' + } >> "$GITHUB_STEP_SUMMARY" + if [ "$code" -eq 2 ]; then + echo "::warning::$verdict" + exit 0 + fi + if [ "$code" -ne 0 ]; then + echo "::error::$verdict" + exit 1 + fi diff --git a/.github/workflows/pricing-check.yaml b/.github/workflows/pricing-check.yaml new file mode 100644 index 0000000..c5bfddd --- /dev/null +++ b/.github/workflows/pricing-check.yaml @@ -0,0 +1,30 @@ +name: pricing-check + +# Runs the same check the release workflow applies before publishing, so it +# can be exercised on pull requests and on demand instead of first at release +# time. A pull request that syncs the bundle should show this check green. +on: + workflow_dispatch: + pull_request: + paths: + - ".github/actions/pricing-check/**" + - ".github/workflows/pricing-check.yaml" + - ".github/workflows/release.yaml" + - "packages/internal/model_prices_and_context_window.json" + - "packages/internal/src/pricing.ts" + - "packages/internal/src/pricing-fetch-utils.ts" + - "packages/internal/src/remote-pricing.ts" + - "scripts/sync-pricing.ts" + +jobs: + pricing-check: + runs-on: ubuntu-latest + timeout-minutes: 5 + permissions: + contents: read + steps: + - uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5.0.1 + - uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.0 + - uses: oven-sh/setup-bun@v2 + - run: pnpm install --no-frozen-lockfile + - uses: ./.github/actions/pricing-check diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 2bd24d2..1f9e9fd 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -64,6 +64,12 @@ jobs: else echo "exists=false" >> "$GITHUB_OUTPUT" fi + # Bundled prices override LiteLLM at runtime, so a bundle that is behind + # LiteLLM would publish wrong costs. Same check as pricing-check.yaml; + # skipped when the version is already on npm (nothing left to publish). + - name: Refuse to publish stale bundled prices + if: steps.check-core.outputs.exists != 'true' + uses: ./.github/actions/pricing-check - name: Publish better-ccusage (core) if: steps.check-core.outputs.exists != 'true' run: |