From 68b7ca379c023e06c7d12ad2c81e346b1670cf8c Mon Sep 17 00:00:00 2001 From: Ashwin Bhat Date: Mon, 18 Aug 2025 17:00:18 -0700 Subject: [PATCH] include input bools in claude env (#464) --- action.yml | 2 ++ base-action/src/run-claude.ts | 12 +++++-- src/entrypoints/collect-inputs.ts | 59 +++++++++++++++++++++++++++++++ src/entrypoints/prepare.ts | 3 ++ 4 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 src/entrypoints/collect-inputs.ts diff --git a/action.yml b/action.yml index ed5bc77..d4631fb 100644 --- a/action.yml +++ b/action.yml @@ -166,6 +166,7 @@ runs: DEFAULT_WORKFLOW_TOKEN: ${{ github.token }} ADDITIONAL_PERMISSIONS: ${{ inputs.additional_permissions }} USE_COMMIT_SIGNING: ${{ inputs.use_commit_signing }} + ALL_INPUTS: ${{ toJson(inputs) }} - name: Install Base Action Dependencies if: steps.prepare.outputs.contains_trigger == 'true' @@ -212,6 +213,7 @@ runs: INPUT_CLAUDE_ENV: ${{ inputs.claude_env }} INPUT_FALLBACK_MODEL: ${{ inputs.fallback_model }} INPUT_EXPERIMENTAL_SLASH_COMMANDS_DIR: ${{ github.action_path }}/slash-commands + INPUT_ACTION_INPUTS_PRESENT: ${{ steps.prepare.outputs.action_inputs_present }} # Model configuration ANTHROPIC_MODEL: ${{ inputs.model || inputs.anthropic_model }} diff --git a/base-action/src/run-claude.ts b/base-action/src/run-claude.ts index 70e38d7..0edfa72 100644 --- a/base-action/src/run-claude.ts +++ b/base-action/src/run-claude.ts @@ -110,6 +110,10 @@ export function prepareRunConfig( // Parse custom environment variables const customEnv = parseCustomEnvVars(options.claudeEnv); + if (process.env.INPUT_ACTION_INPUTS_PRESENT) { + customEnv.GITHUB_ACTION_INPUTS = process.env.INPUT_ACTION_INPUTS_PRESENT; + } + return { claudeArgs, promptPath, @@ -142,9 +146,11 @@ export async function runClaude(promptPath: string, options: ClaudeOptions) { console.log(`Prompt file size: ${promptSize} bytes`); // Log custom environment variables if any - if (Object.keys(config.env).length > 0) { - const envKeys = Object.keys(config.env).join(", "); - console.log(`Custom environment variables: ${envKeys}`); + const customEnvKeys = Object.keys(config.env).filter( + (key) => key !== "CLAUDE_ACTION_INPUTS_PRESENT", + ); + if (customEnvKeys.length > 0) { + console.log(`Custom environment variables: ${customEnvKeys.join(", ")}`); } // Output to console diff --git a/src/entrypoints/collect-inputs.ts b/src/entrypoints/collect-inputs.ts new file mode 100644 index 0000000..501a438 --- /dev/null +++ b/src/entrypoints/collect-inputs.ts @@ -0,0 +1,59 @@ +import * as core from "@actions/core"; + +export function collectActionInputsPresence(): void { + const inputDefaults: Record = { + 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; + 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 = {}; + + 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)); +} diff --git a/src/entrypoints/prepare.ts b/src/entrypoints/prepare.ts index b9995df..b151590 100644 --- a/src/entrypoints/prepare.ts +++ b/src/entrypoints/prepare.ts @@ -13,9 +13,12 @@ import { parseGitHubContext, isEntityContext } from "../github/context"; import { getMode, isValidMode, DEFAULT_MODE } from "../modes/registry"; import type { ModeName } from "../modes/types"; import { prepare } from "../prepare"; +import { collectActionInputsPresence } from "./collect-inputs"; async function run() { try { + collectActionInputsPresence(); + // Step 1: Get mode first to determine authentication method const modeInput = process.env.MODE || DEFAULT_MODE;