Skip to content

Commit db5c3d3

Browse files
fix: detect all changed packages for changeset in model sync pipeline (#445)
The `pnpm generate:models` pipeline runs three scripts sequentially: fetch, convert (regenerates @tanstack/ai-openrouter), and sync (adds new models to provider-specific packages). The changeset was only created when sync found new provider-specific models (totalAdded > 0), missing changes from the convert step entirely. Replace the totalAdded guard with git-based detection that finds all packages with uncommitted changes across the entire pipeline, ensuring changesets are created whenever any package is modified. Co-authored-by: Tanner Linsley <tannerlinsley@gmail.com>
1 parent 19db948 commit db5c3d3

1 file changed

Lines changed: 42 additions & 6 deletions

File tree

scripts/sync-provider-models.ts

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* pnpm tsx scripts/sync-provider-models.ts
1212
*/
1313

14+
import { execFileSync } from 'node:child_process'
1415
import { readFile, writeFile } from 'node:fs/promises'
1516
import { dirname, resolve } from 'node:path'
1617
import { fileURLToPath } from 'node:url'
@@ -496,6 +497,38 @@ function addToTypeMap(
496497
return content.replace(pattern, () => `${match[1]}\n${newEntries}${match[2]}`)
497498
}
498499

500+
// ---------------------------------------------------------------------------
501+
// Git-based change detection
502+
// ---------------------------------------------------------------------------
503+
504+
/**
505+
* Detect packages with uncommitted changes by running `git diff`.
506+
* This captures changes from ALL prior pipeline steps (e.g. convert-openrouter-models.ts)
507+
* not just the models added by this script.
508+
*/
509+
function detectChangedPackages(): Set<string> {
510+
const changed = new Set<string>()
511+
try {
512+
const diff = execFileSync(
513+
'git',
514+
['diff', 'HEAD', '--name-only', '--', 'packages/'],
515+
{ encoding: 'utf-8', cwd: ROOT },
516+
).trim()
517+
if (!diff) return changed
518+
519+
for (const line of diff.split('\n')) {
520+
// packages/typescript/ai-openrouter/... → @tanstack/ai-openrouter
521+
const match = line.match(/^packages\/typescript\/([\w-]+)\//)
522+
if (match) {
523+
changed.add(`@tanstack/${match[1]}`)
524+
}
525+
}
526+
} catch {
527+
// git not available (e.g. running outside a repo) — fall back to empty set
528+
}
529+
return changed
530+
}
531+
499532
// ---------------------------------------------------------------------------
500533
// Main
501534
// ---------------------------------------------------------------------------
@@ -672,20 +705,23 @@ async function main() {
672705
// Record this run's timestamp for future age-based filtering
673706
await writeLastRunTimestamp()
674707

675-
// Create changeset if any models were added
676-
if (totalAdded > 0) {
677-
await createChangeset(changedPackages)
708+
// Detect all packages with uncommitted changes (includes changes from
709+
// convert-openrouter-models.ts which runs before this script)
710+
const allChangedPackages = detectChangedPackages()
711+
for (const pkg of changedPackages) {
712+
allChangedPackages.add(pkg)
713+
}
714+
715+
if (allChangedPackages.size > 0) {
716+
await createChangeset(allChangedPackages)
678717
}
679718
}
680719

681720
/**
682721
* Create or update the sync-models changeset file.
683722
* If one already exists, merges the package lists. Otherwise creates a new one.
684-
* Always includes @tanstack/ai-openrouter since the convert script regenerates it.
685723
*/
686724
async function createChangeset(changedPackages: Set<string>) {
687-
changedPackages.add('@tanstack/ai-openrouter')
688-
689725
const changesetDir = resolve(ROOT, '.changeset')
690726
const { readdir } = await import('node:fs/promises')
691727
const files = await readdir(changesetDir)

0 commit comments

Comments
 (0)