mirror of
https://github.com/anthropics/claude-code-action.git
synced 2026-01-23 23:14:13 +08:00
Compare commits
1 Commits
km-anthrop
...
ashwin/inp
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5491027cea |
@@ -1,102 +0,0 @@
|
|||||||
---
|
|
||||||
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.
|
|
||||||
@@ -166,7 +166,6 @@ runs:
|
|||||||
DEFAULT_WORKFLOW_TOKEN: ${{ github.token }}
|
DEFAULT_WORKFLOW_TOKEN: ${{ github.token }}
|
||||||
ADDITIONAL_PERMISSIONS: ${{ inputs.additional_permissions }}
|
ADDITIONAL_PERMISSIONS: ${{ inputs.additional_permissions }}
|
||||||
USE_COMMIT_SIGNING: ${{ inputs.use_commit_signing }}
|
USE_COMMIT_SIGNING: ${{ inputs.use_commit_signing }}
|
||||||
ALL_INPUTS: ${{ toJson(inputs) }}
|
|
||||||
|
|
||||||
- name: Install Base Action Dependencies
|
- name: Install Base Action Dependencies
|
||||||
if: steps.prepare.outputs.contains_trigger == 'true'
|
if: steps.prepare.outputs.contains_trigger == 'true'
|
||||||
@@ -178,7 +177,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.85
|
curl -fsSL https://claude.ai/install.sh | bash -s 1.0.83
|
||||||
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
|
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
|
||||||
|
|
||||||
- name: Setup Network Restrictions
|
- name: Setup Network Restrictions
|
||||||
@@ -213,7 +212,6 @@ runs:
|
|||||||
INPUT_CLAUDE_ENV: ${{ inputs.claude_env }}
|
INPUT_CLAUDE_ENV: ${{ inputs.claude_env }}
|
||||||
INPUT_FALLBACK_MODEL: ${{ inputs.fallback_model }}
|
INPUT_FALLBACK_MODEL: ${{ inputs.fallback_model }}
|
||||||
INPUT_EXPERIMENTAL_SLASH_COMMANDS_DIR: ${{ github.action_path }}/slash-commands
|
INPUT_EXPERIMENTAL_SLASH_COMMANDS_DIR: ${{ github.action_path }}/slash-commands
|
||||||
INPUT_ACTION_INPUTS_PRESENT: ${{ steps.prepare.outputs.action_inputs_present }}
|
|
||||||
|
|
||||||
# Model configuration
|
# Model configuration
|
||||||
ANTHROPIC_MODEL: ${{ inputs.model || inputs.anthropic_model }}
|
ANTHROPIC_MODEL: ${{ inputs.model || inputs.anthropic_model }}
|
||||||
|
|||||||
@@ -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.85
|
run: curl -fsSL https://claude.ai/install.sh | bash -s 1.0.83
|
||||||
|
|
||||||
- name: Run Claude Code Action
|
- name: Run Claude Code Action
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|||||||
@@ -110,10 +110,6 @@ export function prepareRunConfig(
|
|||||||
// Parse custom environment variables
|
// Parse custom environment variables
|
||||||
const customEnv = parseCustomEnvVars(options.claudeEnv);
|
const customEnv = parseCustomEnvVars(options.claudeEnv);
|
||||||
|
|
||||||
if (process.env.INPUT_ACTION_INPUTS_PRESENT) {
|
|
||||||
customEnv.GITHUB_ACTION_INPUTS = process.env.INPUT_ACTION_INPUTS_PRESENT;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
claudeArgs,
|
claudeArgs,
|
||||||
promptPath,
|
promptPath,
|
||||||
@@ -146,11 +142,9 @@ export async function runClaude(promptPath: string, options: ClaudeOptions) {
|
|||||||
console.log(`Prompt file size: ${promptSize} bytes`);
|
console.log(`Prompt file size: ${promptSize} bytes`);
|
||||||
|
|
||||||
// Log custom environment variables if any
|
// Log custom environment variables if any
|
||||||
const customEnvKeys = Object.keys(config.env).filter(
|
if (Object.keys(config.env).length > 0) {
|
||||||
(key) => key !== "CLAUDE_ACTION_INPUTS_PRESENT",
|
const envKeys = Object.keys(config.env).join(", ");
|
||||||
);
|
console.log(`Custom environment variables: ${envKeys}`);
|
||||||
if (customEnvKeys.length > 0) {
|
|
||||||
console.log(`Custom environment variables: ${customEnvKeys.join(", ")}`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Output to console
|
// Output to console
|
||||||
@@ -175,6 +169,7 @@ export async function runClaude(promptPath: string, options: ClaudeOptions) {
|
|||||||
...config.env,
|
...config.env,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
console.log("yolo", process.env);
|
||||||
|
|
||||||
// Handle Claude process errors
|
// Handle Claude process errors
|
||||||
claudeProcess.on("error", (error) => {
|
claudeProcess.on("error", (error) => {
|
||||||
|
|||||||
@@ -1,59 +0,0 @@
|
|||||||
import * as core from "@actions/core";
|
|
||||||
|
|
||||||
export function collectActionInputsPresence(): void {
|
|
||||||
const inputDefaults: Record<string, string> = {
|
|
||||||
trigger_phrase: "@claude",
|
|
||||||
assignee_trigger: "",
|
|
||||||
label_trigger: "claude",
|
|
||||||
base_branch: "",
|
|
||||||
branch_prefix: "claude/",
|
|
||||||
allowed_bots: "",
|
|
||||||
mode: "tag",
|
|
||||||
model: "",
|
|
||||||
anthropic_model: "",
|
|
||||||
fallback_model: "",
|
|
||||||
allowed_tools: "",
|
|
||||||
disallowed_tools: "",
|
|
||||||
custom_instructions: "",
|
|
||||||
direct_prompt: "",
|
|
||||||
override_prompt: "",
|
|
||||||
mcp_config: "",
|
|
||||||
additional_permissions: "",
|
|
||||||
claude_env: "",
|
|
||||||
settings: "",
|
|
||||||
anthropic_api_key: "",
|
|
||||||
claude_code_oauth_token: "",
|
|
||||||
github_token: "",
|
|
||||||
max_turns: "",
|
|
||||||
use_sticky_comment: "false",
|
|
||||||
use_commit_signing: "false",
|
|
||||||
experimental_allowed_domains: "",
|
|
||||||
};
|
|
||||||
|
|
||||||
const allInputsJson = process.env.ALL_INPUTS;
|
|
||||||
if (!allInputsJson) {
|
|
||||||
console.log("ALL_INPUTS environment variable not found");
|
|
||||||
core.setOutput("action_inputs_present", JSON.stringify({}));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let allInputs: Record<string, string>;
|
|
||||||
try {
|
|
||||||
allInputs = JSON.parse(allInputsJson);
|
|
||||||
} catch (e) {
|
|
||||||
console.error("Failed to parse ALL_INPUTS JSON:", e);
|
|
||||||
core.setOutput("action_inputs_present", JSON.stringify({}));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const presentInputs: Record<string, boolean> = {};
|
|
||||||
|
|
||||||
for (const [name, defaultValue] of Object.entries(inputDefaults)) {
|
|
||||||
const actualValue = allInputs[name] || "";
|
|
||||||
|
|
||||||
const isSet = actualValue !== defaultValue;
|
|
||||||
presentInputs[name] = isSet;
|
|
||||||
}
|
|
||||||
|
|
||||||
core.setOutput("action_inputs_present", JSON.stringify(presentInputs));
|
|
||||||
}
|
|
||||||
@@ -13,12 +13,9 @@ import { parseGitHubContext, isEntityContext } from "../github/context";
|
|||||||
import { getMode, isValidMode, DEFAULT_MODE } from "../modes/registry";
|
import { getMode, isValidMode, DEFAULT_MODE } from "../modes/registry";
|
||||||
import type { ModeName } from "../modes/types";
|
import type { ModeName } from "../modes/types";
|
||||||
import { prepare } from "../prepare";
|
import { prepare } from "../prepare";
|
||||||
import { collectActionInputsPresence } from "./collect-inputs";
|
|
||||||
|
|
||||||
async function run() {
|
async function run() {
|
||||||
try {
|
try {
|
||||||
collectActionInputsPresence();
|
|
||||||
|
|
||||||
// Step 1: Get mode first to determine authentication method
|
// Step 1: Get mode first to determine authentication method
|
||||||
const modeInput = process.env.MODE || DEFAULT_MODE;
|
const modeInput = process.env.MODE || DEFAULT_MODE;
|
||||||
|
|
||||||
|
|||||||
@@ -3,9 +3,8 @@
|
|||||||
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, stat } from "fs/promises";
|
import { readFile } 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";
|
||||||
@@ -163,34 +162,6 @@ 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",
|
||||||
@@ -252,9 +223,6 @@ 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(
|
||||||
@@ -293,7 +261,7 @@ server.tool(
|
|||||||
// Return tree entry with blob SHA
|
// Return tree entry with blob SHA
|
||||||
return {
|
return {
|
||||||
path: filePath,
|
path: filePath,
|
||||||
mode: fileMode,
|
mode: "100644",
|
||||||
type: "blob",
|
type: "blob",
|
||||||
sha: blobData.sha,
|
sha: blobData.sha,
|
||||||
};
|
};
|
||||||
@@ -302,7 +270,7 @@ server.tool(
|
|||||||
const content = await readFile(fullPath, "utf-8");
|
const content = await readFile(fullPath, "utf-8");
|
||||||
return {
|
return {
|
||||||
path: filePath,
|
path: filePath,
|
||||||
mode: fileMode,
|
mode: "100644",
|
||||||
type: "blob",
|
type: "blob",
|
||||||
content: content,
|
content: content,
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user