mirror of
https://github.com/anthropics/claude-code-action.git
synced 2026-01-23 23:14:13 +08:00
Compare commits
3 Commits
v0.0.60
...
km-anthrop
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fd8478624b | ||
|
|
194fca8b05 | ||
|
|
0f913a6e0e |
102
.claude/commands/fix-ci.md
Normal file
102
.claude/commands/fix-ci.md
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
---
|
||||||
|
description: Analyze and fix CI failures by examining logs and making targeted fixes
|
||||||
|
allowed_tools: Edit,MultiEdit,Write,Read,Glob,Grep,LS,Bash(git:*),Bash(bun:*),Bash(npm:*),Bash(npx:*),Bash(gh:*)
|
||||||
|
---
|
||||||
|
|
||||||
|
# Fix CI Failures
|
||||||
|
|
||||||
|
You are tasked with analyzing CI failure logs and fixing the issues. Follow these steps:
|
||||||
|
|
||||||
|
## Context Provided
|
||||||
|
|
||||||
|
$ARGUMENTS
|
||||||
|
|
||||||
|
## Important Context Information
|
||||||
|
|
||||||
|
Look for these key pieces of information in the arguments:
|
||||||
|
|
||||||
|
- **Failed CI Run URL**: Link to the failed CI run
|
||||||
|
- **Failed Jobs**: List of jobs that failed
|
||||||
|
- **PR Number**: The PR number to comment on
|
||||||
|
- **Branch Name**: The fix branch you're working on
|
||||||
|
- **Base Branch**: The original PR branch
|
||||||
|
- **Error logs**: Detailed logs from failed jobs
|
||||||
|
|
||||||
|
## Step 1: Analyze the Failure
|
||||||
|
|
||||||
|
Parse the provided CI failure information to understand:
|
||||||
|
|
||||||
|
- Which jobs failed and why
|
||||||
|
- The specific error messages and stack traces
|
||||||
|
- Whether failures are test-related, build-related, or linting issues
|
||||||
|
|
||||||
|
## Step 2: Search and Understand the Codebase
|
||||||
|
|
||||||
|
Use search tools to locate the failing code:
|
||||||
|
|
||||||
|
- Search for the failing test names or functions
|
||||||
|
- Find the source files mentioned in error messages
|
||||||
|
- Review related configuration files (package.json, tsconfig.json, etc.)
|
||||||
|
|
||||||
|
## Step 3: Apply Targeted Fixes
|
||||||
|
|
||||||
|
Make minimal, focused changes:
|
||||||
|
|
||||||
|
- **For test failures**: Determine if the test or implementation needs fixing
|
||||||
|
- **For type errors**: Fix type definitions or correct the code logic
|
||||||
|
- **For linting issues**: Apply formatting using the project's tools
|
||||||
|
- **For build errors**: Resolve dependency or configuration issues
|
||||||
|
- **For missing imports**: Add the necessary imports or install packages
|
||||||
|
|
||||||
|
Requirements:
|
||||||
|
|
||||||
|
- Only fix the actual CI failures, avoid unrelated changes
|
||||||
|
- Follow existing code patterns and conventions
|
||||||
|
- Ensure changes are production-ready, not temporary hacks
|
||||||
|
- Preserve existing functionality while fixing issues
|
||||||
|
|
||||||
|
## Step 4: Commit and Push Changes
|
||||||
|
|
||||||
|
After applying ALL fixes:
|
||||||
|
|
||||||
|
1. Stage all modified files with `git add -A`
|
||||||
|
2. Commit with: `git commit -m "Fix CI failures: [describe specific fixes]"`
|
||||||
|
3. Document which CI jobs/tests were addressed
|
||||||
|
4. **CRITICAL**: Push the branch with `git push origin HEAD` - You MUST push the branch after committing
|
||||||
|
|
||||||
|
## Step 5: Create PR Comment
|
||||||
|
|
||||||
|
After successfully pushing the fixes, create a comment on the original PR to notify about the auto-fix:
|
||||||
|
|
||||||
|
1. Extract the PR number, branch name, and base branch from the context provided
|
||||||
|
2. Use gh CLI to create a comment with the fix information
|
||||||
|
3. Include a link to create a pull request from the fix branch
|
||||||
|
|
||||||
|
Use this command format (replace placeholders with actual values):
|
||||||
|
```bash
|
||||||
|
gh pr comment PR_NUMBER --body "## 🤖 CI Auto-Fix Available
|
||||||
|
|
||||||
|
Claude has analyzed the CI failures and prepared fixes.
|
||||||
|
|
||||||
|
[**→ Create pull request to fix CI**](https://github.com/OWNER/REPO/compare/BASE_BRANCH...FIX_BRANCH?quick_pull=1)
|
||||||
|
|
||||||
|
_This fix was generated automatically based on the failed CI run._"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Step 6: Verify Fixes Locally
|
||||||
|
|
||||||
|
Run available verification commands:
|
||||||
|
|
||||||
|
- Execute the failing tests locally to confirm they pass
|
||||||
|
- Run the project's lint command (check package.json for scripts)
|
||||||
|
- Run type checking if available
|
||||||
|
- Execute any build commands to ensure compilation succeeds
|
||||||
|
|
||||||
|
## Important Guidelines
|
||||||
|
|
||||||
|
- Focus exclusively on fixing the reported CI failures
|
||||||
|
- Maintain code quality and follow the project's established patterns
|
||||||
|
- If a fix requires significant refactoring, document why it's necessary
|
||||||
|
- When multiple solutions exist, choose the simplest one that maintains code quality
|
||||||
|
|
||||||
|
Begin by analyzing the failure details provided above.
|
||||||
@@ -178,7 +178,7 @@ runs:
|
|||||||
echo "Base-action dependencies installed"
|
echo "Base-action dependencies installed"
|
||||||
cd -
|
cd -
|
||||||
# Install Claude Code globally
|
# Install Claude Code globally
|
||||||
curl -fsSL https://claude.ai/install.sh | bash -s 1.0.84
|
curl -fsSL https://claude.ai/install.sh | bash -s 1.0.85
|
||||||
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
|
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
|
||||||
|
|
||||||
- name: Setup Network Restrictions
|
- name: Setup Network Restrictions
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ runs:
|
|||||||
|
|
||||||
- name: Install Claude Code
|
- name: Install Claude Code
|
||||||
shell: bash
|
shell: bash
|
||||||
run: curl -fsSL https://claude.ai/install.sh | bash -s 1.0.84
|
run: curl -fsSL https://claude.ai/install.sh | bash -s 1.0.85
|
||||||
|
|
||||||
- name: Run Claude Code Action
|
- name: Run Claude Code Action
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|||||||
@@ -3,8 +3,9 @@
|
|||||||
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
||||||
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { readFile } from "fs/promises";
|
import { readFile, stat } from "fs/promises";
|
||||||
import { join } from "path";
|
import { join } from "path";
|
||||||
|
import { constants } from "fs";
|
||||||
import fetch from "node-fetch";
|
import fetch from "node-fetch";
|
||||||
import { GITHUB_API_URL } from "../github/api/config";
|
import { GITHUB_API_URL } from "../github/api/config";
|
||||||
import { retryWithBackoff } from "../utils/retry";
|
import { retryWithBackoff } from "../utils/retry";
|
||||||
@@ -162,6 +163,34 @@ async function getOrCreateBranchRef(
|
|||||||
return baseSha;
|
return baseSha;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the appropriate Git file mode for a file
|
||||||
|
async function getFileMode(filePath: string): Promise<string> {
|
||||||
|
try {
|
||||||
|
const fileStat = await stat(filePath);
|
||||||
|
if (fileStat.isFile()) {
|
||||||
|
// Check if execute bit is set for user
|
||||||
|
if (fileStat.mode & constants.S_IXUSR) {
|
||||||
|
return "100755"; // Executable file
|
||||||
|
} else {
|
||||||
|
return "100644"; // Regular file
|
||||||
|
}
|
||||||
|
} else if (fileStat.isDirectory()) {
|
||||||
|
return "040000"; // Directory (tree)
|
||||||
|
} else if (fileStat.isSymbolicLink()) {
|
||||||
|
return "120000"; // Symbolic link
|
||||||
|
} else {
|
||||||
|
// Fallback for unknown file types
|
||||||
|
return "100644";
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
// If we can't stat the file, default to regular file
|
||||||
|
console.warn(
|
||||||
|
`Could not determine file mode for ${filePath}, using default: ${error}`,
|
||||||
|
);
|
||||||
|
return "100644";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Commit files tool
|
// Commit files tool
|
||||||
server.tool(
|
server.tool(
|
||||||
"commit_files",
|
"commit_files",
|
||||||
@@ -223,6 +252,9 @@ server.tool(
|
|||||||
? filePath
|
? filePath
|
||||||
: join(REPO_DIR, filePath);
|
: join(REPO_DIR, filePath);
|
||||||
|
|
||||||
|
// Get the proper file mode based on file permissions
|
||||||
|
const fileMode = await getFileMode(fullPath);
|
||||||
|
|
||||||
// Check if file is binary (images, etc.)
|
// Check if file is binary (images, etc.)
|
||||||
const isBinaryFile =
|
const isBinaryFile =
|
||||||
/\.(png|jpg|jpeg|gif|webp|ico|pdf|zip|tar|gz|exe|bin|woff|woff2|ttf|eot)$/i.test(
|
/\.(png|jpg|jpeg|gif|webp|ico|pdf|zip|tar|gz|exe|bin|woff|woff2|ttf|eot)$/i.test(
|
||||||
@@ -261,7 +293,7 @@ server.tool(
|
|||||||
// Return tree entry with blob SHA
|
// Return tree entry with blob SHA
|
||||||
return {
|
return {
|
||||||
path: filePath,
|
path: filePath,
|
||||||
mode: "100644",
|
mode: fileMode,
|
||||||
type: "blob",
|
type: "blob",
|
||||||
sha: blobData.sha,
|
sha: blobData.sha,
|
||||||
};
|
};
|
||||||
@@ -270,7 +302,7 @@ server.tool(
|
|||||||
const content = await readFile(fullPath, "utf-8");
|
const content = await readFile(fullPath, "utf-8");
|
||||||
return {
|
return {
|
||||||
path: filePath,
|
path: filePath,
|
||||||
mode: "100644",
|
mode: fileMode,
|
||||||
type: "blob",
|
type: "blob",
|
||||||
content: content,
|
content: content,
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user