|
| 1 | +#!/usr/bin/env bun |
| 2 | +/** |
| 3 | + * Syncs workflow_dispatch inputs in compare-models.yml with available agent:model combinations. |
| 4 | + * Run this after modifying agent model lists to keep the workflow in sync. |
| 5 | + * |
| 6 | + * Usage: |
| 7 | + * bun run scripts/sync-workflow-inputs.ts |
| 8 | + */ |
| 9 | + |
| 10 | +import { readFileSync, writeFileSync } from "node:fs"; |
| 11 | +import { listAgents } from "~/agents/index.js"; |
| 12 | +import YAML from "yaml"; |
| 13 | + |
| 14 | +interface WorkflowInput { |
| 15 | + description: string; |
| 16 | + type: string; |
| 17 | + default: boolean; |
| 18 | +} |
| 19 | + |
| 20 | +interface WorkflowInputs { |
| 21 | + [key: string]: WorkflowInput; |
| 22 | +} |
| 23 | + |
| 24 | +// Convert agent:model to workflow input ID |
| 25 | +function toInputId(agent: string, model: string): string { |
| 26 | + return `${agent}_${model}` |
| 27 | + .replace(/\//g, "_") |
| 28 | + .replace(/-/g, "_"); |
| 29 | +} |
| 30 | + |
| 31 | +// Convert agent:model to display description |
| 32 | +function toDescription(agent: string, model: string): string { |
| 33 | + return `${agent}:${model}`; |
| 34 | +} |
| 35 | + |
| 36 | +async function main(): Promise<void> { |
| 37 | + const workflowPath = ".github/workflows/compare-models.yml"; |
| 38 | + |
| 39 | + // Load the workflow file |
| 40 | + const workflowContent = readFileSync(workflowPath, "utf8"); |
| 41 | + const workflow = YAML.parse(workflowContent); |
| 42 | + |
| 43 | + // Get all available agent:model combinations |
| 44 | + const agents = await listAgents(); |
| 45 | + const combinations: Array<{ agent: string; model: string }> = []; |
| 46 | + |
| 47 | + for (const agent of agents) { |
| 48 | + for (const model of agent.models) { |
| 49 | + combinations.push({ agent: agent.name, model }); |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + if (combinations.length === 0) { |
| 54 | + console.error("No agent:model combinations found"); |
| 55 | + process.exit(1); |
| 56 | + } |
| 57 | + |
| 58 | + // Build new inputs |
| 59 | + const newInputs: WorkflowInputs = {}; |
| 60 | + |
| 61 | + // Group by agent for organization |
| 62 | + const byAgent = new Map<string, string[]>(); |
| 63 | + for (const { agent, model } of combinations) { |
| 64 | + if (!byAgent.has(agent)) { |
| 65 | + byAgent.set(agent, []); |
| 66 | + } |
| 67 | + byAgent.get(agent)!.push(model); |
| 68 | + } |
| 69 | + |
| 70 | + // Build inputs with comments |
| 71 | + const inputsWithComments: any = {}; |
| 72 | + |
| 73 | + for (const [agent, models] of byAgent.entries()) { |
| 74 | + // Add comment for agent group |
| 75 | + const agentKey = `__comment_${agent}`; |
| 76 | + inputsWithComments[agentKey] = `${agent.charAt(0).toUpperCase() + agent.slice(1)} agent models`; |
| 77 | + |
| 78 | + for (const model of models) { |
| 79 | + const inputId = toInputId(agent, model); |
| 80 | + inputsWithComments[inputId] = { |
| 81 | + description: toDescription(agent, model), |
| 82 | + type: "boolean", |
| 83 | + default: false, |
| 84 | + }; |
| 85 | + } |
| 86 | + } |
| 87 | + |
| 88 | + // Update the workflow |
| 89 | + workflow.on.workflow_dispatch.inputs = inputsWithComments; |
| 90 | + |
| 91 | + // Convert back to YAML with proper formatting |
| 92 | + let yamlOutput = YAML.stringify(workflow, { |
| 93 | + indent: 2, |
| 94 | + lineWidth: 0, |
| 95 | + }); |
| 96 | + |
| 97 | + // Replace comment placeholders with actual YAML comments |
| 98 | + yamlOutput = yamlOutput.replace( |
| 99 | + /__comment_(\w+):\s*["']?([^"'\n]+)["']?\n/g, |
| 100 | + "# $2\n", |
| 101 | + ); |
| 102 | + |
| 103 | + // Write back to file |
| 104 | + writeFileSync(workflowPath, yamlOutput, "utf8"); |
| 105 | + |
| 106 | + console.log(`✓ Updated ${workflowPath} with ${combinations.length} agent:model combinations:`); |
| 107 | + for (const { agent, model } of combinations) { |
| 108 | + console.log(` - ${agent}:${model} (ID: ${toInputId(agent, model)})`); |
| 109 | + } |
| 110 | + |
| 111 | + console.log("\n✓ The build-workflow-matrix.ts script will automatically recognize these combinations."); |
| 112 | + console.log(" No manual updates needed - everything is dynamically generated!"); |
| 113 | +} |
| 114 | + |
| 115 | +await main(); |
0 commit comments