Repository navigation
293 lines (260 loc) · 12.5 KB
/
Copy pathsync-models.yml
File metadata and controls
293 lines (260 loc) · 12.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
name: Sync Model Catalogs
on:
schedule:
- cron: "17 */6 * * *"
workflow_dispatch:
# sync runs repository code and provider API keys with the built-in token only. It uploads each provider's catalog
# patch as data. publish runs only .github/sync-models/ from this commit with a models.dev automation app token from
# the automation environment: it applies each patch, allowing only catalog TOML, opens or updates the provider's pull
# request and auto-merges safe syncs. The app's pull requests run their checks and its merges deploy as usual.
permissions:
contents: read
concurrency: ${{ github.workflow }}-${{ github.ref }}
jobs:
# One job syncs every provider so a run pays for one runner instead of one per provider. Providers are independent:
# each starts from a clean dev, and a provider that fails neither stops the rest nor leaks its partial changes.
sync:
if: github.repository == 'anomalyco/models.dev'
runs-on: blacksmith-4vcpu-ubuntu-2404
environment: release
outputs:
changed: ${{ steps.sync.outputs.changed }}
# bun models:sync opens an issue for each missing model and dispatches the issue fixer (repository_dispatch needs
# contents: write). The built-in token can't change dev or workflows; catalog changes still go through publish.
permissions:
contents: write
issues: write
id-token: write
steps:
- name: Checkout code
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5
with:
ref: dev
persist-credentials: false
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@e1253824e5c10ff9df46874f81ed3ec929e19cfd # v6.3.0
with:
role-to-assume: arn:aws:iam::604439173067:role/github/models.dev-release
role-session-name: models.dev-sync-${{ github.run_id }}
aws-region: us-east-1
- name: Fetch secrets
uses: aws-actions/aws-secretsmanager-get-secrets@2297f9a879480a9e3af9b293ed15c70caf8e1c88 # v3.0.2
with:
secret-ids: |
ANTHROPIC_API_KEY,models.dev/release/ANTHROPIC_API_KEY
BASETEN_API_KEY,models.dev/release/BASETEN_API_KEY
DASHSCOPE_API_KEY,models.dev/release/DASHSCOPE_API_KEY
CLOUDFLARE_WORKERS_AI_SYNC_API_TOKEN,models.dev/release/CLOUDFLARE_WORKERS_AI_SYNC_API_TOKEN
DEEPINFRA_API_KEY,models.dev/release/DEEPINFRA_API_KEY
DEEPSEEK_API_KEY,models.dev/release/DEEPSEEK_API_KEY
DIGITALOCEAN_API_TOKEN,models.dev/release/DIGITALOCEAN_API_TOKEN
FIREWORKS_API_KEY,models.dev/release/FIREWORKS_API_KEY
GROQ_API_KEY,models.dev/release/GROQ_API_KEY
GOOGLE_API_KEY,models.dev/release/GOOGLE_API_KEY
MERGE_GATEWAY_API_KEY,models.dev/release/MERGE_GATEWAY_API_KEY
MISTRAL_API_KEY,models.dev/release/MISTRAL_API_KEY
MOONSHOT_API_KEY,models.dev/release/MOONSHOT_API_KEY
NOVITA_AI_API_KEY,models.dev/release/NOVITA_AI_API_KEY
OPENAI_API_KEY,models.dev/release/OPENAI_API_KEY
OPENROUTER_API_KEY,models.dev/release/OPENROUTER_API_KEY
XAI_API_KEY,models.dev/release/XAI_API_KEY
parse-json-secrets: false
- name: Setup Bun
uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
with:
bun-version: 1.4.4
- name: Install dependencies
run: bun install --frozen-lockfile
- name: Sync model catalogs
id: sync
env:
GH_TOKEN: ${{ github.token }}
ANTHROPIC_API_KEY: ${{ env.ANTHROPIC_API_KEY }}
BASETEN_API_KEY: ${{ env.BASETEN_API_KEY }}
DASHSCOPE_API_KEY: ${{ env.DASHSCOPE_API_KEY }}
DEEPINFRA_API_KEY: ${{ env.DEEPINFRA_API_KEY }}
DEEPSEEK_API_KEY: ${{ env.DEEPSEEK_API_KEY }}
DIGITALOCEAN_API_TOKEN: ${{ env.DIGITALOCEAN_API_TOKEN }}
DIGITALOCEAN_ACCESS_TOKEN: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
FIREWORKS_API_KEY: ${{ env.FIREWORKS_API_KEY }}
GROQ_API_KEY: ${{ env.GROQ_API_KEY }}
HF_TOKEN: ${{ secrets.HF_TOKEN }}
OPENROUTER_API_KEY: ${{ env.OPENROUTER_API_KEY }}
OPENAI_API_KEY: ${{ env.OPENAI_API_KEY }}
VENICE_API_KEY: ${{ secrets.VENICE_API_KEY }}
LLMGATEWAY_API_KEY: ${{ secrets.LLMGATEWAY_API_KEY }}
MERGE_GATEWAY_API_KEY: ${{ env.MERGE_GATEWAY_API_KEY }}
MISTRAL_API_KEY: ${{ env.MISTRAL_API_KEY }}
MOONSHOT_API_KEY: ${{ env.MOONSHOT_API_KEY }}
NOVITA_AI_API_KEY: ${{ env.NOVITA_AI_API_KEY }}
KILO_API_KEY: ${{ secrets.KILO_API_KEY }}
GOOGLE_API_KEY: ${{ env.GOOGLE_API_KEY }}
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
GOOGLE_GENERATIVE_AI_API_KEY: ${{ secrets.GOOGLE_GENERATIVE_AI_API_KEY }}
XAI_API_KEY: ${{ env.XAI_API_KEY }}
CLOUDFLARE_API_TOKEN: ${{ env.CLOUDFLARE_WORKERS_AI_SYNC_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ vars.CLOUDFLARE_WORKERS_AI_SYNC_ACCOUNT_ID }}
CLOUDFLARE_WORKERS_AI_SYNC_ACCOUNT_ID: ${{ vars.CLOUDFLARE_WORKERS_AI_SYNC_ACCOUNT_ID }}
CLOUDFLARE_WORKERS_AI_SYNC_API_TOKEN: ${{ env.CLOUDFLARE_WORKERS_AI_SYNC_API_TOKEN }}
run: |
set -uo pipefail
out="$RUNNER_TEMP/sync"
failures="$RUNNER_TEMP/sync-failures"
results="$RUNNER_TEMP/sync-results.md"
providers="$RUNNER_TEMP/sync-providers"
reasons="$RUNNER_TEMP/sync-failure-reasons.md"
log="$RUNNER_TEMP/sync-provider.log"
: > "$failures"
: > "$reasons"
printf '| provider | result |\n| --- | --- |\n' > "$results"
base="$(git rev-parse HEAD)"
changed=false
if ! bun models:sync --list-providers | jq -r '.include[] | [.provider, .name] | @tsv' > "$providers"; then
echo "::error::failed to list sync providers"
echo "failed=true" >> "$GITHUB_OUTPUT"
echo "changed=$changed" >> "$GITHUB_OUTPUT"
exit 0
fi
while IFS=$'\t' read -r provider name <&3; do
echo "::group::Sync $name ($provider)"
# Every provider starts from clean dev, exactly like the old per-provider jobs: nothing a previous
# provider (or a failed one) left behind can appear in this provider's patch.
git reset -q --hard "$base"
git clean -qfd models providers
rm -f .sync/model-sync-report.md "$RUNNER_TEMP/auto-merge"
result=ok
if ! bun models:sync "$provider" < /dev/null 2>&1 | tee "$log"; then
result="sync failed"
elif [ -n "$(git status --porcelain -- models providers)" ] && ! bun validate < /dev/null 2>&1 | tee "$log"; then
result="validation failed"
fi
if [ "$result" != ok ]; then
# Drop this provider's partial changes and keep syncing the rest.
echo "::error::$provider: $result"
printf '%s: %s\n' "$provider" "$result" >> "$failures"
printf '| %s | %s |\n' "$provider" "$result" >> "$results"
# The end of the log is usually the error, so the run summary says why without opening the logs.
{
printf '<details><summary><b>%s</b>: %s</summary>\n\n```text\n' "$provider" "$result"
grep -vE '^[[:space:]]*$|DeprecationWarning|^[[:space:]]+at ' "$log" | tail -n 25
printf '```\n\n</details>\n\n'
} >> "$reasons"
echo "::endgroup::"
continue
fi
if [ -z "$(git status --porcelain -- models providers)" ]; then
echo "No model catalog changes found."
printf '| %s | unchanged |\n' "$provider" >> "$results"
echo "::endgroup::"
continue
fi
dir="$out/sync-$provider"
mkdir -p "$dir"
tee -a "$GITHUB_STEP_SUMMARY" < .sync/model-sync-report.md >/dev/null
git add models providers
git -c user.name=sync -c user.email=sync@localhost commit -q --no-verify -m sync
git diff --binary HEAD^ HEAD > "$dir/changes.patch"
GITHUB_OUTPUT="$RUNNER_TEMP/auto-merge" bun sync:auto-merge HEAD^ HEAD
sed -n 's/^safe=//p' "$RUNNER_TEMP/auto-merge" | tr -d '\n' > "$dir/safe"
printf '%s' "$provider" > "$dir/provider"
printf '%s' "$name" > "$dir/name"
cp .sync/model-sync-report.md "$dir/report.md"
printf '| %s | changed |\n' "$provider" >> "$results"
changed=true
echo "::endgroup::"
done 3< "$providers"
git reset -q --hard "$base"
git clean -qfd models providers
echo "changed=$changed" >> "$GITHUB_OUTPUT"
if [ -s "$failures" ]; then
echo "failed=true" >> "$GITHUB_OUTPUT"
fi
cat "$results" >> "$GITHUB_STEP_SUMMARY"
if [ -s "$reasons" ]; then
printf '\n### Why providers failed\n\n' >> "$GITHUB_STEP_SUMMARY"
cat "$reasons" >> "$GITHUB_STEP_SUMMARY"
fi
- name: Upload changes
if: steps.sync.outputs.changed == 'true'
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: sync
path: ${{ runner.temp }}/sync
if-no-files-found: error
retention-days: 1
# Fails the run after the changes other providers produced are safely uploaded, so publish still goes ahead.
- name: Check for failed providers
if: steps.sync.outputs.failed == 'true'
run: |
echo "These providers did not sync and produced no patch:"
cat "$RUNNER_TEMP/sync-failures"
exit 1
publish:
needs: sync
# Runs when some provider syncs failed, so the others still publish.
if: always() && github.repository == 'anomalyco/models.dev' && needs.sync.outputs.changed == 'true'
runs-on: ubuntu-latest
environment: automation
permissions:
contents: read
id-token: write
steps:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@e1253824e5c10ff9df46874f81ed3ec929e19cfd # v6.3.0
with:
role-to-assume: arn:aws:iam::604439173067:role/github/models.dev-automation
role-session-name: models.dev-automation-${{ github.run_id }}
aws-region: us-east-1
- name: Fetch secrets
uses: aws-actions/aws-secretsmanager-get-secrets@2297f9a879480a9e3af9b293ed15c70caf8e1c88 # v3.0.2
with:
secret-ids: |
AUTOMATION_APP_PRIVATE_KEY,models.dev/automation/AUTOMATION_APP_PRIVATE_KEY
parse-json-secrets: false
- name: Create app token
id: app
uses: actions/create-github-app-token@fee1f7d63c2ff003460e3d139729b119787bc349 # v2.2.2
with:
app-id: ${{ vars.AUTOMATION_APP_ID }}
private-key: ${{ env.AUTOMATION_APP_PRIVATE_KEY }}
repositories: models.dev
permission-contents: write
permission-issues: write
permission-pull-requests: write
- name: Check out publish scripts
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5
with:
ref: ${{ github.sha }}
path: trusted
sparse-checkout: /.github/sync-models/
sparse-checkout-cone-mode: false
persist-credentials: false
# Holds the push credential; nothing from this checkout runs.
- name: Check out dev
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5
with:
ref: dev
path: repo
token: ${{ steps.app.outputs.token }}
- name: Download changes
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
with:
name: sync
path: ${{ runner.temp }}/sync
- name: Publish
working-directory: repo
env:
GH_TOKEN: ${{ steps.app.outputs.token }}
GH_REPO: ${{ github.repository }}
SLUG: ${{ steps.app.outputs.app-slug }}
run: |
set -uo pipefail
BOT_NAME="${SLUG}[bot]"
BOT_EMAIL="$(gh api "/users/${SLUG}%5Bbot%5D" --jq .id)+${SLUG}[bot]@users.noreply.github.com" || exit 1
export BOT_NAME BOT_EMAIL
failed=0
for dir in "$RUNNER_TEMP"/sync/sync-*/; do
[ -d "$dir" ] || continue
bash ../trusted/.github/sync-models/publish.sh "$dir" || failed=1
done
exit "$failed"