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

sync-models.yml

146 lines5.6 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​
48 - name: Sync provider models
49 id: provider
50 continue-on-error: true
51 run: pnpm exec tsx scripts/sync-provider-models.ts
52​
53 - name: Format
54 run: pnpm format
55​
56 - name: Check for package changes
57 id: changes
58 run: |
59 if git diff --quiet -- packages/; then
60 echo "changed=false" >> $GITHUB_OUTPUT
61 else
62 echo "changed=true" >> $GITHUB_OUTPUT
63 fi
64​
65 - name: Commit and force-push
66 if: steps.changes.outputs.changed == 'true'
67 run: |
68 git config user.name "github-actions[bot]"
69 git config user.email "github-actions[bot]@users.noreply.github.com"
70 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/.sync-models-last-run .changeset/
71 git commit -m "chore: sync model metadata"
72 # GITHUB_TOKEN pushes do not start the PR Test / E2E workflows.
73 # After this job, a maintainer must run those checks from the
74 # Actions tab or push an empty commit to automated/sync-models.
75 git push --force origin HEAD:automated/sync-models
76 env:
77 GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
78​
79 - name: Create or update PR
80 if: steps.changes.outputs.changed == 'true'
81 env:
82 GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
83 shell: bash
84 run: |
85 BRANCH="automated/sync-models"
86 EXISTING_PR=$(gh pr list --head "$BRANCH" --base main --json number --jq '.[0].number' 2>/dev/null || true)
87​
88 if [ -z "$EXISTING_PR" ] || [ "$EXISTING_PR" = "null" ]; then
89 BODY=$(cat <<'PRBODY'
90 Automated daily sync of model metadata from OpenRouter, Vercel AI Gateway, Lovable AI Gateway, LLM Gateway, and modelschemas (ElevenLabs text-to-speech, music, sound effects, and voice design).
91​
92 - Fetches the latest model list from OpenRouter (chat + `GET /api/v1/videos/models`)
93 - Fetches the latest model list from Vercel AI Gateway
94 - Fetches the latest model list from Lovable AI Gateway
95 - Fetches the latest model list from LLM Gateway (`GET /v1/models`)
96 - Converts to the internal adapter format
97 - Syncs provider-specific model metadata for affected packages
98 - Inserts new ElevenLabs text-to-speech, music, sound-effect, and voice-design models from modelschemas
99 - Creates a patch changeset for all changed packages
100 PRBODY
101 )
102 gh pr create \
103 --title "chore: sync model metadata" \
104 --body "$BODY" \
105 --base main \
106 --head "$BRANCH"
107 fi
108​
109 - name: Fail if any sync step failed
110 if: >-
111 steps.fetch.outcome == 'failure' ||
112 steps.convert.outcome == 'failure' ||
113 steps.elevenlabs.outcome == 'failure' ||
114 steps.provider.outcome == 'failure'
115 run: |
116 echo "::error::A model sync step failed. Passing steps were still committed."
117 exit 1
118​
119 - name: Open or update failure issue
120 if: failure()
121 env:
122 GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
123 RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
124 OUTCOMES: >-
125 fetch=${{ steps.fetch.outcome }},
126 convert=${{ steps.convert.outcome }},
127 elevenlabs=${{ steps.elevenlabs.outcome }},
128 provider=${{ steps.provider.outcome }}
129 shell: bash
130 run: |
131 gh label create sync-models --color B60205 --description "Daily model sync failures" --force
132 BODY=$(printf '%s\n' \
133 "🚨 Sync Model Metadata failed on $(date -u +%F)." \
134 "" \
135 "Run: $RUN_URL" \
136 "Step outcomes: $OUTCOMES" \
137 "" \
138 "Steps that passed were still committed to \`automated/sync-models\`. Close this issue when the sync is green again.")
139 ISSUE=$(gh issue list --label sync-models --state open --json number --jq '.[0].number // empty')
140 if [ -n "$ISSUE" ]; then
141 gh issue comment "$ISSUE" --body "$BODY"
142 else
143 gh issue create --label sync-models \
144 --title "🚨🚨🚨 DAILY MODEL SYNC IS FAILING 🚨🚨🚨 Model updates are NOT landing" \
145 --body "$BODY"
146 fi