Skip to content

Commit 6e636be

Browse files
committed
ci: add daily model sync workflow
1 parent 0be4eee commit 6e636be

File tree

1 file changed

+116
-0
lines changed

1 file changed

+116
-0
lines changed

.github/workflows/sync-models.yml

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
name: Sync Model Metadata
2+
3+
on:
4+
schedule:
5+
- cron: '0 6 * * *'
6+
workflow_dispatch:
7+
8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.ref }}
10+
cancel-in-progress: true
11+
12+
permissions:
13+
contents: write
14+
pull-requests: write
15+
16+
jobs:
17+
sync:
18+
name: Sync Models
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v6.0.2
23+
with:
24+
fetch-depth: 0
25+
26+
- name: Setup Tools
27+
uses: TanStack/config/.github/setup@main
28+
29+
- name: Fetch and sync model metadata
30+
run: pnpm generate:models:sync
31+
32+
- name: Check for changes
33+
id: changes
34+
run: |
35+
if git diff --quiet; then
36+
echo "changed=false" >> $GITHUB_OUTPUT
37+
else
38+
echo "changed=true" >> $GITHUB_OUTPUT
39+
fi
40+
41+
- name: Detect affected packages and create changeset
42+
if: steps.changes.outputs.changed == 'true'
43+
run: |
44+
CHANGED_FILES=$(git diff --name-only)
45+
TIMESTAMP=$(date +%s)
46+
CHANGESET_FILE=".changeset/sync-models-${TIMESTAMP}.md"
47+
48+
PACKAGES=""
49+
if echo "$CHANGED_FILES" | grep -q "packages/typescript/ai-openai/"; then
50+
PACKAGES="${PACKAGES}'@tanstack/ai-openai': patch
51+
"
52+
fi
53+
if echo "$CHANGED_FILES" | grep -q "packages/typescript/ai-anthropic/"; then
54+
PACKAGES="${PACKAGES}'@tanstack/ai-anthropic': patch
55+
"
56+
fi
57+
if echo "$CHANGED_FILES" | grep -q "packages/typescript/ai-gemini/"; then
58+
PACKAGES="${PACKAGES}'@tanstack/ai-gemini': patch
59+
"
60+
fi
61+
if echo "$CHANGED_FILES" | grep -q "packages/typescript/ai-grok/"; then
62+
PACKAGES="${PACKAGES}'@tanstack/ai-grok': patch
63+
"
64+
fi
65+
if echo "$CHANGED_FILES" | grep -q "packages/typescript/ai-openrouter/"; then
66+
PACKAGES="${PACKAGES}'@tanstack/ai-openrouter': patch
67+
"
68+
fi
69+
70+
if [ -n "$PACKAGES" ]; then
71+
printf '%s' "---
72+
${PACKAGES}---
73+
74+
Update model metadata from OpenRouter API
75+
" > "$CHANGESET_FILE"
76+
fi
77+
78+
- name: Commit and force-push
79+
if: steps.changes.outputs.changed == 'true'
80+
run: |
81+
git config user.name "github-actions[bot]"
82+
git config user.email "github-actions[bot]@users.noreply.github.com"
83+
git add packages/ .changeset/
84+
git commit -m "chore: sync model metadata from OpenRouter"
85+
git push --force origin HEAD:automated/sync-models
86+
env:
87+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
88+
89+
- name: Create or update PR
90+
if: steps.changes.outputs.changed == 'true'
91+
run: |
92+
BRANCH="automated/sync-models"
93+
EXISTING_PR=$(gh pr list --head "$BRANCH" --base main --json number --jq '.[0].number' 2>/dev/null || true)
94+
95+
if [ -z "$EXISTING_PR" ] || [ "$EXISTING_PR" = "null" ]; then
96+
gh pr create \
97+
--title "chore: sync model metadata from OpenRouter" \
98+
--body "## Summary
99+
100+
This automated PR syncs model metadata from the OpenRouter API daily.
101+
102+
- Fetches the latest model list from OpenRouter
103+
- Converts to the internal adapter format
104+
- Syncs provider-specific model metadata for affected packages
105+
- Creates a patch changeset for all changed packages
106+
107+
## Review Checklist
108+
109+
- [ ] Verify model additions/removals look correct
110+
- [ ] Check that no unexpected packages were changed
111+
- [ ] Confirm changeset bump type is appropriate (patch)" \
112+
--base main \
113+
--head "$BRANCH"
114+
fi
115+
env:
116+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)