Skip to content

Commit b84d4b3

Browse files
author
lycbrian
committed
test workflow
1 parent bd86d42 commit b84d4b3

File tree

2 files changed

+77
-6
lines changed

2 files changed

+77
-6
lines changed

.github/workflows/claude.yml

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

33-
- name: Run Claude PR Action
34-
uses: anthropics/claude-code-action@beta
33+
- name: Install JSZip
34+
run: npm install jszip
35+
36+
- name: Get job log and extract error
37+
id: get-error-log
38+
uses: actions/github-script@v7
3539
with:
36-
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
37-
timeout_minutes: "60"
38-
model: "claude-opus-4-20250514"
40+
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+
61+
if (!match) {
62+
core.setFailed("No job ID found in latest comment.");
63+
return;
64+
}
65+
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
100+
run: |
101+
echo "Captured errors:"
102+
echo "${{ steps.get-error-log.outputs.errors }}"
103+
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"

.github/workflows/terraform-test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ jobs:
6464
return;
6565
}
6666
67-
const commentBody = `### ❌ Failed Jobs in Workflow Run #${run_id}\n${failedJobs}`;
67+
const commentBody = `@claude ### ❌ Failed Jobs in Workflow Run #${run_id}\n${failedJobs}`;
6868
6969
await github.rest.issues.createComment({
7070
owner: context.repo.owner,

0 commit comments

Comments
 (0)