You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 344ceb3
Browse filesBrowse the repository at this point in the historyBrowse files
# The report is written to a file as well as piped to cs2pr, so that the step below
102
-
# can look at it.
106
+
# The report is written to a file for the steps below, which turn it into annotations,
107
+
# the pull request comment, and a check for errors that cannot be reported as warnings.
108
+
# Only the report goes to standard output; the debug output goes to standard error, so
109
+
# it stays in the log without corrupting the JSON.
103
110
#
104
-
# cs2pr exits successfully so that reported errors annotate the pull request without
105
-
# failing the run. A pipeline reports only the status of its last command, so that
106
-
# also discards the status of the analysis itself. Recover it from PIPESTATUS.
107
-
composer run phpstan -- -vvv --error-format=checkstyle | tee "${RUNNER_TEMP}/phpstan-report.xml" | cs2pr --errors-as-warnings --graceful-warnings
108
-
status="${PIPESTATUS[0]}"
111
+
# The step shell exits on the first failing command, which would also end the step on
112
+
# the status of 1 that PHPStan uses for reporting errors. Capture the status instead.
113
+
status=0
114
+
composer run phpstan -- -vvv --error-format=json > "${RUNNER_TEMP}/phpstan-report.json" || status=$?
109
115
110
116
# PHPStan exits 1 when it has errors to report, which is the expected case here and
111
-
# is what the annotations are for. Anything higher means it did not finish at all,
112
-
# which would otherwise pass silently, since the discarded status was the only sign.
117
+
# is what the annotations are for. Anything higher means it did not finish at all.
113
118
if [ "${status}" -gt 1 ]; then
114
119
echo "::error title=PHPStan did not complete::The analysis exited with status ${status}, so the code was not fully checked. This is a failure of the run itself rather than a problem found in the code."
115
120
exit "${status}"
116
121
fi
117
122
118
-
#An ignored error that no longer occurs, or occurs a different number of times, is
119
-
#reported under an `ignore.*` identifier. That is not something to fix in the code: the
120
-
#usual cause is that the error *was* fixed, leaving a baseline describing a state that
121
-
#no longer exists. PHPStan does not allow those reports to be ignored or baselined.
123
+
#Errors are annotated as warnings, so that they are visible on the pull request without
124
+
#failing the run. The exception is an error that PHPStan does not allow to be ignored,
125
+
#such as an out-of-date baseline entry, or one that is not specific to a file. These are
126
+
#annotated as errors instead, and the run fails on them in the check further below.
122
127
#
123
-
# The analysis above is reported as warnings, so this would otherwise surface as a
124
-
# passing run carrying an annotation that reads like a complaint about a fix. Call it
125
-
# out on its own, and say what to do about it.
128
+
# The results are also written out for the PHPStan Pull Request Comments workflow, which
129
+
# runs with the permissions needed to comment on the pull request. Only the facts are
130
+
# passed along: the comment is composed there, since a pull request can change anything
# The summary is Markdown, and its code spans and fences are written literally, so the
153
256
# heredoc is quoted to keep the backticks out of the shell's hands. The links are
154
257
# written in reference style for the same reason: the URLs are the only part needing
155
258
# a variable, so defining them afterwards keeps the whole of the prose in here.
156
259
#
157
260
# A newline renders as a line break rather than a space, so each paragraph is one
158
261
# line however long that makes it, and the rendered summary wraps to its own width.
159
-
cat >> "${GITHUB_STEP_SUMMARY}" <<'SUMMARY'
262
+
baselines_summary=$( cat <<'SUMMARY'
160
263
## PHPStan baselines are out of date
161
264
162
265
An ignored error no longer occurs, or occurs a different number of times, so PHPStan reported it under an `ignore.unmatched` or `ignore.count` identifier.
@@ -182,13 +285,20 @@ jobs:
182
285
See [`tests/phpstan/README.md`][readme] for details.
183
286
184
287
SUMMARY
288
+
)
289
+
290
+
if [ "${ignore_errors}" -gt 0 ]; then
291
+
{
292
+
printf '%s\n\n' "${baselines_summary}"
293
+
echo "[baselines]: ${BASELINES_URL}"
294
+
echo "[readme]: ${README_URL}"
295
+
} >> "${GITHUB_STEP_SUMMARY}"
185
296
186
-
{
187
-
echo "[baselines]: ${BASELINES_URL}"
188
-
echo "[readme]: ${README_URL}"
189
-
} >> "${GITHUB_STEP_SUMMARY}"
297
+
echo "::error title=PHPStan baselines are out of date::An ignored error no longer occurs, or occurs a different number of times. If you fixed it, that is expected: run \`npm run typecheck:php:baselines\` or \`composer phpstan:baselines\` and commit the updated baselines. See ${README_URL}"
298
+
else
299
+
echo "::error title=PHPStan reported errors that cannot be ignored::PHPStan reported ${unignorable} error(s) that cannot be ignored or reported as warnings. See the error annotations for details, and ${README_URL} for how to run the analysis locally."
300
+
fi
190
301
191
-
echo "::error title=PHPStan baselines are out of date::An ignored error no longer occurs, or occurs a different number of times. If you fixed it, that is expected: run \`npm run typecheck:php:baselines\` or \`composer phpstan:baselines\` and commit the updated baselines. See ${README_URL}"
0 commit comments