Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

sync-models.yml

161 lines6.3 KB

1name: Sync Model Metadata
2​
3on:
4 schedule:
5 - cron: '0 6 * * *'
6 workflow_dispatch:
7​
8concurrency:
9 group: ${{ github.workflow }}-${{ github.ref }}
10 cancel-in-progress: true
11​
12permissions:
13 contents: write
14 pull-requests: write
15 issues: write # failure alert issue
16​
17jobs:
18 sync:
19 name: Sync Models
20 runs-on: ubuntu-latest
21 steps:
22 - name: Checkout
23 uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
24 with:
25 fetch-depth: 0
26 persist-credentials: true # sync job pushes generated model updates
27​
28 - name: Setup Tools
29 uses: TanStack/config/.github/setup@190f659075ff0845850e330883eb26d7ffd0671f # main
30​
31 # Each sync runs as its own step so one provider failing does not block
32 # the others. Whatever succeeded is still committed, then the job fails.
33 - name: Fetch gateway models
34 id: fetch
35 continue-on-error: true
36 run: pnpm generate:models:fetch
37​
38 - name: Convert gateway models
39 id: convert
40 continue-on-error: true
41 run: pnpm regenerate:models
42​
43 - name: Sync ElevenLabs models
44 id: elevenlabs
45 continue-on-error: true
46 run: pnpm generate:models:elevenlabs
47 env:
48 MODELSCHEMAS_API_KEY: ${{ secrets.MODELSCHEMAS_API_KEY }}
49​
50 - name: Sync provider models
51 id: provider
52 continue-on-error: true
53 run: pnpm exec tsx scripts/sync-provider-models.ts
54 env:
55 MODELSCHEMAS_API_KEY: ${{ secrets.MODELSCHEMAS_API_KEY }}
56​
57 - name: Sync model catalogs
58 id: catalogs
59 continue-on-error: true
60 run: pnpm generate:models:catalogs
61 env:
62 MODELSCHEMAS_API_KEY: ${{ secrets.MODELSCHEMAS_API_KEY }}
63​
64 - name: Format
65 run: pnpm format
66​
67 - name: Check for package changes
68 id: changes
69 run: |
70 if git diff --quiet -- packages/; then
71 echo "changed=false" >> $GITHUB_OUTPUT
72 else
73 echo "changed=true" >> $GITHUB_OUTPUT
74 fi
75​
76 - name: Commit and force-push
77 if: steps.changes.outputs.changed == 'true'
78 run: |
79 git config user.name "github-actions[bot]"
80 git config user.email "github-actions[bot]@users.noreply.github.com"
81 git add packages/ scripts/openrouter.models.json scripts/openrouter.video-models.json scripts/vercel-gateway.models.json scripts/lovable-gateway.models.json scripts/llmgateway.models.json scripts/neon.models.json scripts/.sync-models-last-run .changeset/
82 git commit -m "chore: sync model metadata"
83 # GITHUB_TOKEN pushes do not start the PR Test / E2E workflows.
84 # After this job, a maintainer must run those checks from the
85 # Actions tab or push an empty commit to automated/sync-models.
86 git push --force origin HEAD:automated/sync-models
87 env:
88 GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
89​
90 - name: Create or update PR
91 if: steps.changes.outputs.changed == 'true'
92 env:
93 GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
94 shell: bash
95 run: |
96 BRANCH="automated/sync-models"
97 EXISTING_PR=$(gh pr list --head "$BRANCH" --base main --json number --jq '.[0].number' 2>/dev/null || true)
98​
99 if [ -z "$EXISTING_PR" ] || [ "$EXISTING_PR" = "null" ]; then
100 BODY=$(cat <<'PRBODY'
101 Automated daily sync of model metadata from OpenRouter, Vercel AI Gateway, Lovable AI Gateway, LLM Gateway, Neon AI Gateway, and modelschemas (native provider models, plus ElevenLabs text-to-speech, music, sound effects, and voice design).
102​
103 - Fetches the latest model list from OpenRouter (chat + `GET /api/v1/videos/models`)
104 - Fetches the latest model list from Vercel AI Gateway
105 - Fetches the latest model list from Lovable AI Gateway
106 - Fetches the latest model list from LLM Gateway (`GET /v1/models`)
107 - Fetches the latest model list from Neon AI Gateway
108 - Converts to the internal adapter format
109 - Inserts new native-provider models from modelschemas (`@modelschemas/client`)
110 - Inserts new ElevenLabs text-to-speech, music, sound-effect, and voice-design models from modelschemas
111 - Writes each provider package's `./models` catalog (prices, limits, reasoning levels) from modelschemas
112 - Creates a patch changeset for all changed packages
113 PRBODY
114 )
115 gh pr create \
116 --title "chore: sync model metadata" \
117 --body "$BODY" \
118 --base main \
119 --head "$BRANCH"
120 fi
121​
122 - name: Fail if any sync step failed
123 if: >-
124 steps.fetch.outcome == 'failure' ||
125 steps.convert.outcome == 'failure' ||
126 steps.elevenlabs.outcome == 'failure' ||
127 steps.provider.outcome == 'failure' ||
128 steps.catalogs.outcome == 'failure'
129 run: |
130 echo "::error::A model sync step failed. Passing steps were still committed."
131 exit 1
132​
133 - name: Open or update failure issue
134 if: failure()
135 env:
136 GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
137 RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
138 OUTCOMES: >-
139 fetch=${{ steps.fetch.outcome }},
140 convert=${{ steps.convert.outcome }},
141 elevenlabs=${{ steps.elevenlabs.outcome }},
142 provider=${{ steps.provider.outcome }},
143 catalogs=${{ steps.catalogs.outcome }}
144 shell: bash
145 run: |
146 gh label create sync-models --color B60205 --description "Daily model sync failures" --force
147 BODY=$(printf '%s\n' \
148 "🚨 Sync Model Metadata failed on $(date -u +%F)." \
149 "" \
150 "Run: $RUN_URL" \
151 "Step outcomes: $OUTCOMES" \
152 "" \
153 "Steps that passed were still committed to \`automated/sync-models\`. Close this issue when the sync is green again.")
154 ISSUE=$(gh issue list --label sync-models --state open --json number --jq '.[0].number // empty')
155 if [ -n "$ISSUE" ]; then
156 gh issue comment "$ISSUE" --body "$BODY"
157 else
158 gh issue create --label sync-models \
159 --title "🚨🚨🚨 DAILY MODEL SYNC IS FAILING 🚨🚨🚨 Model updates are NOT landing" \
160 --body "$BODY"
161 fi