Skip to content

Commit 4f5a5cd

Browse files
committed
chore: Claude
1 parent cd3169c commit 4f5a5cd

3 files changed

Lines changed: 214 additions & 0 deletions

File tree

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: Auto Fix CI Failures
2+
3+
on:
4+
workflow_run:
5+
workflows: ["CI"]
6+
types:
7+
- completed
8+
9+
permissions:
10+
contents: write
11+
pull-requests: write
12+
actions: read
13+
issues: write
14+
id-token: write # Required for OIDC token exchange
15+
16+
jobs:
17+
auto-fix:
18+
if: |
19+
github.event.workflow_run.conclusion == 'failure' &&
20+
github.event.workflow_run.pull_requests[0] &&
21+
!startsWith(github.event.workflow_run.head_branch, 'claude-auto-fix-ci-')
22+
runs-on: ubuntu-latest
23+
steps:
24+
- name: Checkout code
25+
uses: actions/checkout@v5
26+
with:
27+
ref: ${{ github.event.workflow_run.head_branch }}
28+
fetch-depth: 0
29+
token: ${{ secrets.GITHUB_TOKEN }}
30+
31+
- name: Setup git identity
32+
run: |
33+
git config --global user.email "claude[bot]@users.noreply.github.com"
34+
git config --global user.name "claude[bot]"
35+
36+
- name: Create fix branch
37+
id: branch
38+
run: |
39+
BRANCH_NAME="claude-auto-fix-ci-${{ github.event.workflow_run.head_branch }}-${{ github.run_id }}"
40+
git checkout -b "$BRANCH_NAME"
41+
echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT
42+
43+
- name: Get CI failure details
44+
id: failure_details
45+
uses: actions/github-script@v7
46+
with:
47+
script: |
48+
const run = await github.rest.actions.getWorkflowRun({
49+
owner: context.repo.owner,
50+
repo: context.repo.repo,
51+
run_id: ${{ github.event.workflow_run.id }}
52+
});
53+
54+
const jobs = await github.rest.actions.listJobsForWorkflowRun({
55+
owner: context.repo.owner,
56+
repo: context.repo.repo,
57+
run_id: ${{ github.event.workflow_run.id }}
58+
});
59+
60+
const failedJobs = jobs.data.jobs.filter(job => job.conclusion === 'failure');
61+
62+
let errorLogs = [];
63+
for (const job of failedJobs) {
64+
const logs = await github.rest.actions.downloadJobLogsForWorkflowRun({
65+
owner: context.repo.owner,
66+
repo: context.repo.repo,
67+
job_id: job.id
68+
});
69+
errorLogs.push({
70+
jobName: job.name,
71+
logs: logs.data
72+
});
73+
}
74+
75+
return {
76+
runUrl: run.data.html_url,
77+
failedJobs: failedJobs.map(j => j.name),
78+
errorLogs: errorLogs
79+
};
80+
81+
- name: Fix CI failures with Claude
82+
id: claude
83+
uses: anthropics/claude-code-action@v1
84+
with:
85+
prompt: |
86+
/fix-ci
87+
Failed CI Run: ${{ fromJSON(steps.failure_details.outputs.result).runUrl }}
88+
Failed Jobs: ${{ join(fromJSON(steps.failure_details.outputs.result).failedJobs, ', ') }}
89+
PR Number: ${{ github.event.workflow_run.pull_requests[0].number }}
90+
Branch Name: ${{ steps.branch.outputs.branch_name }}
91+
Base Branch: ${{ github.event.workflow_run.head_branch }}
92+
Repository: ${{ github.repository }}
93+
94+
Error logs:
95+
${{ toJSON(fromJSON(steps.failure_details.outputs.result).errorLogs) }}
96+
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
97+
claude_args: "--allowedTools 'Edit,MultiEdit,Write,Read,Glob,Grep,LS,Bash(git:*),Bash(bun:*),Bash(npm:*),Bash(npx:*),Bash(gh:*)'"

.github/workflows/claude.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Claude Code
2+
3+
on:
4+
issue_comment:
5+
types: [created]
6+
pull_request_review_comment:
7+
types: [created]
8+
issues:
9+
types: [opened, assigned]
10+
pull_request_review:
11+
types: [submitted]
12+
13+
jobs:
14+
claude:
15+
if: |
16+
(github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude')) ||
17+
(github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude')) ||
18+
(github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude')) ||
19+
(github.event_name == 'issues' && (contains(github.event.issue.body, '@claude') || contains(github.event.issue.title, '@claude')))
20+
runs-on: ubuntu-latest
21+
permissions:
22+
contents: write
23+
pull-requests: write
24+
issues: write
25+
id-token: write
26+
actions: read # Required for Claude to read CI results on PRs
27+
steps:
28+
- name: Checkout repository
29+
uses: actions/checkout@v5
30+
with:
31+
fetch-depth: 1
32+
33+
- name: Run Claude Code
34+
id: claude
35+
uses: anthropics/claude-code-action@v1
36+
with:
37+
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
38+
39+
# Optional: Customize the trigger phrase (default: @claude)
40+
# trigger_phrase: "/claude"
41+
42+
# Optional: Trigger when specific user is assigned to an issue
43+
# assignee_trigger: "claude-bot"
44+
45+
# Optional: Configure Claude's behavior with CLI arguments
46+
# claude_args: |
47+
# --model claude-opus-4-1-20250805
48+
# --max-turns 10
49+
# --allowedTools "Bash(npm install),Bash(npm run build),Bash(npm run test:*),Bash(npm run lint:*)"
50+
# --system-prompt "Follow our coding standards. Ensure all new code has tests. Use TypeScript for new files."
51+
52+
# Optional: Advanced settings configuration
53+
# settings: |
54+
# {
55+
# "env": {
56+
# "NODE_ENV": "test"
57+
# }
58+
# }

CLAUDE.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# CLAUDE.md
2+
3+
## Code Style
4+
5+
- C++11 unless otherwise specified
6+
- Boost C++ Libraries naming conventions (snake_case)
7+
- 4-space indentation, no tabs
8+
- Braces on their own line for classes/functions
9+
10+
## Javadoc Documentation
11+
12+
Follow Boost C++ Libraries Javadoc style:
13+
14+
- Brief descriptions on first line after `/**`
15+
- Functions returning values: brief starts with "Return"
16+
- Use `@param` for function parameters
17+
- Use `@tparam` for template parameters, except:
18+
- Variadic args (`Args...`) — omit
19+
- Types deduced from function parameters — omit (self-evident from `@param`)
20+
- Use `@return` for return value details
21+
- Use `@pre` for preconditions
22+
- Use `@post` for postconditions
23+
- Use `@throws` for exceptions
24+
- Use `@note` for important notes
25+
- Use `@see` for cross-references
26+
- Use `@code` / `@endcode` for examples
27+
28+
## Examples
29+
30+
```cpp
31+
/** Return the size of the buffer sequence.
32+
33+
@param buffers The buffer sequence to measure.
34+
35+
@return The total byte count.
36+
*/
37+
template<class BufferSequence>
38+
std::size_t
39+
buffer_size(BufferSequence const& buffers);
40+
```
41+
42+
No `@tparam` needed—`BufferSequence` is evident from `@param buffers`.
43+
44+
```cpp
45+
/** Return the default value.
46+
47+
@tparam T The value type.
48+
*/
49+
template<class T>
50+
T default_value();
51+
```
52+
53+
`@tparam` needed—`T` has no corresponding function parameter.
54+
55+
## Preferences
56+
57+
- Concise, dry answers
58+
- Full files, not diffs
59+
- Accurate, compiling C++ code

0 commit comments

Comments
 (0)