Skip to content

Commit 030a78e

Browse files
authored
Merge branch 'main' into terraform-test
2 parents 58b8929 + c719633 commit 030a78e

File tree

1 file changed

+36
-69
lines changed

1 file changed

+36
-69
lines changed

.github/workflows/claude.yml

Lines changed: 36 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -30,80 +30,47 @@ jobs:
3030
with:
3131
fetch-depth: 1
3232

33-
- name: Install JSZip
34-
run: npm install jszip
35-
36-
- name: Get job log and extract error
37-
id: get-error-log
33+
- name: Extract Job ID from comment
34+
id: extract
3835
uses: actions/github-script@v7
3936
with:
4037
script: |
41-
const runId = context.runId;
42-
const pull_number = context.payload.pull_request?.number;
43-
44-
if (!pull_number) {
45-
core.setFailed("No pull request number found.");
46-
return;
47-
}
48-
49-
// Get latest PR comments
50-
const { data: comments } = await github.rest.issues.listComments({
51-
owner: context.repo.owner,
52-
repo: context.repo.repo,
53-
issue_number: pull_number,
54-
per_page: 10,
55-
});
56-
57-
const jobIdRegex = /Job ID: (\d+)/;
58-
const latestComment = comments.reverse().find(c => jobIdRegex.test(c.body));
59-
const match = latestComment?.body?.match(jobIdRegex);
60-
38+
const comment = context.payload.comment.body;
39+
const match = comment.match(/Job ID:\s*(\d+)/);
6140
if (!match) {
62-
core.setFailed("No job ID found in latest comment.");
63-
return;
41+
core.setFailed("No Job ID found in the comment.");
42+
} else {
43+
const jobId = match[1];
44+
core.setOutput("job_id", jobId);
45+
console.log(`Found Job ID: ${jobId}`);
6446
}
47+
48+
- name: Install GH CLI
49+
uses: dev-hanz-ops/install-gh-cli-action@v0.2.1
6550

66-
const jobId = match[1];
67-
console.log(`Found Job ID: ${jobId}`);
68-
69-
// Get log archive URL
70-
const { data: logZip } = await github.request(
71-
`GET /repos/${context.repo.owner}/${context.repo.repo}/actions/jobs/${jobId}/logs`
72-
);
73-
74-
const response = await fetch(logZip.url);
75-
const buffer = await response.arrayBuffer();
76-
const JSZip = require("jszip");
77-
const zip = await JSZip.loadAsync(Buffer.from(buffer));
78-
79-
let errorLines = [];
80-
81-
for (const filename of Object.keys(zip.files)) {
82-
const file = zip.files[filename];
83-
if (!file.dir && filename.endsWith('.txt')) {
84-
const content = await file.async('string');
85-
const lines = content.split('\n');
86-
for (const line of lines) {
87-
if (line.toLowerCase().includes('error') || line.includes('✗')) {
88-
errorLines.push(line.trim());
89-
}
90-
}
91-
}
92-
}
93-
94-
const errors = errorLines.join('\n').slice(0, 10000); // Limit output to 10,000 chars
95-
core.setOutput("errors", errors || "No errors found");
96-
#env:
97-
# NODE_OPTIONS: "--no-experimental-fetch"
98-
99-
- name: Post captured errors
51+
- name: Download job log
52+
id: grep-errors
53+
run: |
54+
gh api /repos/${{ github.repository }}/actions/jobs/${{ steps.extract.outputs.job_id }}/logs > job-log.txt
55+
grep -iE 'error|✗|failed|panic' job-log.txt > errors.txt
56+
cat errors.txt
57+
echo "errors<<EOF" >> $GITHUB_OUTPUT
58+
cat errors.txt >> $GITHUB_OUTPUT
59+
echo "EOF" >> $GITHUB_OUTPUT
60+
env:
61+
GH_TOKEN: ${{ secrets.CICD_GH_PAT }}
62+
63+
- name: Output error logs
10064
run: |
101-
echo "Captured errors:"
102-
echo "${{ steps.get-error-log.outputs.errors }}"
65+
echo "----- ERROR LOGS -----"
66+
echo "${{ steps.grep-errors.outputs.errors }}"
10367
104-
# - name: Run Claude PR Action
105-
# uses: anthropics/claude-code-action@beta
106-
# with:
107-
# anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
108-
# timeout_minutes: "60"
109-
# model: "claude-opus-4-20250514"
68+
- name: Run Claude PR Action
69+
uses: anthropics/claude-code-action@beta
70+
with:
71+
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
72+
timeout_minutes: "60"
73+
model: "claude-opus-4-20250514"
74+
direct_prompt: |
75+
Please check the error ${{ steps.grep-errors.outputs.errors }}
76+
and fix the issue in the code.

0 commit comments

Comments
 (0)