fix: move critical outputs to immediately after prepare step

Previously, outputs like GITHUB_TOKEN and branch_name were set after Claude execution completed. This caused issues if Claude failed, as downstream cleanup steps wouldn't have access to these outputs.

Now outputs are set immediately after prepare() completes, ensuring they're available even if Claude execution fails.
This commit is contained in:
Ashwin Bhat
2025-08-04 16:50:24 -07:00
parent e3a4ac69fe
commit a3c96305c1

View File

@@ -80,6 +80,19 @@ async function run() {
githubToken, githubToken,
}); });
// Set critical outputs immediately after prepare completes
// This ensures they're available for cleanup even if Claude fails
core.setOutput("GITHUB_TOKEN", githubToken);
core.setOutput("mcp_config", prepareResult.mcpConfig);
if (prepareResult.branchInfo.claudeBranch) {
core.setOutput("branch_name", prepareResult.branchInfo.claudeBranch);
core.setOutput("CLAUDE_BRANCH", prepareResult.branchInfo.claudeBranch);
}
core.setOutput("BASE_BRANCH", prepareResult.branchInfo.baseBranch);
if (prepareResult.commentId) {
core.setOutput("claude_comment_id", prepareResult.commentId.toString());
}
// Step 7: The mode.prepare() call already created the prompt and set up tools // Step 7: The mode.prepare() call already created the prompt and set up tools
// We need to get the allowed/disallowed tools from environment variables // We need to get the allowed/disallowed tools from environment variables
// TODO: Update Mode interface to return tools from prepare() instead of relying on env vars // TODO: Update Mode interface to return tools from prepare() instead of relying on env vars
@@ -102,40 +115,21 @@ async function run() {
CLAUDE_CODE_ACTION: "1", CLAUDE_CODE_ACTION: "1",
}; };
// Run Claude using the shared core function await runClaudeCore({
try { promptFile,
await runClaudeCore({ settings: process.env.SETTINGS,
promptFile, allowedTools,
settings: process.env.SETTINGS, disallowedTools,
allowedTools, maxTurns: process.env.MAX_TURNS,
disallowedTools, mcpConfig: prepareResult.mcpConfig,
maxTurns: process.env.MAX_TURNS, systemPrompt: "",
mcpConfig: prepareResult.mcpConfig, appendSystemPrompt: "",
systemPrompt: "", claudeEnv: process.env.CLAUDE_ENV,
appendSystemPrompt: "", fallbackModel: process.env.FALLBACK_MODEL,
claudeEnv: process.env.CLAUDE_ENV, model: process.env.ANTHROPIC_MODEL || process.env.MODEL,
fallbackModel: process.env.FALLBACK_MODEL, timeoutMinutes: process.env.TIMEOUT_MINUTES || "30",
model: process.env.ANTHROPIC_MODEL || process.env.MODEL, env: claudeEnvObject,
timeoutMinutes: process.env.TIMEOUT_MINUTES || "30", });
env: claudeEnvObject,
});
} catch (claudeError) {
// The outputs should already be set by runClaudeCore
// Just re-throw to handle in outer catch
throw claudeError;
}
// Set outputs that were previously set by prepare step
core.setOutput("GITHUB_TOKEN", githubToken);
core.setOutput("mcp_config", prepareResult.mcpConfig);
if (prepareResult.branchInfo.claudeBranch) {
core.setOutput("branch_name", prepareResult.branchInfo.claudeBranch);
core.setOutput("CLAUDE_BRANCH", prepareResult.branchInfo.claudeBranch);
}
core.setOutput("BASE_BRANCH", prepareResult.branchInfo.baseBranch);
if (prepareResult.commentId) {
core.setOutput("claude_comment_id", prepareResult.commentId.toString());
}
} catch (error) { } catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error); const errorMessage = error instanceof Error ? error.message : String(error);
core.setFailed(`Action failed with error: ${errorMessage}`); core.setFailed(`Action failed with error: ${errorMessage}`);