forked from phpstan/phpstan
-
Notifications
You must be signed in to change notification settings - Fork 0
221 lines (167 loc) · 10.4 KB
/
claude-update-error-docs.yml
File metadata and controls
221 lines (167 loc) · 10.4 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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
name: "Claude Update Error Docs"
on:
workflow_dispatch:
inputs:
sha:
description: "phpstan/phpstan commit with errorIdentifiers.json change"
required: true
type: string
workflow_call:
inputs:
sha:
description: "phpstan/phpstan commit with errorIdentifiers.json change"
required: true
type: string
permissions:
contents: read
jobs:
fix:
name: "Update Error Docs"
runs-on: "ubuntu-latest"
timeout-minutes: 60
permissions:
contents: read
issues: read
pull-requests: write
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@5ef0c079ce82195b2a36a210272d6b661572d83e # v2.14.2
with:
egress-policy: audit
- name: "Checkout"
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
with:
ref: ${{ inputs.sha }}
repository: phpstan/phpstan
fetch-depth: 10
- name: "Install Claude Code"
run: npm install -g @anthropic-ai/claude-code
- name: "Run Claude Code"
env:
CLAUDE_CODE_OAUTH_TOKEN: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
GH_TOKEN: ${{ secrets.PHPSTAN_BOT_FORK_TOKEN }}
run: |
git config user.name "phpstan-bot"
git config user.email "ondrej+phpstanbot@mirtes.cz"
claude --model claude-opus-4-6 \
--dangerously-skip-permissions \
-p "$(cat << 'PROMPT_EOF'
You are generating documentation pages for PHPStan error identifiers. PHPStan is a PHP static analysis tool that finds bugs in code without running it. Each error identifier (like `argument.type`, `deadCode.unreachable`, `property.notFound`) categorizes a specific type of error.
The goal is to create a markdown file for each identifier in `website/errors/` explaining what the error means, showing a code example, and offering ways to fix it.
## Step 1: Find what changed
See the checked out commit of the current repository. It should contain changes to `website/src/errorsIdentifiers.json`. See if the diff means any identifier was added or updated.
Read `website/src/errorsIdentifiers.json`. This JSON maps each identifier to its rule classes and source code locations:
```json
{
"argument.type": {
"PHPStan\\Rules\\Functions\\CallToFunctionParametersRule": {
"phpstan/phpstan-src": [
"https://github.com/phpstan/phpstan-src/blob/2.2.x/src/Rules/FunctionCallParametersCheck.php#L280"
]
}
}
}
```
Then list existing files in `website/errors/`. Each file is named `<identifier>.md`.
You will document any identifiers that do not have .md file. You will also look if any identifiers involved in the diff of the checked out commit need updating the docs.
## Step 2: Clone required repositories
Clone only the repositories referenced by the affected identifiers. Extract the branch name from the GitHub URLs (e.g., `blob/2.2.x/` → branch `2.2.x`).
Use shallow clones to save time:
```bash
git clone --depth 1 --branch <branch> https://github.com/phpstan/<repo>.git /tmp/repos/<repo>
```
The possible repositories are:
- `phpstan/phpstan-src` (typically branch `2.2.x`)
- `phpstan/phpstan-strict-rules`
- `phpstan/phpstan-deprecation-rules`
- `phpstan/phpstan-doctrine`
- `phpstan/phpstan-symfony`
- `phpstan/phpstan-phpunit`
- `phpstan/phpstan-nette`
## Step 3: Research each identifier
For each identifier, gather the information needed to write the documentation.
### 3a. Read the rule source code
From the JSON URLs, extract the file path and line number. Read the source code around those lines to find:
1. **Error message**: Look for `RuleErrorBuilder::message('...')` — this is the exact error text PHPStan shows
2. **Trigger condition**: Read the surrounding `processNode()` method to understand what code pattern causes this error
3. **Tips**: Look for `->tip('...')` or `->addTip('...')` calls in the same builder chain — these often contain links to blog posts or documentation pages on phpstan.org
4. **Non-ignorable**: Check for `->nonIgnorable()` in the builder chain
### 3b. Understand the identifier prefix when source uses `$location->createIdentifier()`
When reading the rule source code in step 3a, check whether the linked source code line uses `$location->createIdentifier()`. If it does, the identifier prefix comes from `ClassNameUsageLocation` in phpstan-src, and the prefix indicates a specific PHP language feature — which may not be obvious from the prefix name alone.
If the source code does **not** use `$location->createIdentifier()`, the prefix is set directly by the rule and typically describes its PHP feature straightforwardly.
Consult the "Identifier prefix reference" section in `website/errors/CLAUDE.md` for the complete prefix-to-PHP-feature mapping tables.
### 3c. Find test fixtures with code examples
For a rule class like `PHPStan\Rules\Functions\CallToFunctionParametersRule`:
- Test class: `tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php`
- Test data: `tests/PHPStan/Rules/Functions/data/*.php`
For extension repos (phpstan-doctrine, phpstan-symfony, etc.), the path pattern may differ — check `tests/Rules/` or `tests/` directories.
Read the test class to find which data files trigger this specific identifier. Look for the error message text in the test assertions:
```php
$this->analyse([__DIR__ . '/data/someFile.php'], [
['Error message text', 42],
]);
```
Then read the corresponding data file to extract a minimal code example.
### 3d. Determine if the error is ignorable
An error identifier is **not ignorable** if:
- The source code uses `->nonIgnorable()` in the error builder chain
- The identifier starts with `phpstan.` (internal PHPStan errors)
- The identifier starts with `phpstanPlayground.` (playground-specific)
All other identifiers are ignorable.
### 3e. Check for configuration options
Some rules accept constructor parameters from PHPStan configuration. Look at the rule class constructor for injected config values. Cross-reference with `website/src/config-reference.md` to find the documented parameter name.
Examples of configurable rules:
- Rules that check strict types may be controlled by `treatPhpDocTypesAsCertain`
- Dead code rules may be controlled by `checkAlwaysTrueCheckTypeFunctionCall`
- Some rules are only active at certain PHPStan levels
## Step 4: Generate markdown files
Create `website/errors/` directory if it doesn't exist.
For each identifier, create `website/errors/<identifier>.md` following the file format, content guidelines, and tone described in `website/errors/CLAUDE.md`. Read that file before generating any markdown.
Each file's frontmatter MUST include a `shortDescription` field — one sentence (ending with a period) describing when the error is reported, from a user's perspective. For example: `"Accessing a private property from outside the declaring class."` or `"Loose comparison using == will always evaluate to true."`. This description should capture the essence of the error — what code pattern triggers it — without mentioning PHPStan internals.
## Step 5: Write a summary
After completing the fix, write two files:
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:
Update error docs - added new `new.trait` identifier
More detailed description of the commit
2. /tmp/pr-description.md - A pull request description in this format:
What was the work involved in updating the docs.
These files are critical - they will be used for the commit message and PR description.
PROMPT_EOF
)"
- name: "Read Claude's summary"
id: claude-summary
run: |
if [ -f /tmp/commit-message.txt ]; then
delimiter="EOF_$(openssl rand -hex 16)"
{
echo "commit_message<<${delimiter}"
cat /tmp/commit-message.txt
echo "${delimiter}"
} >> "$GITHUB_OUTPUT"
else
echo "commit_message=Update error identifiers docs" >> "$GITHUB_OUTPUT"
fi
if [ -f /tmp/pr-description.md ]; then
delimiter="EOF_$(openssl rand -hex 16)"
{
echo "pr_body<<${delimiter}"
cat /tmp/pr-description.md
echo "${delimiter}"
} >> "$GITHUB_OUTPUT"
else
echo "pr_body=Update error identifiers docs" >> "$GITHUB_OUTPUT"
fi
- name: "Create Pull Request"
id: create-pr
uses: peter-evans/create-pull-request@c0f553fe549906ede9cf27b5156039d195d2ece0 # v8.1.0
with:
branch-token: ${{ secrets.PHPSTAN_BOT_FORK_TOKEN }}
token: ${{ secrets.PHPSTAN_BOT_PR_TOKEN }}
push-to-fork: phpstan-bot/phpstan
branch-suffix: random
delete-branch: true
base: 2.2.x
title: "Update Error Docs"
body: ${{ steps.claude-summary.outputs.pr_body }}
committer: "phpstan-bot <ondrej+phpstanbot@mirtes.cz>"
commit-message: ${{ steps.claude-summary.outputs.commit_message }}