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:
106
action.yml
106
action.yml
@@ -111,60 +111,74 @@ runs:
|
|||||||
ANTHROPIC_API_KEY: ${{ inputs.anthropic_api_key != 'use-oauth' && inputs.anthropic_api_key || '' }}
|
ANTHROPIC_API_KEY: ${{ inputs.anthropic_api_key != 'use-oauth' && inputs.anthropic_api_key || '' }}
|
||||||
CLAUDE_CREDENTIALS: ${{ inputs.claude_credentials }}
|
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
|
- name: Run Claude Code
|
||||||
id: claude-code
|
id: claude-code
|
||||||
if: steps.prepare.outputs.contains_trigger == 'true'
|
if: steps.prepare.outputs.contains_trigger == 'true'
|
||||||
uses: anthropics/claude-code-base-action@v0.0.24
|
shell: bash
|
||||||
with:
|
run: |
|
||||||
prompt_file: /tmp/claude-prompts/claude-prompt.txt
|
# Run Claude Code directly when using OAuth
|
||||||
allowed_tools: ${{ env.ALLOWED_TOOLS }}
|
if [ "${{ inputs.anthropic_api_key }}" = "use-oauth" ]; then
|
||||||
disallowed_tools: ${{ env.DISALLOWED_TOOLS }}
|
echo "Running Claude Code with OAuth authentication"
|
||||||
timeout_minutes: ${{ inputs.timeout_minutes }}
|
# Export empty ANTHROPIC_API_KEY to ensure OAuth credentials are used
|
||||||
model: ${{ inputs.model || inputs.anthropic_model }}
|
export ANTHROPIC_API_KEY=""
|
||||||
mcp_config: ${{ steps.prepare.outputs.mcp_config }}
|
else
|
||||||
# Workaround: pretend to use bedrock when using OAuth to bypass validation
|
echo "Running Claude Code with API key authentication"
|
||||||
use_bedrock: ${{ inputs.use_bedrock || inputs.anthropic_api_key == 'use-oauth' }}
|
export ANTHROPIC_API_KEY="${{ inputs.anthropic_api_key }}"
|
||||||
use_vertex: ${{ inputs.use_vertex }}
|
fi
|
||||||
# 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 }}
|
|
||||||
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 }}
|
|
||||||
|
|
||||||
|
# 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:
|
||||||
# GitHub token for repository access
|
# GitHub token for repository access
|
||||||
GITHUB_TOKEN: ${{ steps.prepare.outputs.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ steps.prepare.outputs.GITHUB_TOKEN }}
|
||||||
GITEA_API_URL: ${{ env.GITHUB_SERVER_URL }}
|
GITEA_API_URL: ${{ env.GITHUB_SERVER_URL }}
|
||||||
|
|
||||||
# Git configuration
|
# Git configuration for Claude Code
|
||||||
CLAUDE_GIT_NAME: ${{ inputs.claude_git_name }}
|
GIT_AUTHOR_NAME: ${{ inputs.claude_git_name }}
|
||||||
CLAUDE_GIT_EMAIL: ${{ inputs.claude_git_email }}
|
GIT_AUTHOR_EMAIL: ${{ inputs.claude_git_email }}
|
||||||
|
GIT_COMMITTER_NAME: ${{ inputs.claude_git_name }}
|
||||||
# Provider configuration (for future cloud provider support)
|
GIT_COMMITTER_EMAIL: ${{ inputs.claude_git_email }}
|
||||||
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 }}
|
|
||||||
|
|
||||||
- name: Update comment with job link
|
- name: Update comment with job link
|
||||||
if: steps.prepare.outputs.contains_trigger == 'true' && steps.prepare.outputs.claude_comment_id && always()
|
if: steps.prepare.outputs.contains_trigger == 'true' && steps.prepare.outputs.claude_comment_id && always()
|
||||||
|
|||||||
Reference in New Issue
Block a user