Skip to content

Commit aa740d4

Browse files
committed
ci(pricing): land pricing updates on main instead of opening PRs
The hourly pricing refresh opened a PR with github.token, which cannot trigger ci.yaml, so the PR arrived with no checks and nothing merged it. Pricing data was therefore only as fresh as the last time someone merged that PR by hand, even though the workflow already accepts a workflow_dispatch. Both jobs now run the checks that a pull request would have run - flake check, Rust tests and the Node tests, in a parallel step - and push the result straight to main. `just gen-models-dev-pricing` already runs before validation, so the committed snapshots never lag the locked revision. The commit and rebase-onto-main dance is shared by both jobs, so it lives in a composite action. A concurrency group keeps a manual dispatch from racing the hourly run's push.
1 parent 1dab5c2 commit aa740d4

2 files changed

Lines changed: 110 additions & 72 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Commit and push to main
2+
description: >
3+
Commit the given paths as github-actions[bot] and push them to main, rebasing
4+
onto whatever main has become while the caller was validating. Callers must
5+
check out with fetch-depth: 0, because a shallow clone has no merge base to
6+
rebase onto, and must only run this when the paths actually changed.
7+
inputs:
8+
message:
9+
description: Commit message
10+
required: true
11+
paths:
12+
description: Whitespace-separated list of paths to commit
13+
required: true
14+
runs:
15+
using: composite
16+
steps:
17+
- name: Commit and push to main
18+
shell: bash
19+
env:
20+
GH_TOKEN: ${{ github.token }}
21+
MESSAGE: ${{ inputs.message }}
22+
PATHS: ${{ inputs.paths }}
23+
run: |
24+
git config user.name "github-actions[bot]"
25+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
26+
gh auth setup-git
27+
28+
# PATHS is word-split on purpose: it carries a list of paths.
29+
# shellcheck disable=SC2086
30+
git commit --message "$MESSAGE" -- $PATHS
31+
32+
git fetch origin main
33+
if ! git rebase origin/main; then
34+
git rebase --abort
35+
echo 'main moved with a conflicting change; the next run will retry.'
36+
exit 1
37+
fi
38+
git push origin HEAD:main

‎.github/workflows/update-pricing.yaml‎

Lines changed: 72 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,22 @@ on:
77

88
permissions: {}
99

10+
# Both jobs push to main, so a manual dispatch landing on top of the hourly
11+
# schedule would otherwise race the other run's push.
12+
concurrency:
13+
group: update-pricing
14+
cancel-in-progress: false
15+
1016
jobs:
1117
update-pricing:
1218
runs-on: blacksmith-32vcpu-ubuntu-2404
19+
timeout-minutes: 60
1320
permissions:
1421
contents: write
15-
pull-requests: write
1622
steps:
1723
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
1824
with:
25+
fetch-depth: 0
1926
persist-credentials: false
2027
- uses: ./.github/actions/setup-nix-cache
2128
- name: Capture current LiteLLM pricing JSON
@@ -28,64 +35,61 @@ jobs:
2835
run: |
2936
nix flake update litellm
3037
- name: Skip lock-only LiteLLM updates
38+
id: litellm
3139
run: |
3240
rev="$(jq -r '.nodes.litellm.locked.rev' flake.lock)"
3341
curl --fail --location --silent --show-error \
3442
"https://raw.githubusercontent.com/BerriAI/litellm/${rev}/model_prices_and_context_window.json" \
3543
--output /tmp/litellm-pricing-after.json
3644
3745
if cmp --silent /tmp/litellm-pricing-before.json /tmp/litellm-pricing-after.json; then
38-
echo "LiteLLM pricing JSON is unchanged; skipping PR."
46+
echo "LiteLLM pricing JSON is unchanged; skipping the update."
3947
git checkout -- flake.lock
4048
fi
41-
- name: Validate updated pricing snapshot
42-
run: |
43-
if git diff --quiet; then
44-
echo "Pricing snapshot is already up to date."
45-
exit 0
46-
fi
47-
nix develop --command just check
48-
- name: Create pull request
49-
env:
50-
GH_TOKEN: ${{ github.token }}
51-
run: |
52-
if git diff --quiet; then
53-
echo "Pricing snapshot is already up to date."
54-
exit 0
55-
fi
56-
57-
git config user.name "github-actions[bot]"
58-
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
59-
gh auth setup-git
60-
61-
branch="automation/litellm-pricing"
62-
git checkout -B "$branch"
63-
git add flake.lock
64-
git commit -m "chore(pricing): update LiteLLM snapshot"
65-
git push --force origin "$branch"
6649
67-
body="$(printf '%s\n' \
68-
'Updates the locked LiteLLM pricing input used by Nix builds.' \
69-
'' \
70-
'Validation:' \
71-
'- just check')"
72-
73-
if gh pr view "$branch" >/dev/null 2>&1; then
74-
printf '%s\n' "$body" | gh pr edit "$branch" --title "chore(pricing): update LiteLLM snapshot" --body-file -
50+
if git diff --quiet; then
51+
echo 'Pricing snapshot is already up to date.'
52+
echo 'changed=false' >> "$GITHUB_OUTPUT"
7553
else
76-
printf '%s\n' "$body" | gh pr create --base main --head "$branch" --title "chore(pricing): update LiteLLM snapshot" --body-file -
54+
echo 'changed=true' >> "$GITHUB_OUTPUT"
7755
fi
56+
# The push below cannot trigger ci.yaml, so the checks that would have run
57+
# on a pull request run here instead. Each leg no-ops when the snapshot was
58+
# already up to date.
59+
- parallel:
60+
- name: Run nix flake check
61+
run: |
62+
git diff --quiet && exit 0
63+
nix flake check --print-build-logs
64+
- name: Run Rust tests
65+
run: |
66+
git diff --quiet && exit 0
67+
nix build .#ccusage-tests --no-link --print-build-logs
68+
- name: JS test
69+
run: |
70+
git diff --quiet && exit 0
71+
nix profile install --inputs-from . nixpkgs#pnpm nixpkgs#nodejs nixpkgs#just
72+
pnpm install --frozen-lockfile
73+
mkdir -p "$HOME/.claude/projects"
74+
mkdir -p "$HOME/.config/claude/projects"
75+
just test-node
76+
- uses: ./.github/actions/commit-and-push-main
77+
if: steps.litellm.outputs.changed == 'true'
78+
with:
79+
message: 'chore(pricing): update LiteLLM snapshot'
80+
paths: flake.lock
7881

7982
update-models-dev-pricing:
8083
needs: update-pricing
8184
if: ${{ always() }}
8285
runs-on: blacksmith-32vcpu-ubuntu-2404
86+
timeout-minutes: 60
8387
permissions:
8488
contents: write
85-
pull-requests: write
8689
steps:
8790
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
8891
with:
92+
fetch-depth: 0
8993
persist-credentials: false
9094
- uses: ./.github/actions/setup-nix-cache
9195
- name: Update models.dev input
@@ -95,47 +99,43 @@ jobs:
9599
run: |
96100
nix develop --command just gen-models-dev-pricing
97101
- name: Skip lock-only models.dev updates
102+
id: models-dev
98103
run: |
99104
# Only the compacted snapshot affects the build; if a models.dev bump
100105
# leaves embedded pricing unchanged, drop the lock-only churn.
101106
if git diff --quiet -- rust/crates/ccusage-core/src/models-dev-pricing.json rust/crates/ccusage-adapter-codex/src/codex-auto-review-fallbacks.json; then
102-
echo "models.dev pricing snapshots are unchanged; skipping PR."
107+
echo "models.dev pricing snapshots are unchanged; skipping the update."
103108
git checkout -- flake.lock rust/crates/ccusage-core/src/models-dev-pricing.json rust/crates/ccusage-adapter-codex/src/codex-auto-review-fallbacks.json
104109
fi
105-
- name: Validate updated pricing snapshot
106-
run: |
107-
if git diff --quiet; then
108-
echo "Pricing snapshot is already up to date."
109-
exit 0
110-
fi
111-
nix develop --command just check
112-
- name: Create pull request
113-
env:
114-
GH_TOKEN: ${{ github.token }}
115-
run: |
116-
if git diff --quiet; then
117-
echo "Pricing snapshot is already up to date."
118-
exit 0
119-
fi
120110
121-
git config user.name "github-actions[bot]"
122-
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
123-
gh auth setup-git
124-
125-
branch="automation/models-dev-pricing"
126-
git checkout -B "$branch"
127-
git add flake.lock rust/crates/ccusage-core/src/models-dev-pricing.json rust/crates/ccusage-adapter-codex/src/codex-auto-review-fallbacks.json
128-
git commit -m "chore(pricing): update models.dev snapshot"
129-
git push --force origin "$branch"
130-
131-
body="$(printf '%s\n' \
132-
'Updates the pinned models.dev input and its committed pricing snapshot.' \
133-
'' \
134-
'Validation:' \
135-
'- just check')"
136-
137-
if gh pr view "$branch" >/dev/null 2>&1; then
138-
printf '%s\n' "$body" | gh pr edit "$branch" --title "chore(pricing): update models.dev snapshot" --body-file -
111+
if git diff --quiet; then
112+
echo 'Pricing snapshot is already up to date.'
113+
echo 'changed=false' >> "$GITHUB_OUTPUT"
139114
else
140-
printf '%s\n' "$body" | gh pr create --base main --head "$branch" --title "chore(pricing): update models.dev snapshot" --body-file -
115+
echo 'changed=true' >> "$GITHUB_OUTPUT"
141116
fi
117+
- parallel:
118+
- name: Run nix flake check
119+
run: |
120+
git diff --quiet && exit 0
121+
nix flake check --print-build-logs
122+
- name: Run Rust tests
123+
run: |
124+
git diff --quiet && exit 0
125+
nix build .#ccusage-tests --no-link --print-build-logs
126+
- name: JS test
127+
run: |
128+
git diff --quiet && exit 0
129+
nix profile install --inputs-from . nixpkgs#pnpm nixpkgs#nodejs nixpkgs#just
130+
pnpm install --frozen-lockfile
131+
mkdir -p "$HOME/.claude/projects"
132+
mkdir -p "$HOME/.config/claude/projects"
133+
just test-node
134+
- uses: ./.github/actions/commit-and-push-main
135+
if: steps.models-dev.outputs.changed == 'true'
136+
with:
137+
message: 'chore(pricing): update models.dev snapshot'
138+
paths: >-
139+
flake.lock
140+
rust/crates/ccusage-core/src/models-dev-pricing.json
141+
rust/crates/ccusage-adapter-codex/src/codex-auto-review-fallbacks.json

0 commit comments

Comments
 (0)