Skip to content

Commit cb0d99b

Browse files
Enhance log analysis prompt for DevOps diagnosis
Refactor prompt for log analysis to improve clarity and structure.
1 parent 04d346d commit cb0d99b

1 file changed

Lines changed: 61 additions & 13 deletions

File tree

‎.github/scripts/analyze-failure.js‎

Lines changed: 61 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,34 +70,82 @@ async function run() {
7070
console.log(`Extracted log tail (${tailLogs.length} characters). Generating analysis...`);
7171

7272
// 5. Generate Analysis with Gemini
73+
// const prompt = `
74+
// You are a DevOps Expert and "Build Doctor".
75+
// A GitHub Actions workflow '${workflowName}' failed.
76+
77+
// Analyze the following log snippet (last ${MAX_LOG_LINES} lines) to identify the root cause.
78+
79+
// Log Snippet:
80+
// \`\`\`
81+
// ${tailLogs}
82+
// \`\`\`
83+
84+
// Your response must be a concise Markdown comment suitable for a developer.
85+
// Structure:
86+
87+
// ## 🩺 Build Doctor Diagnosis
88+
89+
// **1. Root Cause:**
90+
// (Explain what went wrong in 1-2 senteces. Be specific: Syntax error, Dependencies, Test failure, Infra, etc.)
91+
92+
// **2. Relevant Log Lines:**
93+
// (Quote the specific error message from the logs)
94+
95+
// **3. Suggested Fix:**
96+
// (Actionable advice. If it's a code fix, show the snippet. If it's a config tweak, show the command or yaml change.)
97+
98+
// **Confidence:** (High/Medium/Low)
99+
// `;
73100
const prompt = `
74-
You are a DevOps Expert and "Build Doctor".
75-
A GitHub Actions workflow '${workflowName}' failed.
101+
You are an expert DevOps engineer and "Build Doctor".
102+
A GitHub Actions workflow '${workflowName}' has failed.
103+
104+
Your job:
105+
- Read the log snippet carefully.
106+
- Identify the **single most likely root cause** of the failure.
107+
- Map it to a clear category (Syntax, Dependency, Test, Infra, Config, Credential, Network, Tooling, etc.).
108+
- Propose **one** primary fix that a developer can apply quickly.
76109
77-
Analyze the following log snippet (last ${MAX_LOG_LINES} lines) to identify the root cause.
110+
Context:
111+
- These are the last ${MAX_LOG_LINES} lines of the job log.
112+
- They may contain retries, warnings, and noisy stack traces.
113+
- The **true error** is usually near the first occurrence of "error", "exception", "failed", "fatal", non‑zero exit codes, or GitHub Actions step failure messages.
78114
79115
Log Snippet:
80116
\`\`\`
81117
${tailLogs}
82118
\`\`\`
83119
84-
Your response must be a concise Markdown comment suitable for a developer.
85-
Structure:
120+
First, think step by step (do NOT include this reasoning in the final answer):
121+
1. Skim for the first real failure signal (error/exception/exit code/failed step).
122+
2. Summarize in your own words what actually went wrong.
123+
3. Decide which category it belongs to: Syntax, Dependency, Test, Infra, Config, Credential, Network, Tooling, Other.
124+
4. Decide the most likely fix a DevOps/dev engineer should try first.
125+
5. If there is not enough information, state that clearly and suggest what extra logs/checks are needed.
86126
87-
## 🩺 Build Doctor Diagnosis
127+
Then, output **only** the following Markdown comment, nothing else:
88128
89-
**1. Root Cause:**
90-
(Explain what went wrong in 1-2 senteces. Be specific: Syntax error, Dependencies, Test failure, Infra, etc.)
129+
# 🩺 Build Doctor Diagnosis
91130
92-
**2. Relevant Log Lines:**
93-
(Quote the specific error message from the logs)
131+
### Diagnosis (${workflowName})
132+
**1. Root Cause:**
133+
(Explain what went wrong in 1–2 sentences. Be specific: e.g. "Maven dependency not found", "JUnit test failure", "Docker login failed", "Kubernetes connection timeout". If unsure, say "Most likely ..." and why.)
94134
95-
**3. Suggested Fix:**
96-
(Actionable advice. If it's a code fix, show the snippet. If it's a config tweak, show the command or yaml change.)
135+
**2. Relevant Log Lines:**
136+
(Quote the *minimal* most important 1–3 lines from the logs that show the error. Do not paste large blocks.)
97137
98-
**Confidence:** (High/Medium/Low)
138+
**3. Suggested Fix:**
139+
(Give concrete, copy‑pasteable steps.
140+
- For code issues: show the key code or config snippet to change.
141+
- For pipeline/config issues: show the YAML or command to adjust.
142+
- For infra/credentials: describe exact checks or commands to run, and what to update.)
143+
144+
**Confidence:** High | Medium | Low
145+
(Choose one based on how clear the error is. If logs are ambiguous or truncated, use Medium or Low and say what’s missing.)
99146
`;
100147

148+
101149
const result = await model.generateContent(prompt);
102150
const analysis = result.response.text();
103151

0 commit comments

Comments
 (0)