CoolFace
Apppublic

delqhi/sin-github-issues

sourceHugging Faceupdated 6mo agoView on Hugging Face
0likes
render-github-app-vm-rollout.mjs104 linesDownload Raw Back to scripts
1#!/usr/bin/env node2 3import { readFile } from 'node:fs/promises';4import path from 'node:path';5 6const cwd = process.cwd();7 8function parseArgs(argv) {9  const out = {};10  for (let i = 0; i < argv.length; i += 1) {11    const token = argv[i];12    if (!token.startsWith('--')) continue;13    const key = token.slice(2);14    const next = argv[i + 1];15    if (!next || next.startsWith('--')) {16      out[key] = 'true';17      continue;18    }19    out[key] = next;20    i += 1;21  }22  return out;23}24 25function firstString(...values) {26  for (const value of values) {27    if (typeof value === 'string' && value.trim()) return value.trim();28  }29  return null;30}31 32function parseList(value) {33  if (!value || typeof value !== 'string') return [];34  return value.split(',').map((item) => item.trim()).filter(Boolean);35}36 37async function main() {38  const args = parseArgs(process.argv.slice(2));39  const configPath = path.resolve(cwd, args.config || process.env.SIN_GITHUB_APP_ROUTING_PATH || './config/github-app-routing.local.json');40  const baseUrl = firstString(args['base-url'], 'https://<SET_VM_BASE_URL>');41  const repo = firstString(args.repo, 'OpenSIN-AI/OpenSIN-backend');42  const issueNumber = firstString(args['issue-number'], '<SET_TEST_ISSUE_NUMBER>');43  const installationId = firstString(args['installation-id'], '<SET_INSTALLATION_ID>');44  const selected = new Set(parseList(args.agents || args.agent));45 46  const raw = await readFile(configPath, 'utf8');47  const config = JSON.parse(raw);48  const apps = Array.isArray(config.apps) ? config.apps : [];49  const rolloutAgents = apps50    .map((entry) => ({51      agentSlug: firstString(entry.agentSlug, entry.preferredAgentSlug, entry.appSlug),52      appSlug: firstString(entry.appSlug, entry.agentSlug, entry.preferredAgentSlug),53      botName: firstString(entry.botName),54      routePath: firstString(entry.routePath, entry.webhookPath, config.defaultWebhookPath, '/github/webhook'),55    }))56    .filter((entry) => entry.agentSlug && entry.appSlug)57    .filter((entry) => selected.size === 0 || selected.has(entry.agentSlug) || selected.has(entry.appSlug));58 59  const agentArgs = rolloutAgents.map((entry) => entry.appSlug).join(',');60  const lines = [61    '# GitHub App VM Rollout Checklist',62    '',63    'cd a2a/team-coding/A2A-SIN-GitHub-Issues',64    'npm run build',65    'npm run ops:github-app-routing:init',66    `export SIN_GITHUB_APP_ROUTING_PATH=./config/github-app-routing.local.json`,67    'export SIN_GITHUB_API_BASE_URL=https://api.github.com',68    '',69    '# Fill these VM env vars',70  ];71 72  for (const entry of rolloutAgents) {73    const prefix = String(entry.appSlug).toUpperCase().replace(/-/g, '_');74    lines.push(`export ${prefix}_GITHUB_APP_ID=<SET_${prefix}_GITHUB_APP_ID>`);75    lines.push(`export ${prefix}_GITHUB_APP_CLIENT_ID=<SET_${prefix}_GITHUB_APP_CLIENT_ID>`);76    lines.push(`export ${prefix}_GITHUB_APP_PRIVATE_KEY_PEM='<SET_${prefix}_GITHUB_APP_PRIVATE_KEY_PEM>'`);77    lines.push(`export ${prefix}_GITHUB_APP_WEBHOOK_SECRET=<SET_${prefix}_GITHUB_APP_WEBHOOK_SECRET>`);78    lines.push('');79  }80 81  lines.push(`# Validate only the configured rollout targets`);82  lines.push(`npm run ops:github-app-routing:check -- --configured-only true --agents ${agentArgs}`);83  lines.push('');84  lines.push('# Start the GitHub Issues A2A runtime');85  lines.push('node dist/src/cli.js serve-a2a');86  lines.push('');87  lines.push('# In a second shell, run signed webhook smoke tests');88  for (const entry of rolloutAgents) {89    lines.push(`npm run ops:github-app-routing:smoke -- --agent ${entry.appSlug} --base-url ${baseUrl}`);90  }91  lines.push('');92  lines.push('# Optional: live comment test as each bot identity');93  for (const entry of rolloutAgents) {94    lines.push(`npm run ops:github-app-comment -- --agent ${entry.agentSlug} --repo ${repo} --issue-number ${issueNumber} --installation-id ${installationId} --body "Hello from ${entry.botName}"`);95  }96 97  process.stdout.write(lines.join('\n') + '\n');98}99 100main().catch((error) => {101  console.error(error instanceof Error ? error.message : String(error));102  process.exit(1);103});104