|
18 | 18 | - name: "Checkout" |
19 | 19 | uses: actions/checkout@v4 |
20 | 20 | with: |
| 21 | + ref: "2.1.x" |
21 | 22 | fetch-depth: 0 |
22 | 23 |
|
23 | 24 | - name: "Install PHP" |
@@ -55,102 +56,122 @@ jobs: |
55 | 56 | ISSUE_NUMBER=$(echo "$ISSUE" | jq -r '.number') |
56 | 57 | ISSUE_TITLE=$(echo "$ISSUE" | jq -r '.title') |
57 | 58 | ISSUE_URL=$(echo "$ISSUE" | jq -r '.url') |
58 | | - ISSUE_BODY=$(echo "$ISSUE" | jq -r '.body') |
59 | | -
|
60 | 59 | echo "issue_number=$ISSUE_NUMBER" >> "$GITHUB_OUTPUT" |
61 | 60 | echo "issue_title=$ISSUE_TITLE" >> "$GITHUB_OUTPUT" |
62 | 61 | echo "issue_url=$ISSUE_URL" >> "$GITHUB_OUTPUT" |
63 | 62 |
|
64 | | - EOF_MARKER=$(dd if=/dev/urandom bs=15 count=1 status=none | base64) |
65 | | - echo "issue_body<<$EOF_MARKER" >> "$GITHUB_OUTPUT" |
66 | | - echo "$ISSUE_BODY" >> "$GITHUB_OUTPUT" |
67 | | - echo "$EOF_MARKER" >> "$GITHUB_OUTPUT" |
68 | | -
|
69 | | - # Also fetch the first comment (issue body is the first comment) |
70 | 63 | FIRST_COMMENT_BODY=$(gh issue view "$ISSUE_NUMBER" \ |
71 | 64 | --repo phpstan/phpstan \ |
72 | 65 | --json body \ |
73 | 66 | --jq '.body') |
74 | 67 |
|
| 68 | + EOF_MARKER=$(dd if=/dev/urandom bs=15 count=1 status=none | base64) |
75 | 69 | echo "first_comment<<$EOF_MARKER" >> "$GITHUB_OUTPUT" |
76 | 70 | echo "$FIRST_COMMENT_BODY" >> "$GITHUB_OUTPUT" |
77 | 71 | echo "$EOF_MARKER" >> "$GITHUB_OUTPUT" |
78 | 72 |
|
79 | 73 | echo "### Selected issue: #$ISSUE_NUMBER - $ISSUE_TITLE" >> "$GITHUB_STEP_SUMMARY" |
80 | 74 | echo "$ISSUE_URL" >> "$GITHUB_STEP_SUMMARY" |
81 | 75 |
|
82 | | - - name: "Run Claude Code" |
83 | | - uses: anthropics/claude-code-action@v1 |
84 | | - with: |
85 | | - anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} |
86 | | - github_token: ${{ secrets.GITHUB_TOKEN }} |
87 | | - prompt: | |
88 | | - You are working on phpstan/phpstan-src, the source code of PHPStan - a PHP static analysis tool. |
| 76 | + - name: "Install Claude Code" |
| 77 | + run: npm install -g @anthropic-ai/claude-code |
| 78 | + |
| 79 | + - name: "Build prompt" |
| 80 | + env: |
| 81 | + ISSUE_NUMBER: ${{ steps.pick-issue.outputs.issue_number }} |
| 82 | + ISSUE_TITLE: ${{ steps.pick-issue.outputs.issue_title }} |
| 83 | + ISSUE_URL: ${{ steps.pick-issue.outputs.issue_url }} |
| 84 | + ISSUE_BODY: ${{ steps.pick-issue.outputs.first_comment }} |
| 85 | + run: | |
| 86 | + python3 << 'PYEOF' |
| 87 | + import os |
89 | 88 |
|
90 | | - Your task is to fix the following GitHub issue from the phpstan/phpstan repository: |
91 | | - Issue #${{ steps.pick-issue.outputs.issue_number }}: ${{ steps.pick-issue.outputs.issue_title }} |
92 | | - URL: ${{ steps.pick-issue.outputs.issue_url }} |
| 89 | + n = os.environ["ISSUE_NUMBER"] |
| 90 | + title = os.environ["ISSUE_TITLE"] |
| 91 | + url = os.environ["ISSUE_URL"] |
| 92 | + body = os.environ["ISSUE_BODY"] |
93 | 93 |
|
94 | | - Issue body: |
95 | | - ${{ steps.pick-issue.outputs.first_comment }} |
| 94 | + prompt = f"""You are working on phpstan/phpstan-src, the source code of PHPStan - a PHP static analysis tool. |
96 | 95 |
|
97 | | - ## Step 1: Retrieve playground code |
| 96 | + Your task is to fix the following GitHub issue from the phpstan/phpstan repository: |
| 97 | + Issue #{n}: {title} |
| 98 | + URL: {url} |
98 | 99 |
|
99 | | - From the issue body above, find any referenced PHPStan playground links (URLs matching https://phpstan.org/r/<UUID>). |
| 100 | + Issue body: |
| 101 | + {body} |
100 | 102 |
|
101 | | - For each playground link, extract the UUID and fetch the code and analysis results using the API: |
102 | | - ``` |
103 | | - curl https://api.phpstan.org/sample?id=<UUID> |
104 | | - ``` |
| 103 | + ## Step 1: Retrieve playground code |
105 | 104 |
|
106 | | - The API returns JSON with: |
107 | | - - `code`: The PHP code that was analyzed |
108 | | - - `level`: The PHPStan rule level |
109 | | - - `config.strictRules`: Whether strict rules are enabled |
110 | | - - `config.bleedingEdge`: Whether bleeding edge is enabled |
111 | | - - `config.treatPhpDocTypesAsCertain`: PHPDoc type certainty setting |
112 | | - - `versionedErrors`: Array of `{phpVersion, errors: [{line, message, identifier}]}` |
| 105 | + From the issue body above, find any referenced PHPStan playground links (URLs matching https://phpstan.org/r/<UUID>). |
113 | 106 |
|
114 | | - ## Step 2: Write a regression test |
| 107 | + For each playground link, extract the UUID and fetch the code and analysis results using the API: |
| 108 | + curl https://api.phpstan.org/sample?id=<UUID> |
115 | 109 |
|
116 | | - Based on the issue and the playground code: |
| 110 | + The API returns JSON with: |
| 111 | + - code: The PHP code that was analyzed |
| 112 | + - level: The PHPStan rule level |
| 113 | + - config.strictRules: Whether strict rules are enabled |
| 114 | + - config.bleedingEdge: Whether bleeding edge is enabled |
| 115 | + - config.treatPhpDocTypesAsCertain: PHPDoc type certainty setting |
| 116 | + - versionedErrors: Array of {{phpVersion, errors: [{{line, message, identifier}}]}} |
117 | 117 |
|
118 | | - - If the problem is **only about type inference** (wrong type reported, missing type narrowing, etc.), add a test file in `tests/PHPStan/Analyser/nsrt/` using `assertType()` and `assertNativeType()` calls. Name it `bug-<issue_number>.php`. Look at existing files in that directory for examples. |
| 118 | + ## Step 2: Write a regression test |
119 | 119 |
|
120 | | - - If the problem is about a **rule false positive/negative** (wrong error reported or missing error), add a rule-specific test. Find the relevant rule test case in `tests/PHPStan/Rules/` and add a test data file. Look at existing bug test files in those directories for the pattern. |
| 120 | + Based on the issue and the playground code: |
121 | 121 |
|
122 | | - The regression test **should fail** without the fix - verify this by running it before implementing the fix. |
| 122 | + - If the problem is only about type inference (wrong type reported, missing type narrowing, etc.), add a test file in tests/PHPStan/Analyser/nsrt/ using assertType() and assertNativeType() calls. Name it bug-{n}.php. Look at existing files in that directory for examples. |
123 | 123 |
|
124 | | - Run individual test files with: `php vendor/bin/phpunit <test-file>` |
125 | | - Run all tests with: `make tests` |
126 | | - Run PHPStan with: `make phpstan` |
| 124 | + - If the problem is about a rule false positive/negative (wrong error reported or missing error), add a rule-specific test. Find the relevant rule test case in tests/PHPStan/Rules/ and add a test data file. Look at existing bug test files in those directories for the pattern. |
127 | 125 |
|
128 | | - ## Step 3: Fix the bug |
| 126 | + The regression test should fail without the fix - verify this by running it before implementing the fix. |
129 | 127 |
|
130 | | - Implement the fix in the source code under `src/`. Common areas to look: |
131 | | - - `src/Analyser/NodeScopeResolver.php` - AST traversal and scope management |
132 | | - - `src/Analyser/MutatingScope.php` - Type tracking |
133 | | - - `src/Analyser/TypeSpecifier.php` - Type narrowing from conditions |
134 | | - - `src/Type/` - Type system implementations |
135 | | - - `src/Rules/` - Rule implementations |
136 | | - - `src/Reflection/` - Reflection layer |
| 128 | + Run individual test files with: php vendor/bin/phpunit <test-file> |
| 129 | + Run all tests with: make tests |
| 130 | + Run PHPStan with: make phpstan |
137 | 131 |
|
138 | | - Read CLAUDE.md for important guidelines about the codebase architecture and common patterns. |
| 132 | + ## Step 3: Fix the bug |
139 | 133 |
|
140 | | - ## Step 4: Verify the fix |
| 134 | + Implement the fix in the source code under src/. Common areas to look: |
| 135 | + - src/Analyser/NodeScopeResolver.php - AST traversal and scope management |
| 136 | + - src/Analyser/MutatingScope.php - Type tracking |
| 137 | + - src/Analyser/TypeSpecifier.php - Type narrowing from conditions |
| 138 | + - src/Type/ - Type system implementations |
| 139 | + - src/Rules/ - Rule implementations |
| 140 | + - src/Reflection/ - Reflection layer |
141 | 141 |
|
142 | | - 1. Run the regression test to confirm it passes now |
143 | | - 2. Run the full test suite: `make tests` |
144 | | - 3. Run PHPStan self-analysis: `make phpstan` |
145 | | - 4. Fix any failures that come up |
| 142 | + Read CLAUDE.md for important guidelines about the codebase architecture and common patterns. |
146 | 143 |
|
147 | | - ## Step 5: Create a branch and PR |
| 144 | + ## Step 4: Verify the fix |
| 145 | +
|
| 146 | + 1. Run the regression test to confirm it passes now |
| 147 | + 2. Run the full test suite: make tests |
| 148 | + 3. Run PHPStan self-analysis: make phpstan |
| 149 | + 4. Fix any failures that come up |
| 150 | +
|
| 151 | + ## Step 5: Create a branch and PR |
| 152 | +
|
| 153 | + 1. Create a branch named fix/bug-{n} |
| 154 | + 2. Commit all changes with message: "Fix #{n}" |
| 155 | + 3. Push the branch |
| 156 | + 4. Create a PR targeting the 2.1.x branch with: |
| 157 | + - Title: "Fix #{n}: {title}" |
| 158 | + - Body referencing the issue: "Fixes phpstan/phpstan#{n}" |
| 159 | + - Include a description of the fix and what was wrong |
| 160 | + """ |
| 161 | +
|
| 162 | + with open("/tmp/claude-prompt.txt", "w") as f: |
| 163 | + f.write(prompt) |
| 164 | + PYEOF |
| 165 | +
|
| 166 | + - name: "Run Claude Code" |
| 167 | + env: |
| 168 | + ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} |
| 169 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 170 | + run: | |
| 171 | + git config user.name "github-actions[bot]" |
| 172 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
148 | 173 |
|
149 | | - 1. Create a branch named `fix/bug-${{ steps.pick-issue.outputs.issue_number }}` |
150 | | - 2. Commit all changes with message: "Fix #${{ steps.pick-issue.outputs.issue_number }}" |
151 | | - 3. Push the branch |
152 | | - 4. Create a PR targeting the `2.1.x` branch with: |
153 | | - - Title: "Fix #${{ steps.pick-issue.outputs.issue_number }}: ${{ steps.pick-issue.outputs.issue_title }}" |
154 | | - - Body referencing the issue: "Fixes phpstan/phpstan#${{ steps.pick-issue.outputs.issue_number }}" |
155 | | - - Include a description of the fix and what was wrong |
156 | | - claude_args: "--model claude-opus-4-6 --max-turns 50" |
| 174 | + claude -p \ |
| 175 | + --model claude-opus-4-6 \ |
| 176 | + --max-turns 50 \ |
| 177 | + "$(cat /tmp/claude-prompt.txt)" |
0 commit comments