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

sync-models.yml

77 lines2.4 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​
16jobs:
17 sync:
18 name: Sync Models
19 runs-on: ubuntu-latest
20 steps:
21 - name: Checkout
22 uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
23 with:
24 fetch-depth: 0
25 persist-credentials: true # sync job pushes generated model updates
26​
27 - name: Setup Tools
28 uses: TanStack/config/.github/setup@190f659075ff0845850e330883eb26d7ffd0671f # main
29​
30 - name: Fetch and sync model metadata
31 run: pnpm generate:models
32​
33 - name: Check for package changes
34 id: changes
35 run: |
36 if git diff --quiet -- packages/; then
37 echo "changed=false" >> $GITHUB_OUTPUT
38 else
39 echo "changed=true" >> $GITHUB_OUTPUT
40 fi
41​
42 - name: Commit and force-push
43 if: steps.changes.outputs.changed == 'true'
44 run: |
45 git config user.name "github-actions[bot]"
46 git config user.email "github-actions[bot]@users.noreply.github.com"
47 git add packages/ scripts/openrouter.models.json scripts/.sync-models-last-run .changeset/
48 git commit -m "chore: sync model metadata from OpenRouter"
49 git push --force origin HEAD:automated/sync-models
50 env:
51 GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
52​
53 - name: Create or update PR
54 if: steps.changes.outputs.changed == 'true'
55 env:
56 GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
57 shell: bash
58 run: |
59 BRANCH="automated/sync-models"
60 EXISTING_PR=$(gh pr list --head "$BRANCH" --base main --json number --jq '.[0].number' 2>/dev/null || true)
61​
62 if [ -z "$EXISTING_PR" ] || [ "$EXISTING_PR" = "null" ]; then
63 BODY=$(cat <<'PRBODY'
64 Automated daily sync of model metadata from the OpenRouter API.
65​
66 - Fetches the latest model list from OpenRouter
67 - Converts to the internal adapter format
68 - Syncs provider-specific model metadata for affected packages
69 - Creates a patch changeset for all changed packages
70 PRBODY
71 )
72 gh pr create \
73 --title "chore: sync model metadata from OpenRouter" \
74 --body "$BODY" \
75 --base main \
76 --head "$BRANCH"
77 fi