scripts/run.mjs
scripts/run.mjsBrowse 5 files
716 tokens
2,658 bytes
Token encoding: o200k_base
Snapshot 506f736
← Back to SKILL.md
1#!/usr/bin/env node2 3import { execFileSync, spawnSync } from 'node:child_process';4import path from 'node:path';5import { fileURLToPath } from 'node:url';6 7const { console, process } = globalThis;8const scriptPath = fileURLToPath(import.meta.url);9const scriptDir = path.dirname(scriptPath);10 11const VALIDATION_NAMES = [12 'build-check',13 'dist-check',14 'lint',15 'test',16 'format-check',17];18const VALIDATION_COMMANDS = [19 'pnpm -r build-check',20 'pnpm -r -F "@openai/*" dist:check',21 'pnpm lint',22 'pnpm test',23 'pnpm format:check:changed',24];25 26function printUsage() {27 console.log(`code-change-verification28 29Usage:30 node .agents/skills/code-change-verification/scripts/run.mjs31`);32}33 34function getRepoRoot() {35 try {36 return execFileSync(37 'git',38 ['-C', scriptDir, 'rev-parse', '--show-toplevel'],39 {40 encoding: 'utf8',41 stdio: ['ignore', 'pipe', 'ignore'],42 },43 ).trim();44 } catch {45 return path.resolve(scriptDir, '../../../..');46 }47}48 49function getPnpmCommand() {50 return process.platform === 'win32' ? 'pnpm.cmd' : 'pnpm';51}52 53function runPnpm(repoRoot, label, args) {54 console.log(`Running pnpm ${args.join(' ')}...`);55 const result = spawnSync(getPnpmCommand(), args, {56 cwd: repoRoot,57 env: process.env,58 stdio: 'inherit',59 });60 61 if (result.error) {62 console.error(`code-change-verification: ${label} failed to start.`);63 console.error(result.error);64 return 1;65 }66 if (typeof result.status === 'number') {67 if (result.status !== 0) {68 console.error(69 `code-change-verification: ${label} failed with exit code ${result.status}.`,70 );71 }72 return result.status;73 }74 75 console.error(76 `code-change-verification: ${label} terminated by ${result.signal ?? 'an unknown signal'}.`,77 );78 return 1;79}80 81function runVerification() {82 const repoRoot = getRepoRoot();83 const installExitCode = runPnpm(repoRoot, 'install', [84 'i',85 '--frozen-lockfile',86 ]);87 if (installExitCode !== 0) {88 return installExitCode;89 }90 91 const buildExitCode = runPnpm(repoRoot, 'build', ['build']);92 if (buildExitCode !== 0) {93 return buildExitCode;94 }95 96 const validationExitCode = runPnpm(repoRoot, 'validation', [97 'exec',98 'concurrently',99 '--kill-others-on-fail',100 '--kill-timeout',101 '5000',102 '--names',103 VALIDATION_NAMES.join(','),104 ...VALIDATION_COMMANDS,105 ]);106 if (validationExitCode !== 0) {107 return validationExitCode;108 }109 110 console.log('code-change-verification: all commands passed.');111 return 0;112}113 114if (process.argv.includes('--help')) {115 printUsage();116 process.exit(0);117}118 119process.exit(runVerification());120