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: |