Replace claude-code-base-action with direct Claude Code execution
The claude-code-base-action doesn't support OAuth authentication. This change bypasses the base action entirely and runs Claude Code directly. Changes: - Add Node.js setup step - Add Claude Code installation step - Replace uses: claude-code-base-action with direct shell script execution - Handle OAuth by not setting ANTHROPIC_API_KEY when using OAuth - Set up MCP configuration manually - Simplify environment variables to only what's needed This allows OAuth credentials to be used properly since Claude Code will check the credentials file when ANTHROPIC_API_KEY is empty.
This commit is contained in:
108
action.yml
108
action.yml
@@ -111,60 +111,74 @@ runs:
|
||||
ANTHROPIC_API_KEY: ${{ inputs.anthropic_api_key != 'use-oauth' && inputs.anthropic_api_key || '' }}
|
||||
CLAUDE_CREDENTIALS: ${{ inputs.claude_credentials }}
|
||||
|
||||
- name: Setup Node.js
|
||||
if: steps.prepare.outputs.contains_trigger == 'true'
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '18'
|
||||
|
||||
- name: Install Claude Code
|
||||
if: steps.prepare.outputs.contains_trigger == 'true'
|
||||
shell: bash
|
||||
run: |
|
||||
echo "Installing Claude Code..."
|
||||
npm install -g @anthropic-ai/claude-code@latest
|
||||
|
||||
- name: Run Claude Code
|
||||
id: claude-code
|
||||
if: steps.prepare.outputs.contains_trigger == 'true'
|
||||
uses: anthropics/claude-code-base-action@v0.0.24
|
||||
with:
|
||||
prompt_file: /tmp/claude-prompts/claude-prompt.txt
|
||||
allowed_tools: ${{ env.ALLOWED_TOOLS }}
|
||||
disallowed_tools: ${{ env.DISALLOWED_TOOLS }}
|
||||
timeout_minutes: ${{ inputs.timeout_minutes }}
|
||||
model: ${{ inputs.model || inputs.anthropic_model }}
|
||||
mcp_config: ${{ steps.prepare.outputs.mcp_config }}
|
||||
# Workaround: pretend to use bedrock when using OAuth to bypass validation
|
||||
use_bedrock: ${{ inputs.use_bedrock || inputs.anthropic_api_key == 'use-oauth' }}
|
||||
use_vertex: ${{ inputs.use_vertex }}
|
||||
# Pass empty string when using OAuth to avoid base action validation issues
|
||||
anthropic_api_key: ${{ inputs.anthropic_api_key == 'use-oauth' && '' || inputs.anthropic_api_key }}
|
||||
shell: bash
|
||||
run: |
|
||||
# Run Claude Code directly when using OAuth
|
||||
if [ "${{ inputs.anthropic_api_key }}" = "use-oauth" ]; then
|
||||
echo "Running Claude Code with OAuth authentication"
|
||||
# Export empty ANTHROPIC_API_KEY to ensure OAuth credentials are used
|
||||
export ANTHROPIC_API_KEY=""
|
||||
else
|
||||
echo "Running Claude Code with API key authentication"
|
||||
export ANTHROPIC_API_KEY="${{ inputs.anthropic_api_key }}"
|
||||
fi
|
||||
|
||||
# Set up other environment variables
|
||||
export ALLOWED_TOOLS="${{ env.ALLOWED_TOOLS }}"
|
||||
export DISALLOWED_TOOLS="${{ env.DISALLOWED_TOOLS }}"
|
||||
export MCP_CONFIG='${{ steps.prepare.outputs.mcp_config }}'
|
||||
export MODEL="${{ inputs.model || inputs.anthropic_model }}"
|
||||
export ANTHROPIC_MODEL="${{ inputs.model || inputs.anthropic_model }}"
|
||||
export TIMEOUT_MINUTES="${{ inputs.timeout_minutes }}"
|
||||
export PROMPT_FILE="/tmp/claude-prompts/claude-prompt.txt"
|
||||
|
||||
# Set up MCP configuration
|
||||
mkdir -p ~/.config/claude-code
|
||||
echo "$MCP_CONFIG" > ~/.config/claude-code/mcp-config.json
|
||||
|
||||
# Run Claude Code
|
||||
OUTPUT_FILE="/tmp/claude-code-output-$(date +%s).json"
|
||||
if claude-code --prompt-file "$PROMPT_FILE" \
|
||||
--output-file "$OUTPUT_FILE" \
|
||||
--allowed-tools "$ALLOWED_TOOLS" \
|
||||
--disallowed-tools "$DISALLOWED_TOOLS" \
|
||||
--model "$MODEL" \
|
||||
--timeout "${TIMEOUT_MINUTES}m" \
|
||||
--mcp-config ~/.config/claude-code/mcp-config.json; then
|
||||
echo "Claude Code execution succeeded"
|
||||
echo "execution_file=$OUTPUT_FILE" >> $GITHUB_OUTPUT
|
||||
echo "conclusion=success" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "Claude Code execution failed"
|
||||
echo "conclusion=failure" >> $GITHUB_OUTPUT
|
||||
exit 1
|
||||
fi
|
||||
env:
|
||||
# Core configuration
|
||||
PROMPT_FILE: /tmp/claude-prompts/claude-prompt.txt
|
||||
ALLOWED_TOOLS: ${{ env.ALLOWED_TOOLS }}
|
||||
DISALLOWED_TOOLS: ${{ env.DISALLOWED_TOOLS }}
|
||||
TIMEOUT_MINUTES: ${{ inputs.timeout_minutes }}
|
||||
MODEL: ${{ inputs.model || inputs.anthropic_model }}
|
||||
ANTHROPIC_MODEL: ${{ inputs.model || inputs.anthropic_model }}
|
||||
MCP_CONFIG: ${{ steps.prepare.outputs.mcp_config }}
|
||||
# Workaround: pretend to use bedrock when using OAuth to bypass validation
|
||||
USE_BEDROCK: ${{ inputs.use_bedrock || inputs.anthropic_api_key == 'use-oauth' }}
|
||||
USE_VERTEX: ${{ inputs.use_vertex }}
|
||||
# Don't set ANTHROPIC_API_KEY when using OAuth
|
||||
ANTHROPIC_API_KEY: ${{ inputs.anthropic_api_key != 'use-oauth' && inputs.anthropic_api_key || '' }}
|
||||
CLAUDE_CREDENTIALS: ${{ inputs.claude_credentials }}
|
||||
|
||||
# GitHub token for repository access
|
||||
GITHUB_TOKEN: ${{ steps.prepare.outputs.GITHUB_TOKEN }}
|
||||
GITEA_API_URL: ${{ env.GITHUB_SERVER_URL }}
|
||||
|
||||
# Git configuration
|
||||
CLAUDE_GIT_NAME: ${{ inputs.claude_git_name }}
|
||||
CLAUDE_GIT_EMAIL: ${{ inputs.claude_git_email }}
|
||||
|
||||
# Provider configuration (for future cloud provider support)
|
||||
ANTHROPIC_BASE_URL: ${{ env.ANTHROPIC_BASE_URL }}
|
||||
AWS_REGION: ${{ env.AWS_REGION }}
|
||||
AWS_ACCESS_KEY_ID: ${{ env.AWS_ACCESS_KEY_ID }}
|
||||
AWS_SECRET_ACCESS_KEY: ${{ env.AWS_SECRET_ACCESS_KEY }}
|
||||
AWS_SESSION_TOKEN: ${{ env.AWS_SESSION_TOKEN }}
|
||||
ANTHROPIC_BEDROCK_BASE_URL: ${{ env.ANTHROPIC_BEDROCK_BASE_URL }}
|
||||
ANTHROPIC_VERTEX_PROJECT_ID: ${{ env.ANTHROPIC_VERTEX_PROJECT_ID }}
|
||||
CLOUD_ML_REGION: ${{ env.CLOUD_ML_REGION }}
|
||||
GOOGLE_APPLICATION_CREDENTIALS: ${{ env.GOOGLE_APPLICATION_CREDENTIALS }}
|
||||
ANTHROPIC_VERTEX_BASE_URL: ${{ env.ANTHROPIC_VERTEX_BASE_URL }}
|
||||
VERTEX_REGION_CLAUDE_3_5_HAIKU: ${{ env.VERTEX_REGION_CLAUDE_3_5_HAIKU }}
|
||||
VERTEX_REGION_CLAUDE_3_5_SONNET: ${{ env.VERTEX_REGION_CLAUDE_3_5_SONNET }}
|
||||
VERTEX_REGION_CLAUDE_3_7_SONNET: ${{ env.VERTEX_REGION_CLAUDE_3_7_SONNET }}
|
||||
|
||||
# Git configuration for Claude Code
|
||||
GIT_AUTHOR_NAME: ${{ inputs.claude_git_name }}
|
||||
GIT_AUTHOR_EMAIL: ${{ inputs.claude_git_email }}
|
||||
GIT_COMMITTER_NAME: ${{ inputs.claude_git_name }}
|
||||
GIT_COMMITTER_EMAIL: ${{ inputs.claude_git_email }}
|
||||
|
||||
- name: Update comment with job link
|
||||
if: steps.prepare.outputs.contains_trigger == 'true' && steps.prepare.outputs.claude_comment_id && always()
|
||||
|
||||
Reference in New Issue
Block a user