Skip to content

Commit 998c151

Browse files
ondrejmirtesclaude
andcommitted
Use Claude Code GitHub Action instead of CLI
- Replace `npm install -g @anthropic-ai/claude-code` + `claude -p` with `anthropics/claude-code-action@v1` in fix-issue and fix-pr-ci workflows - Pass prompts via safe YAML `with: prompt:` parameter instead of shell heredocs, eliminating injection risks from untrusted content - Move inline ${{ }} expression to env var in react-on-comment workflow Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent eee7ea7 commit 998c151

File tree

3 files changed

+90
-105
lines changed

3 files changed

+90
-105
lines changed

.github/workflows/claude-fix-issue.yml

Lines changed: 51 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ jobs:
4242

4343
- uses: "ramsey/composer-install@v3"
4444

45-
- name: "Install Claude Code"
46-
run: npm install -g @anthropic-ai/claude-code
47-
4845
- name: "Fetch issue details"
4946
id: issue
5047
env:
@@ -62,87 +59,80 @@ jobs:
6259
echo "$ISSUE_JSON" | jq -r '.body' > /tmp/issue-body.txt
6360
6461
- name: "Run Claude Code"
65-
env:
66-
CLAUDE_CODE_OAUTH_TOKEN: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
67-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
68-
run: |
69-
git config user.name "phpstan-bot"
70-
git config user.email "ondrej+phpstanbot@mirtes.cz"
71-
72-
claude -p \
73-
--model claude-opus-4-6 \
74-
"$(cat << 'PROMPT_EOF'
75-
You are working on phpstan/phpstan-src, the source code of PHPStan - a PHP static analysis tool.
62+
uses: anthropics/claude-code-action@v1
63+
with:
64+
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
65+
claude_args: "--model claude-opus-4-6"
66+
prompt: |
67+
You are working on phpstan/phpstan-src, the source code of PHPStan - a PHP static analysis tool.
7668
77-
Your task is to fix the following GitHub issue from the phpstan/phpstan repository:
78-
Issue phpstan/phpstan#${{ inputs.issue-number }}: ${{ steps.issue.outputs.title }}
79-
URL: ${{ steps.issue.outputs.url }}
69+
Your task is to fix the following GitHub issue from the phpstan/phpstan repository:
70+
Issue phpstan/phpstan#${{ inputs.issue-number }}: ${{ steps.issue.outputs.title }}
71+
URL: ${{ steps.issue.outputs.url }}
8072
81-
Issue body is in the file /tmp/issue-body.txt — read it before proceeding.
73+
Issue body is in the file /tmp/issue-body.txt — read it before proceeding.
8274
83-
## Step 1: Write a regression test
75+
## Step 1: Write a regression test
8476
85-
Read .claude/skills/regression-test/SKILL.md for detailed guidance on writing regression tests for PHPStan bugs.
77+
Read .claude/skills/regression-test/SKILL.md for detailed guidance on writing regression tests for PHPStan bugs.
8678
87-
The issue body is already provided above — start from Step 2 of the skill (deciding test type). For Step 1 (gathering context), you only need to fetch the playground samples from any playground links found in the issue body.
79+
The issue body is already provided above — start from Step 2 of the skill (deciding test type). For Step 1 (gathering context), you only need to fetch the playground samples from any playground links found in the issue body.
8880
89-
Skip Steps 5-6 of the skill (reverting fix and committing) — those are not needed here.
81+
Skip Steps 5-6 of the skill (reverting fix and committing) — those are not needed here.
9082
91-
The regression test should fail without the fix — verify this by running it before implementing the fix.
83+
The regression test should fail without the fix — verify this by running it before implementing the fix.
9284
93-
## Step 2: Fix the bug
85+
## Step 2: Fix the bug
9486
95-
Implement the fix in the source code under src/. Common areas to look:
96-
- src/Analyser/NodeScopeResolver.php - AST traversal and scope management
97-
- src/Analyser/MutatingScope.php - Type tracking
98-
- src/Analyser/TypeSpecifier.php - Type narrowing from conditions
99-
- src/Type/ - Type system implementations
100-
- src/Rules/ - Rule implementations
101-
- src/Reflection/ - Reflection layer
87+
Implement the fix in the source code under src/. Common areas to look:
88+
- src/Analyser/NodeScopeResolver.php - AST traversal and scope management
89+
- src/Analyser/MutatingScope.php - Type tracking
90+
- src/Analyser/TypeSpecifier.php - Type narrowing from conditions
91+
- src/Type/ - Type system implementations
92+
- src/Rules/ - Rule implementations
93+
- src/Reflection/ - Reflection layer
10294
103-
Read CLAUDE.md for important guidelines about the codebase architecture and common patterns.
95+
Read CLAUDE.md for important guidelines about the codebase architecture and common patterns.
10496
105-
## Step 3: Verify the fix
97+
## Step 3: Verify the fix
10698
107-
1. Run the regression test to confirm it passes now
108-
2. Run the full test suite: make tests
109-
3. Run PHPStan self-analysis: make phpstan
110-
4. Fix any failures that come up
111-
5. Run make cs-fix to fix any coding standard violations
112-
6. Run make name-collision and fix violations - add different tests in unique namespaces. If the function and class declarations are exactly the same, you can reuse them across files instead of duplicating them.
99+
1. Run the regression test to confirm it passes now
100+
2. Run the full test suite: make tests
101+
3. Run PHPStan self-analysis: make phpstan
102+
4. Fix any failures that come up
103+
5. Run make cs-fix to fix any coding standard violations
104+
6. Run make name-collision and fix violations - add different tests in unique namespaces. If the function and class declarations are exactly the same, you can reuse them across files instead of duplicating them.
113105
114-
Do not create a branch, push, or create a PR - this will be handled automatically.
106+
Do not create a branch, push, or create a PR - this will be handled automatically.
115107
116-
## Step 4: Write a summary
108+
## Step 4: Write a summary
117109
118-
After completing the fix, write two files:
110+
After completing the fix, write two files:
119111
120-
1. /tmp/commit-message.txt - A concise commit message (first line: short summary under 72 chars, then a blank line, then a few bullet points describing key changes). Example:
121-
Fix array_key_exists narrowing for template types
112+
1. /tmp/commit-message.txt - A concise commit message (first line: short summary under 72 chars, then a blank line, then a few bullet points describing key changes). Example:
113+
Fix array_key_exists narrowing for template types
122114
123-
- Added handling for TemplateType in TypeSpecifier when processing array_key_exists
124-
- New regression test in tests/PHPStan/Analyser/nsrt/bug-12345.php
125-
- The root cause was that TypeSpecifier did not unwrap template bounds before narrowing
115+
- Added handling for TemplateType in TypeSpecifier when processing array_key_exists
116+
- New regression test in tests/PHPStan/Analyser/nsrt/bug-12345.php
117+
- The root cause was that TypeSpecifier did not unwrap template bounds before narrowing
126118
127-
2. /tmp/pr-description.md - A pull request description in this format:
128-
## Summary
129-
Brief description of what the issue was about and what the fix does.
119+
2. /tmp/pr-description.md - A pull request description in this format:
120+
## Summary
121+
Brief description of what the issue was about and what the fix does.
130122
131-
## Changes
132-
- Bullet points of specific code changes made
133-
- Reference file paths where changes were made
123+
## Changes
124+
- Bullet points of specific code changes made
125+
- Reference file paths where changes were made
134126
135-
## Root cause
136-
Explain why the bug happened and how the fix addresses it.
127+
## Root cause
128+
Explain why the bug happened and how the fix addresses it.
137129
138-
## Test
139-
Describe the regression test that was added.
130+
## Test
131+
Describe the regression test that was added.
140132
141-
Fixes phpstan/phpstan#${{ inputs.issue-number }}
133+
Fixes phpstan/phpstan#${{ inputs.issue-number }}
142134
143-
These files are critical - they will be used for the commit message and PR description.
144-
PROMPT_EOF
145-
)"
135+
These files are critical - they will be used for the commit message and PR description.
146136
147137
- name: "Read Claude's summary"
148138
id: claude-summary

.github/workflows/claude-fix-pr-ci.yml

Lines changed: 37 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -132,68 +132,62 @@ jobs:
132132
if: steps.check-attempts.outputs.skip != 'true' && steps.failures.outputs.skip != 'true'
133133
uses: "ramsey/composer-install@v3"
134134

135-
- name: "Install Claude Code"
136-
if: steps.check-attempts.outputs.skip != 'true' && steps.failures.outputs.skip != 'true'
137-
run: npm install -g @anthropic-ai/claude-code
138-
139135
- name: "Run Claude Code"
140136
if: steps.check-attempts.outputs.skip != 'true' && steps.failures.outputs.skip != 'true'
141-
env:
142-
CLAUDE_CODE_OAUTH_TOKEN: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
143-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
144-
run: |
145-
git config user.name "phpstan-bot"
146-
git config user.email "ondrej+phpstanbot@mirtes.cz"
147-
148-
claude -p \
149-
--model claude-opus-4-6 \
150-
"$(cat << 'PROMPT_EOF'
151-
You are working on phpstan/phpstan-src. CI has failed on PR #${{ github.event.pull_request.number }} which was created by an automated process.
137+
uses: anthropics/claude-code-action@v1
138+
with:
139+
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
140+
claude_args: "--model claude-opus-4-6"
141+
additional_permissions: |
142+
actions: read
143+
prompt: |
144+
You are working on phpstan/phpstan-src. CI has failed on PR #${{ github.event.pull_request.number }} which was created by an automated process.
152145
153-
This is CI fix attempt ${{ steps.check-attempts.outputs.attempt_number }} of maximum 2.
146+
This is CI fix attempt ${{ steps.check-attempts.outputs.attempt_number }} of maximum 2.
154147
155-
## CI Failure Logs
148+
## CI Failure Logs
156149
157-
Read the CI failure logs from the file /tmp/ci-failure-context.txt.
150+
Read the CI failure logs from the file /tmp/ci-failure-context.txt.
158151
159-
## Your Task
152+
## Your Task
160153
161-
1. Read the failure logs above carefully to understand what went wrong
162-
2. Read CLAUDE.md for codebase architecture guidance
163-
3. Look at the recent commits on this branch (`git log origin/2.1.x..HEAD`) to understand what changes were made
164-
4. Fix the issue(s) causing CI failures
154+
1. Read the failure logs above carefully to understand what went wrong
155+
2. Read CLAUDE.md for codebase architecture guidance
156+
3. Look at the recent commits on this branch (`git log origin/2.1.x..HEAD`) to understand what changes were made
157+
4. Fix the issue(s) causing CI failures
165158
166-
## Common CI failure categories
159+
## Common CI failure categories
167160
168-
- **Test failures**: A test assertion is wrong or the code change broke existing behavior. Fix the code or update the test expectations.
169-
- **PHPStan self-analysis errors**: The code change introduced type errors that PHPStan catches on itself. Fix the type issues.
170-
- **Coding standard violations**: Run `make cs-fix` to auto-fix, or fix manually.
171-
- **Name collision**: Two test files define the same class/function in the same namespace. Fix by using unique namespaces.
172-
- **Lint errors**: PHP syntax errors in test data files, usually needing `// lint >= 8.x` comments for version-specific syntax.
173-
- **Backward compatibility**: A public API change broke BC. May need to preserve old signatures or add `@api` tags.
161+
- **Test failures**: A test assertion is wrong or the code change broke existing behavior. Fix the code or update the test expectations.
162+
- **PHPStan self-analysis errors**: The code change introduced type errors that PHPStan catches on itself. Fix the type issues.
163+
- **Coding standard violations**: Run `make cs-fix` to auto-fix, or fix manually.
164+
- **Name collision**: Two test files define the same class/function in the same namespace. Fix by using unique namespaces.
165+
- **Lint errors**: PHP syntax errors in test data files, usually needing `// lint >= 8.x` comments for version-specific syntax.
166+
- **Backward compatibility**: A public API change broke BC. May need to preserve old signatures or add `@api` tags.
174167
175-
## Verification
168+
## Verification
176169
177-
After making fixes, run these commands to verify:
178-
1. Run the specific failing test if identifiable: `vendor/bin/phpunit <test-file> --filter <test-name>`
179-
2. `make tests` - full test suite
180-
3. `make phpstan` - PHPStan self-analysis
181-
4. `make cs-fix` - coding standards
182-
5. `make name-collision` - namespace collision check
170+
After making fixes, run these commands to verify:
171+
1. Run the specific failing test if identifiable: `vendor/bin/phpunit <test-file> --filter <test-name>`
172+
2. `make tests` - full test suite
173+
3. `make phpstan` - PHPStan self-analysis
174+
4. `make cs-fix` - coding standards
175+
5. `make name-collision` - namespace collision check
183176
184-
## Important
177+
## Important
185178
186-
- Do NOT create a branch, push, or create a PR — this is handled automatically after you finish
187-
- Focus only on fixing the CI failures, do not refactor or add unrelated changes
188-
- If you cannot determine how to fix the failure, create a file /tmp/ci-fix-failed.txt with an explanation
189-
PROMPT_EOF
190-
)"
179+
- Do NOT create a branch, push, or create a PR — this is handled automatically after you finish
180+
- Focus only on fixing the CI failures, do not refactor or add unrelated changes
181+
- If you cannot determine how to fix the failure, create a file /tmp/ci-fix-failed.txt with an explanation
191182
192183
- name: "Commit and push fixes"
193184
if: steps.check-attempts.outputs.skip != 'true' && steps.failures.outputs.skip != 'true'
194185
env:
195186
ATTEMPT: ${{ steps.check-attempts.outputs.attempt_number }}
196187
run: |
188+
git config user.name "phpstan-bot"
189+
git config user.email "ondrej+phpstanbot@mirtes.cz"
190+
197191
if [ -f /tmp/ci-fix-failed.txt ]; then
198192
echo "Claude could not fix the CI failure:"
199193
cat /tmp/ci-fix-failed.txt

.github/workflows/claude-react-on-comment.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ jobs:
2424
id: check
2525
env:
2626
COMMENT_BODY: ${{ github.event.comment.body || github.event.review.body || '' }}
27+
COMMENT_USER: ${{ github.event.comment.user.login || github.event.review.user.login || '' }}
2728
run: |
28-
if [ "${{ github.event.comment.user.login || github.event.review.user.login || '' }}" = "phpstan-bot" ]; then
29+
if [ "$COMMENT_USER" = "phpstan-bot" ]; then
2930
echo "triggered=false" >> "$GITHUB_OUTPUT"
3031
elif echo "$COMMENT_BODY" | grep -qF "@phpstan-bot"; then
3132
echo "triggered=true" >> "$GITHUB_OUTPUT"

0 commit comments

Comments
 (0)