Skip to content

Commit 38fbcec

Browse files
committed
Fix CI failures from run 18679056658
1 parent 82c282c commit 38fbcec

File tree

1 file changed

+77
-1
lines changed

1 file changed

+77
-1
lines changed

scripts/claude.mjs

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,66 @@ async function buildEnhancedPrompt(template, basePrompt, options = {}) {
926926
return enhancedPrompt
927927
}
928928

929+
/**
930+
* Filter CI logs to extract only relevant failure information
931+
* Removes runner setup noise and focuses on actual errors
932+
*/
933+
function filterCILogs(rawLogs) {
934+
const lines = rawLogs.split('\n')
935+
const relevantLines = []
936+
let inErrorSection = false
937+
938+
for (const line of lines) {
939+
// Skip runner metadata and setup
940+
if (
941+
line.includes('Current runner version:') ||
942+
line.includes('Runner Image') ||
943+
line.includes('Operating System') ||
944+
line.includes('GITHUB_TOKEN') ||
945+
line.includes('Prepare workflow') ||
946+
line.includes('Prepare all required') ||
947+
line.includes('##[group]') ||
948+
line.includes('##[endgroup]') ||
949+
line.includes('Post job cleanup') ||
950+
line.includes('git config') ||
951+
line.includes('git submodule') ||
952+
line.includes('Cleaning up orphan') ||
953+
line.includes('secret source:') ||
954+
line.includes('[command]/usr/bin/git')
955+
) {
956+
continue
957+
}
958+
959+
// Detect error sections
960+
if (
961+
line.includes('##[error]') ||
962+
line.includes('Error:') ||
963+
line.includes('error TS') ||
964+
line.includes('FAIL') ||
965+
line.includes('✗') ||
966+
line.includes('❌') ||
967+
line.includes('failed') ||
968+
line.includes('ELIFECYCLE')
969+
) {
970+
inErrorSection = true
971+
relevantLines.push(line)
972+
} else if (inErrorSection && line.trim() !== '') {
973+
relevantLines.push(line)
974+
// Keep context for 5 lines after error
975+
if (relevantLines.length > 100) {
976+
inErrorSection = false
977+
}
978+
}
979+
}
980+
981+
// If no errors found, return last 50 lines (might contain useful context)
982+
if (relevantLines.length === 0) {
983+
return lines.slice(-50).join('\n')
984+
}
985+
986+
return relevantLines.join('\n')
987+
}
988+
929989
/**
930990
* Prepare Claude command arguments for Claude Code.
931991
* Claude Code uses natural language prompts, not the same flags.
@@ -3505,6 +3565,22 @@ Fix all CI failures now by making the necessary changes.`
35053565
)
35063566
console.log('')
35073567

3568+
// Filter logs to extract relevant errors
3569+
const rawLogs = logsResult.stdout || 'No logs available'
3570+
const filteredLogs = filterCILogs(rawLogs)
3571+
3572+
// Show summary to user (not full logs)
3573+
const logLines = filteredLogs.split('\n').slice(0, 10)
3574+
log.substep('Error summary:')
3575+
for (const line of logLines) {
3576+
if (line.trim()) {
3577+
log.substep(` ${line.trim().substring(0, 100)}`)
3578+
}
3579+
}
3580+
if (filteredLogs.split('\n').length > 10) {
3581+
log.substep(` ... (${filteredLogs.split('\n').length - 10} more lines)`)
3582+
}
3583+
35083584
// Analyze and fix with Claude
35093585
log.progress(`Analyzing failure in ${job.name}`)
35103586
const fixPrompt = `You are automatically fixing CI failures. The job "${job.name}" failed in workflow run ${lastRunId} for commit ${currentSha} in ${owner}/${repo}.
@@ -3513,7 +3589,7 @@ Job: ${job.name}
35133589
Status: ${job.conclusion}
35143590
35153591
Failure logs:
3516-
${logsResult.stdout || 'No logs available'}
3592+
${filteredLogs}
35173593
35183594
Your task:
35193595
1. Analyze these CI logs for the "${job.name}" job

0 commit comments

Comments
 (0)