Skip to content

Commit 7388713

Browse files
committed
Update Claude Code integration to use Docker image and add GitHub token for authentication
1 parent cc3a273 commit 7388713

File tree

5 files changed

+160
-1
lines changed

5 files changed

+160
-1
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM node:20-alpine
2+
3+
RUN npm install -g @anthropic-ai/claude-code
4+
5+
WORKDIR /app
6+
COPY entrypoint.sh .
7+
RUN chmod +x entrypoint.sh
8+
9+
ENTRYPOINT ["/app/entrypoint.sh"]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: "Claude Code Action"
2+
description: "Custom Claude Code runner for PraisonAI"
3+
4+
inputs:
5+
anthropic_api_key:
6+
required: true
7+
description: "Anthropic API key"
8+
github_token:
9+
required: true
10+
description: "GitHub token for repo access"
11+
12+
runs:
13+
using: "docker"
14+
image: "ghcr.io/mervinpraison/praisonai-claude-code:latest"
15+
args:
16+
- "--anthropic-api-key=${{ inputs.anthropic_api_key }}"
17+
- "--github-token=${{ inputs.github_token }}"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
echo "Running Claude Code in CI mode..."
6+
7+
# Extract GitHub context and create a smart prompt
8+
PROMPT="Analyse the GitHub issue or PR context and generate a smart response based on the repository context."
9+
10+
# Set environment variables
11+
export ANTHROPIC_API_KEY="$1"
12+
export GITHUB_TOKEN="$2"
13+
14+
# Run Claude with the prompt
15+
claude -p "$PROMPT"
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
name: "Claude Code Action"
2+
description: "Run Claude Code in GitHub Actions workflows"
3+
4+
inputs:
5+
github_token:
6+
description: "GitHub token with repo and issues permissions"
7+
required: true
8+
anthropic_api_key:
9+
description: "Anthropic API key"
10+
required: true
11+
prompt:
12+
description: "The prompt to send to Claude Code"
13+
required: false
14+
default: ""
15+
prompt_file:
16+
description: "Path to a file containing the prompt to send to Claude Code"
17+
required: false
18+
default: ""
19+
allowed_tools:
20+
description: "Comma-separated list of allowed tools for Claude Code to use"
21+
required: false
22+
default: ""
23+
output_file:
24+
description: "File to save Claude Code output to (optional)"
25+
required: false
26+
default: ""
27+
timeout_minutes:
28+
description: "Timeout in minutes for Claude Code execution"
29+
required: false
30+
default: "10"
31+
install_github_mcp:
32+
description: "Whether to install the GitHub MCP server"
33+
required: false
34+
default: "false"
35+
36+
runs:
37+
using: "composite"
38+
steps:
39+
- name: Install Claude Code
40+
shell: bash
41+
run: npm install -g @anthropic-ai/claude-code
42+
43+
- name: Install GitHub MCP Server
44+
if: inputs.install_github_mcp == 'true'
45+
shell: bash
46+
run: |
47+
claude mcp add-json github '{
48+
"command": "docker",
49+
"args": [
50+
"run",
51+
"-i",
52+
"--rm",
53+
"-e",
54+
"GITHUB_PERSONAL_ACCESS_TOKEN",
55+
"ghcr.io/github/github-mcp-server:sha-ff3036d"
56+
],
57+
"env": {
58+
"GITHUB_PERSONAL_ACCESS_TOKEN": "${{ inputs.GITHUB_TOKEN }}"
59+
}
60+
}'
61+
62+
- name: Prepare Prompt File
63+
shell: bash
64+
id: prepare_prompt
65+
run: |
66+
if [ -z "${{ inputs.prompt }}" ] && [ -z "${{ inputs.prompt_file }}" ]; then
67+
echo "::error::Neither 'prompt' nor 'prompt_file' was provided. At least one is required."
68+
exit 1
69+
fi
70+
71+
if [ ! -z "${{ inputs.prompt_file }}" ]; then
72+
if [ ! -f "${{ inputs.prompt_file }}" ]; then
73+
echo "::error::Prompt file '${{ inputs.prompt_file }}' does not exist."
74+
exit 1
75+
fi
76+
PROMPT_PATH="${{ inputs.prompt_file }}"
77+
else
78+
mkdir -p /tmp/claude-action
79+
PROMPT_PATH="/tmp/claude-action/prompt.txt"
80+
echo "${{ inputs.prompt }}" > "$PROMPT_PATH"
81+
fi
82+
83+
if [ ! -s "$PROMPT_PATH" ]; then
84+
echo "::error::Prompt is empty. Please provide a non-empty prompt."
85+
exit 1
86+
fi
87+
88+
echo "PROMPT_PATH=$PROMPT_PATH" >> $GITHUB_ENV
89+
90+
- name: Run Claude Code
91+
shell: bash
92+
id: run_claude
93+
run: |
94+
timeout_seconds=$((${{ inputs.timeout_minutes }} * 60))
95+
96+
if [ -z "${{ inputs.output_file }}" ]; then
97+
timeout $timeout_seconds claude \
98+
-p \
99+
--verbose \
100+
--output-format stream-json \
101+
"$(cat ${{ env.PROMPT_PATH }})" \
102+
${{ inputs.allowed_tools != '' && format('--allowedTools "{0}"', inputs.allowed_tools) || '' }}
103+
else
104+
timeout $timeout_seconds claude \
105+
-p \
106+
--verbose \
107+
--output-format stream-json \
108+
"$(cat ${{ env.PROMPT_PATH }})" \
109+
${{ inputs.allowed_tools != '' && format('--allowedTools "{0}"', inputs.allowed_tools) || '' }} | tee output.txt
110+
111+
jq -s '.' output.txt > output.json
112+
jq -r '.[-1].result' output.json > "${{ inputs.output_file }}"
113+
echo "Complete output saved to output.json, final response saved to ${{ inputs.output_file }}"
114+
fi
115+
env:
116+
ANTHROPIC_API_KEY: ${{ inputs.anthropic_api_key }}
117+
GITHUB_TOKEN: ${{ inputs.github_token }}

.github/workflows/claude.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ jobs:
3131

3232
- name: Run Claude Code
3333
id: claude
34-
uses: anthropics/claude-code-action@beta
34+
uses: docker://ghcr.io/mervinpraison/praisonai-claudecode:latest
3535
with:
3636
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
37+
github_token: ${{ secrets.GH_TOKEN }}
3738

0 commit comments

Comments
 (0)