mirror of
https://github.com/anthropics/claude-code-action.git
synced 2026-01-24 07:24:12 +08:00
Compare commits
3 Commits
claude/fix
...
claude/fix
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a86ef08036 | ||
|
|
9acae263e7 | ||
|
|
67bf0594ce |
@@ -127,6 +127,9 @@ outputs:
|
|||||||
structured_output:
|
structured_output:
|
||||||
description: "JSON string containing all structured output fields when --json-schema is provided in claude_args. Use fromJSON() to parse: fromJSON(steps.id.outputs.structured_output).field_name"
|
description: "JSON string containing all structured output fields when --json-schema is provided in claude_args. Use fromJSON() to parse: fromJSON(steps.id.outputs.structured_output).field_name"
|
||||||
value: ${{ steps.claude-code.outputs.structured_output }}
|
value: ${{ steps.claude-code.outputs.structured_output }}
|
||||||
|
session_id:
|
||||||
|
description: "The Claude Code session ID that can be used with --resume to continue this conversation"
|
||||||
|
value: ${{ steps.claude-code.outputs.session_id }}
|
||||||
|
|
||||||
runs:
|
runs:
|
||||||
using: "composite"
|
using: "composite"
|
||||||
@@ -195,7 +198,7 @@ runs:
|
|||||||
|
|
||||||
# Install Claude Code if no custom executable is provided
|
# Install Claude Code if no custom executable is provided
|
||||||
if [ -z "$PATH_TO_CLAUDE_CODE_EXECUTABLE" ]; then
|
if [ -z "$PATH_TO_CLAUDE_CODE_EXECUTABLE" ]; then
|
||||||
CLAUDE_CODE_VERSION="2.0.69"
|
CLAUDE_CODE_VERSION="2.0.70"
|
||||||
echo "Installing Claude Code v${CLAUDE_CODE_VERSION}..."
|
echo "Installing Claude Code v${CLAUDE_CODE_VERSION}..."
|
||||||
for attempt in 1 2 3; do
|
for attempt in 1 2 3; do
|
||||||
echo "Installation attempt $attempt..."
|
echo "Installation attempt $attempt..."
|
||||||
|
|||||||
@@ -82,6 +82,9 @@ outputs:
|
|||||||
structured_output:
|
structured_output:
|
||||||
description: "JSON string containing all structured output fields when --json-schema is provided in claude_args (use fromJSON() or jq to parse)"
|
description: "JSON string containing all structured output fields when --json-schema is provided in claude_args (use fromJSON() or jq to parse)"
|
||||||
value: ${{ steps.run_claude.outputs.structured_output }}
|
value: ${{ steps.run_claude.outputs.structured_output }}
|
||||||
|
session_id:
|
||||||
|
description: "The Claude Code session ID that can be used with --resume to continue this conversation"
|
||||||
|
value: ${{ steps.run_claude.outputs.session_id }}
|
||||||
|
|
||||||
runs:
|
runs:
|
||||||
using: "composite"
|
using: "composite"
|
||||||
@@ -121,7 +124,7 @@ runs:
|
|||||||
PATH_TO_CLAUDE_CODE_EXECUTABLE: ${{ inputs.path_to_claude_code_executable }}
|
PATH_TO_CLAUDE_CODE_EXECUTABLE: ${{ inputs.path_to_claude_code_executable }}
|
||||||
run: |
|
run: |
|
||||||
if [ -z "$PATH_TO_CLAUDE_CODE_EXECUTABLE" ]; then
|
if [ -z "$PATH_TO_CLAUDE_CODE_EXECUTABLE" ]; then
|
||||||
CLAUDE_CODE_VERSION="2.0.69"
|
CLAUDE_CODE_VERSION="2.0.70"
|
||||||
echo "Installing Claude Code v${CLAUDE_CODE_VERSION}..."
|
echo "Installing Claude Code v${CLAUDE_CODE_VERSION}..."
|
||||||
for attempt in 1 2 3; do
|
for attempt in 1 2 3; do
|
||||||
echo "Installation attempt $attempt..."
|
echo "Installation attempt $attempt..."
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
{
|
{
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
|
"configVersion": 0,
|
||||||
"workspaces": {
|
"workspaces": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@anthropic-ai/claude-code-base-action",
|
"name": "@anthropic-ai/claude-code-base-action",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.10.1",
|
"@actions/core": "^1.10.1",
|
||||||
"@anthropic-ai/claude-agent-sdk": "^0.1.52",
|
"@anthropic-ai/claude-agent-sdk": "^0.1.70",
|
||||||
"shell-quote": "^1.8.3",
|
"shell-quote": "^1.8.3",
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
@@ -26,7 +27,7 @@
|
|||||||
|
|
||||||
"@actions/io": ["@actions/io@1.1.3", "", {}, "sha512-wi9JjgKLYS7U/z8PPbco+PvTb/nRWjeoFlJ1Qer83k/3C5PHQi28hiVdeE2kHXmIL99mQFawx8qt/JPjZilJ8Q=="],
|
"@actions/io": ["@actions/io@1.1.3", "", {}, "sha512-wi9JjgKLYS7U/z8PPbco+PvTb/nRWjeoFlJ1Qer83k/3C5PHQi28hiVdeE2kHXmIL99mQFawx8qt/JPjZilJ8Q=="],
|
||||||
|
|
||||||
"@anthropic-ai/claude-agent-sdk": ["@anthropic-ai/claude-agent-sdk@0.1.52", "", { "optionalDependencies": { "@img/sharp-darwin-arm64": "^0.33.5", "@img/sharp-darwin-x64": "^0.33.5", "@img/sharp-linux-arm": "^0.33.5", "@img/sharp-linux-arm64": "^0.33.5", "@img/sharp-linux-x64": "^0.33.5", "@img/sharp-linuxmusl-arm64": "^0.33.5", "@img/sharp-linuxmusl-x64": "^0.33.5", "@img/sharp-win32-x64": "^0.33.5" }, "peerDependencies": { "zod": "^3.24.1" } }, "sha512-yF8N05+9NRbqYA/h39jQ726HTQFrdXXp7pEfDNKIJ2c4FdWvEjxBA/8ciZIebN6/PyvGDcbEp3yq2Co4rNpg6A=="],
|
"@anthropic-ai/claude-agent-sdk": ["@anthropic-ai/claude-agent-sdk@0.1.70", "", { "optionalDependencies": { "@img/sharp-darwin-arm64": "^0.33.5", "@img/sharp-darwin-x64": "^0.33.5", "@img/sharp-linux-arm": "^0.33.5", "@img/sharp-linux-arm64": "^0.33.5", "@img/sharp-linux-x64": "^0.33.5", "@img/sharp-linuxmusl-arm64": "^0.33.5", "@img/sharp-linuxmusl-x64": "^0.33.5", "@img/sharp-win32-x64": "^0.33.5" }, "peerDependencies": { "zod": "^3.24.1" } }, "sha512-4jpFPDX8asys6skO1r3Pzh0Fe9nbND2ASYTWuyFB5iN9bWEL6WScTFyGokjql3M2TkEp9ZGuB2YYpTCdaqT9Sw=="],
|
||||||
|
|
||||||
"@fastify/busboy": ["@fastify/busboy@2.1.1", "", {}, "sha512-vBZP4NlzfOlerQTnba4aqZoMhE/a9HY7HRqoOPaETQcSQuWEIyZMHGfVu6w9wGtGK5fED5qRs2DteVCjOH60sA=="],
|
"@fastify/busboy": ["@fastify/busboy@2.1.1", "", {}, "sha512-vBZP4NlzfOlerQTnba4aqZoMhE/a9HY7HRqoOPaETQcSQuWEIyZMHGfVu6w9wGtGK5fED5qRs2DteVCjOH60sA=="],
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.10.1",
|
"@actions/core": "^1.10.1",
|
||||||
"@anthropic-ai/claude-agent-sdk": "^0.1.52",
|
"@anthropic-ai/claude-agent-sdk": "^0.1.70",
|
||||||
"shell-quote": "^1.8.3"
|
"shell-quote": "^1.8.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
@@ -124,6 +124,36 @@ export function prepareRunConfig(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses session_id from execution file and sets GitHub Action output
|
||||||
|
* Exported for testing
|
||||||
|
*/
|
||||||
|
export async function parseAndSetSessionId(
|
||||||
|
executionFile: string,
|
||||||
|
): Promise<void> {
|
||||||
|
try {
|
||||||
|
const content = await readFile(executionFile, "utf-8");
|
||||||
|
const messages = JSON.parse(content) as {
|
||||||
|
type: string;
|
||||||
|
subtype?: string;
|
||||||
|
session_id?: string;
|
||||||
|
}[];
|
||||||
|
|
||||||
|
// Find the system.init message which contains session_id
|
||||||
|
const initMessage = messages.find(
|
||||||
|
(m) => m.type === "system" && m.subtype === "init",
|
||||||
|
);
|
||||||
|
|
||||||
|
if (initMessage?.session_id) {
|
||||||
|
core.setOutput("session_id", initMessage.session_id);
|
||||||
|
core.info(`Set session_id: ${initMessage.session_id}`);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
// Don't fail the action if session_id extraction fails
|
||||||
|
core.warning(`Failed to extract session_id: ${error}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses structured_output from execution file and sets GitHub Action outputs
|
* Parses structured_output from execution file and sets GitHub Action outputs
|
||||||
* Only runs if --json-schema was explicitly provided in claude_args
|
* Only runs if --json-schema was explicitly provided in claude_args
|
||||||
@@ -368,6 +398,9 @@ export async function runClaude(promptPath: string, options: ClaudeOptions) {
|
|||||||
|
|
||||||
core.setOutput("execution_file", EXECUTION_FILE);
|
core.setOutput("execution_file", EXECUTION_FILE);
|
||||||
|
|
||||||
|
// Extract and set session_id
|
||||||
|
await parseAndSetSessionId(EXECUTION_FILE);
|
||||||
|
|
||||||
// Parse and set structured outputs only if user provided --json-schema in claude_args
|
// Parse and set structured outputs only if user provided --json-schema in claude_args
|
||||||
if (hasJsonSchema) {
|
if (hasJsonSchema) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -4,7 +4,10 @@ import { describe, test, expect, afterEach, beforeEach, spyOn } from "bun:test";
|
|||||||
import { writeFile, unlink } from "fs/promises";
|
import { writeFile, unlink } from "fs/promises";
|
||||||
import { tmpdir } from "os";
|
import { tmpdir } from "os";
|
||||||
import { join } from "path";
|
import { join } from "path";
|
||||||
import { parseAndSetStructuredOutputs } from "../src/run-claude";
|
import {
|
||||||
|
parseAndSetStructuredOutputs,
|
||||||
|
parseAndSetSessionId,
|
||||||
|
} from "../src/run-claude";
|
||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
|
|
||||||
// Mock execution file path
|
// Mock execution file path
|
||||||
@@ -35,16 +38,19 @@ async function createMockExecutionFile(
|
|||||||
// Spy on core functions
|
// Spy on core functions
|
||||||
let setOutputSpy: any;
|
let setOutputSpy: any;
|
||||||
let infoSpy: any;
|
let infoSpy: any;
|
||||||
|
let warningSpy: any;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
setOutputSpy = spyOn(core, "setOutput").mockImplementation(() => {});
|
setOutputSpy = spyOn(core, "setOutput").mockImplementation(() => {});
|
||||||
infoSpy = spyOn(core, "info").mockImplementation(() => {});
|
infoSpy = spyOn(core, "info").mockImplementation(() => {});
|
||||||
|
warningSpy = spyOn(core, "warning").mockImplementation(() => {});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("parseAndSetStructuredOutputs", () => {
|
describe("parseAndSetStructuredOutputs", () => {
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
setOutputSpy?.mockRestore();
|
setOutputSpy?.mockRestore();
|
||||||
infoSpy?.mockRestore();
|
infoSpy?.mockRestore();
|
||||||
|
warningSpy?.mockRestore();
|
||||||
try {
|
try {
|
||||||
await unlink(TEST_EXECUTION_FILE);
|
await unlink(TEST_EXECUTION_FILE);
|
||||||
} catch {
|
} catch {
|
||||||
@@ -156,3 +162,66 @@ describe("parseAndSetStructuredOutputs", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("parseAndSetSessionId", () => {
|
||||||
|
afterEach(async () => {
|
||||||
|
setOutputSpy?.mockRestore();
|
||||||
|
infoSpy?.mockRestore();
|
||||||
|
warningSpy?.mockRestore();
|
||||||
|
try {
|
||||||
|
await unlink(TEST_EXECUTION_FILE);
|
||||||
|
} catch {
|
||||||
|
// Ignore if file doesn't exist
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test("should extract session_id from system.init message", async () => {
|
||||||
|
const messages = [
|
||||||
|
{ type: "system", subtype: "init", session_id: "test-session-123" },
|
||||||
|
{ type: "result", cost_usd: 0.01 },
|
||||||
|
];
|
||||||
|
await writeFile(TEST_EXECUTION_FILE, JSON.stringify(messages));
|
||||||
|
|
||||||
|
await parseAndSetSessionId(TEST_EXECUTION_FILE);
|
||||||
|
|
||||||
|
expect(setOutputSpy).toHaveBeenCalledWith("session_id", "test-session-123");
|
||||||
|
expect(infoSpy).toHaveBeenCalledWith("Set session_id: test-session-123");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("should handle missing session_id gracefully", async () => {
|
||||||
|
const messages = [
|
||||||
|
{ type: "system", subtype: "init" },
|
||||||
|
{ type: "result", cost_usd: 0.01 },
|
||||||
|
];
|
||||||
|
await writeFile(TEST_EXECUTION_FILE, JSON.stringify(messages));
|
||||||
|
|
||||||
|
await parseAndSetSessionId(TEST_EXECUTION_FILE);
|
||||||
|
|
||||||
|
expect(setOutputSpy).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("should handle missing system.init message gracefully", async () => {
|
||||||
|
const messages = [{ type: "result", cost_usd: 0.01 }];
|
||||||
|
await writeFile(TEST_EXECUTION_FILE, JSON.stringify(messages));
|
||||||
|
|
||||||
|
await parseAndSetSessionId(TEST_EXECUTION_FILE);
|
||||||
|
|
||||||
|
expect(setOutputSpy).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("should handle malformed JSON gracefully with warning", async () => {
|
||||||
|
await writeFile(TEST_EXECUTION_FILE, "{ invalid json");
|
||||||
|
|
||||||
|
await parseAndSetSessionId(TEST_EXECUTION_FILE);
|
||||||
|
|
||||||
|
expect(setOutputSpy).not.toHaveBeenCalled();
|
||||||
|
expect(warningSpy).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("should handle non-existent file gracefully with warning", async () => {
|
||||||
|
await parseAndSetSessionId("/nonexistent/file.json");
|
||||||
|
|
||||||
|
expect(setOutputSpy).not.toHaveBeenCalled();
|
||||||
|
expect(warningSpy).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
5
bun.lock
5
bun.lock
@@ -1,12 +1,13 @@
|
|||||||
{
|
{
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
|
"configVersion": 0,
|
||||||
"workspaces": {
|
"workspaces": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@anthropic-ai/claude-code-action",
|
"name": "@anthropic-ai/claude-code-action",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.10.1",
|
"@actions/core": "^1.10.1",
|
||||||
"@actions/github": "^6.0.1",
|
"@actions/github": "^6.0.1",
|
||||||
"@anthropic-ai/claude-agent-sdk": "^0.1.52",
|
"@anthropic-ai/claude-agent-sdk": "^0.1.70",
|
||||||
"@modelcontextprotocol/sdk": "^1.11.0",
|
"@modelcontextprotocol/sdk": "^1.11.0",
|
||||||
"@octokit/graphql": "^8.2.2",
|
"@octokit/graphql": "^8.2.2",
|
||||||
"@octokit/rest": "^21.1.1",
|
"@octokit/rest": "^21.1.1",
|
||||||
@@ -36,7 +37,7 @@
|
|||||||
|
|
||||||
"@actions/io": ["@actions/io@1.1.3", "", {}, "sha512-wi9JjgKLYS7U/z8PPbco+PvTb/nRWjeoFlJ1Qer83k/3C5PHQi28hiVdeE2kHXmIL99mQFawx8qt/JPjZilJ8Q=="],
|
"@actions/io": ["@actions/io@1.1.3", "", {}, "sha512-wi9JjgKLYS7U/z8PPbco+PvTb/nRWjeoFlJ1Qer83k/3C5PHQi28hiVdeE2kHXmIL99mQFawx8qt/JPjZilJ8Q=="],
|
||||||
|
|
||||||
"@anthropic-ai/claude-agent-sdk": ["@anthropic-ai/claude-agent-sdk@0.1.52", "", { "optionalDependencies": { "@img/sharp-darwin-arm64": "^0.33.5", "@img/sharp-darwin-x64": "^0.33.5", "@img/sharp-linux-arm": "^0.33.5", "@img/sharp-linux-arm64": "^0.33.5", "@img/sharp-linux-x64": "^0.33.5", "@img/sharp-linuxmusl-arm64": "^0.33.5", "@img/sharp-linuxmusl-x64": "^0.33.5", "@img/sharp-win32-x64": "^0.33.5" }, "peerDependencies": { "zod": "^3.24.1" } }, "sha512-yF8N05+9NRbqYA/h39jQ726HTQFrdXXp7pEfDNKIJ2c4FdWvEjxBA/8ciZIebN6/PyvGDcbEp3yq2Co4rNpg6A=="],
|
"@anthropic-ai/claude-agent-sdk": ["@anthropic-ai/claude-agent-sdk@0.1.70", "", { "optionalDependencies": { "@img/sharp-darwin-arm64": "^0.33.5", "@img/sharp-darwin-x64": "^0.33.5", "@img/sharp-linux-arm": "^0.33.5", "@img/sharp-linux-arm64": "^0.33.5", "@img/sharp-linux-x64": "^0.33.5", "@img/sharp-linuxmusl-arm64": "^0.33.5", "@img/sharp-linuxmusl-x64": "^0.33.5", "@img/sharp-win32-x64": "^0.33.5" }, "peerDependencies": { "zod": "^3.24.1" } }, "sha512-4jpFPDX8asys6skO1r3Pzh0Fe9nbND2ASYTWuyFB5iN9bWEL6WScTFyGokjql3M2TkEp9ZGuB2YYpTCdaqT9Sw=="],
|
||||||
|
|
||||||
"@fastify/busboy": ["@fastify/busboy@2.1.1", "", {}, "sha512-vBZP4NlzfOlerQTnba4aqZoMhE/a9HY7HRqoOPaETQcSQuWEIyZMHGfVu6w9wGtGK5fED5qRs2DteVCjOH60sA=="],
|
"@fastify/busboy": ["@fastify/busboy@2.1.1", "", {}, "sha512-vBZP4NlzfOlerQTnba4aqZoMhE/a9HY7HRqoOPaETQcSQuWEIyZMHGfVu6w9wGtGK5fED5qRs2DteVCjOH60sA=="],
|
||||||
|
|
||||||
|
|||||||
@@ -35,8 +35,11 @@ jobs:
|
|||||||
|
|
||||||
- name: Create fix branch
|
- name: Create fix branch
|
||||||
id: branch
|
id: branch
|
||||||
|
env:
|
||||||
|
SOURCE_BRANCH: ${{ github.event.workflow_run.head_branch }}
|
||||||
|
RUN_ID: ${{ github.run_id }}
|
||||||
run: |
|
run: |
|
||||||
BRANCH_NAME="claude-auto-fix-ci-${{ github.event.workflow_run.head_branch }}-${{ github.run_id }}"
|
BRANCH_NAME="claude-auto-fix-ci-${SOURCE_BRANCH}-${RUN_ID}"
|
||||||
git checkout -b "$BRANCH_NAME"
|
git checkout -b "$BRANCH_NAME"
|
||||||
echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT
|
echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ jobs:
|
|||||||
fromJSON(steps.detect.outputs.structured_output).confidence >= 0.7
|
fromJSON(steps.detect.outputs.structured_output).confidence >= 0.7
|
||||||
env:
|
env:
|
||||||
GH_TOKEN: ${{ github.token }}
|
GH_TOKEN: ${{ github.token }}
|
||||||
|
WORKFLOW_NAME: ${{ github.event.workflow_run.name }}
|
||||||
HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }}
|
HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }}
|
||||||
run: |
|
run: |
|
||||||
OUTPUT='${{ steps.detect.outputs.structured_output }}'
|
OUTPUT='${{ steps.detect.outputs.structured_output }}'
|
||||||
@@ -64,7 +65,7 @@ jobs:
|
|||||||
echo ""
|
echo ""
|
||||||
echo "Triggering automatic retry..."
|
echo "Triggering automatic retry..."
|
||||||
|
|
||||||
gh workflow run "${{ github.event.workflow_run.name }}" \
|
gh workflow run "$WORKFLOW_NAME" \
|
||||||
--ref "$HEAD_BRANCH"
|
--ref "$HEAD_BRANCH"
|
||||||
|
|
||||||
# Low confidence flaky detection - skip retry
|
# Low confidence flaky detection - skip retry
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.10.1",
|
"@actions/core": "^1.10.1",
|
||||||
"@actions/github": "^6.0.1",
|
"@actions/github": "^6.0.1",
|
||||||
"@anthropic-ai/claude-agent-sdk": "^0.1.52",
|
"@anthropic-ai/claude-agent-sdk": "^0.1.70",
|
||||||
"@modelcontextprotocol/sdk": "^1.11.0",
|
"@modelcontextprotocol/sdk": "^1.11.0",
|
||||||
"@octokit/graphql": "^8.2.2",
|
"@octokit/graphql": "^8.2.2",
|
||||||
"@octokit/rest": "^21.1.1",
|
"@octokit/rest": "^21.1.1",
|
||||||
|
|||||||
Reference in New Issue
Block a user