-
Notifications
You must be signed in to change notification settings - Fork 26
197 lines (164 loc) · 7.42 KB
/
Copy pathclaude_runner.yml
File metadata and controls
197 lines (164 loc) · 7.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
name: Claude Code • Auto PR on Comment
on:
issue_comment:
types: [created]
schedule:
- cron: "0 * * * *"
workflow_dispatch: {}
concurrency:
group: doc-fixing-ai-agent
cancel-in-progress: false
jobs:
get_issue_and_assign:
runs-on: ubuntu-latest
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- name: Set up Node.js 24
uses: actions/setup-node@v5
with:
node-version: '24'
- name: Install GitHub CLI
run: |
sudo apt-get update
sudo apt-get install -y gh jq
- name: Get the Oldest Issue with AI-Agent/Queued label
id: get_oldest_queued
env:
GITHUB_TOKEN: ${{ secrets.DOC_FIXING_AGENT_GITHUB_TOKEN }}
run: |
ISSUE_JSON=$(gh issue list --label "AI-Agent/Queued" --state open --json number,createdAt --limit 100 \
| jq '[.[]] | sort_by(.createdAt) | .[0]')
if [ "$ISSUE_JSON" = "null" ] || [ -z "$ISSUE_JSON" ]; then
echo "oldest_issue_number=" >> $GITHUB_OUTPUT
exit 0
fi
ISSUE_NUMBER=$(echo "$ISSUE_JSON" | jq -r .number)
echo "oldest_issue_number=$ISSUE_NUMBER" >> $GITHUB_OUTPUT
- name: Update labels and trigger Claude
if: steps.get_oldest_queued.outputs.oldest_issue_number != ''
env:
GITHUB_TOKEN: ${{ secrets.DOC_FIXING_AGENT_GITHUB_TOKEN }}
run: |
ISSUE=${{ steps.get_oldest_queued.outputs.oldest_issue_number }}
# Remove AI-Agent/Queued, add AI-Agent/In-Progress
gh issue edit $ISSUE --remove-label "AI-Agent/Queued"
gh issue edit $ISSUE --add-label "AI-Agent/In-Progress"
# Add trigger comment for Claude
gh issue comment $ISSUE --body "@wso2-engineering-bot create a PR for this issue following repo conventions"
run_claude:
runs-on: ubuntu-latest
if: contains(github.event.comment.body, '@wso2-engineering-bot')
steps:
- name: Checkout original repository
uses: actions/checkout@v5
with:
repository: ${{ vars.DOC_FIXING_AGENT_REPOSITORY }}
token: ${{ secrets.DOC_FIXING_AGENT_GITHUB_TOKEN }}
fetch-depth: 0
persist-credentials: false
- name: Set up Node.js 24
uses: actions/setup-node@v5
with:
node-version: '24'
- name: Configure git for commits
env:
GIT_USER_NAME: ${{ secrets.DOC_FIXING_AGENT_GIT_USER_NAME }}
GIT_USER_EMAIL: ${{ secrets.DOC_FIXING_AGENT_GIT_USER_EMAIL }}
run: |
# Show current remotes for debugging
echo "Current remotes:"
git remote -v
# Configure git for commits
git config user.name "$GIT_USER_NAME"
git config user.email "$GIT_USER_EMAIL"
- name: Install security pre-commit hook
run: |
echo "Installing pre-commit hook for path validation..."
# Create hooks directory if it doesn't exist
mkdir -p .git/hooks
# Copy and enable the pre-commit hook
cp ${{ github.workspace }}/.github/scripts/pre-commit-hook.sh .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit
echo "✅ Pre-commit hook installed successfully"
echo "This hook will prevent commits to forbidden paths"
- name: Prepare system prompt with environment variables
id: prepare_prompt
run: |
# Install gettext if not available (for envsubst)
if ! command -v envsubst &> /dev/null; then
sudo apt-get update && sudo apt-get install -y gettext-base
fi
# Export environment variables for substitution
export ISSUE_NUMBER="${{ github.event.issue.number }}"
export REPOSITORY="${{ vars.DOC_FIXING_AGENT_REPOSITORY }}"
# Process the system prompt with variable substitution
SYSTEM_PROMPT=$(envsubst < ${{github.workspace}}/.github/claude/system_prompt.txt)
# Generate unique delimiter to prevent collision
DELIMITER="EOF_$(date +%s)_$$"
# Save to GitHub env with unique delimiter
echo "SYSTEM_PROMPT<<${DELIMITER}" >> $GITHUB_ENV
echo "$SYSTEM_PROMPT" >> $GITHUB_ENV
echo "${DELIMITER}" >> $GITHUB_ENV
# Also set these for Claude
echo "ISSUE_NUMBER=$ISSUE_NUMBER" >> $GITHUB_ENV
echo "REPOSITORY=$REPOSITORY" >> $GITHUB_ENV
- name: Set up Python 3.8
uses: actions/setup-python@v5
with:
python-version: '3.8'
- name: Install documentation dependencies
run: |
cd $GITHUB_WORKSPACE/en
if [ -f requirements.txt ]; then
pip3 install -r requirements.txt
echo "✓ Installed dependencies from requirements.txt"
else
pip3 install mkdocs mkdocs-material
echo "✓ Installed mkdocs and mkdocs-material"
fi
- name: Run Claude
id: run_claude
uses: anthropics/claude-code-action@v1
env:
ISSUE_NUMBER: ${{ github.event.issue.number }}
REPOSITORY: ${{ vars.DOC_FIXING_AGENT_REPOSITORY }}
with:
anthropic_api_key: ${{ secrets.DOC_FIXING_AGENT_ANTHROPIC_API_KEY }}
github_token: ${{ secrets.DOC_FIXING_AGENT_GITHUB_TOKEN }}
prompt: ${{ env.SYSTEM_PROMPT }}
trigger_phrase: "@wso2-engineering-bot"
claude_args: |
--allowedTools "Bash(git fetch *),Bash(git checkout *),Bash(git branch *),Bash(git status *),Bash(git diff *),Bash(git add *),Bash(git commit *),Bash(git push *),Bash(git log *),Bash(ls *),Bash(mkdir *),Bash(cp *),Bash(mv *),Bash(mkdocs *),WebFetch,mcp__github__create_pull_request,mcp__github__get_issue,mcp__github__search_pull_requests,mcp__github__list_branches,Edit,Read,Write,mcp__github__update_issue,mcp__github__create_branch,mcp__github__add_issue_comment,mcp__github__get_file_contents"
--model claude-sonnet-4-5-20250929
- name: Get next queued issue
id: get_next_queued
env:
GITHUB_TOKEN: ${{ secrets.DOC_FIXING_AGENT_GITHUB_TOKEN }}
run: |
ISSUE_JSON=$(gh issue list --label "AI-Agent/Queued" --state open --json number,createdAt --limit 100 \
| jq '[.[]] | sort_by(.createdAt) | .[0]')
if [ "$ISSUE_JSON" = "null" ] || [ -z "$ISSUE_JSON" ]; then
echo "next_issue_number=" >> $GITHUB_OUTPUT
exit 0
fi
NEXT_ISSUE_NUMBER=$(echo "$ISSUE_JSON" | jq -r .number)
echo "next_issue_number=$NEXT_ISSUE_NUMBER" >> $GITHUB_OUTPUT
- name: Exit if no queued issues
if: steps.get_next_queued.outputs.next_issue_number == ''
run: |
echo "No queued issues."
exit 0
- name: Update labels and trigger Claude
env:
GITHUB_TOKEN: ${{ secrets.DOC_FIXING_AGENT_GITHUB_TOKEN }}
if: steps.get_next_queued.outputs.next_issue_number != ''
run: |
ISSUE=${{ steps.get_next_queued.outputs.next_issue_number }}
# Remove AI-Agent/Queued, add AI-Agent/In-Progress
gh issue edit $ISSUE --remove-label "AI-Agent/Queued"
gh issue edit $ISSUE --add-label "AI-Agent/In-Progress"
# Add trigger comment for Claude
gh issue comment $ISSUE --body "@wso2-engineering-bot create a PR for this issue following repo conventions"