@@ -21,7 +21,43 @@ concurrency:
2121 group : run-issue-bot-${{ github.head_ref || github.run_id }} # will be canceled on subsequent pushes in pull requests but not branches
2222 cancel-in-progress : true
2323
24+ permissions :
25+ contents : read
26+
2427jobs :
28+ pr-comment-init :
29+ name : " Init PR comment (if exists)"
30+ if : github.event_name == 'pull_request'
31+ runs-on : " ubuntu-latest"
32+ permissions :
33+ pull-requests : write
34+
35+ steps :
36+ - name : Harden the runner (Audit all outbound calls)
37+ uses : step-security/harden-runner@5ef0c079ce82195b2a36a210272d6b661572d83e # v2.14.2
38+ with :
39+ egress-policy : audit
40+
41+ - name : " Find existing PR comment"
42+ id : find-comment
43+ uses : peter-evans/find-comment@3eae4d37986fb5a8592848f6a574fdf654e61f9e # v3.1.0
44+ with :
45+ issue-number : ${{ github.event.pull_request.number }}
46+ body-includes : " <!-- phpstan-issue-bot -->"
47+
48+ - name : " Mark comment as running"
49+ if : steps.find-comment.outputs.comment-id != ''
50+ uses : peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0
51+ with :
52+ comment-id : ${{ steps.find-comment.outputs.comment-id }}
53+ edit-mode : replace
54+ body : |
55+ <!-- phpstan-issue-bot -->
56+
57+ :hourglass_flowing_sand: A new issue bot run is in progress: [view job](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}).
58+
59+ This comment will be updated with the latest results when the run completes.
60+
2561 download :
2662 name : " Download data"
2763
@@ -161,6 +197,9 @@ jobs:
161197
162198 runs-on : " ubuntu-latest"
163199
200+ outputs :
201+ pr-evaluate-exit-code : ${{ steps.evaluate-pr.outputs.exit_code }}
202+
164203 steps :
165204 - name : Harden the runner (Audit all outbound calls)
166205 uses : step-security/harden-runner@5ef0c079ce82195b2a36a210272d6b661572d83e # v2.14.2
@@ -201,6 +240,7 @@ jobs:
201240 run : " ls -lA issue-bot/tmp"
202241
203242 - name : " Evaluate results - pull request"
243+ id : evaluate-pr
204244 working-directory : " issue-bot"
205245 if : github.event_name == 'pull_request'
206246 env :
@@ -212,12 +252,27 @@ jobs:
212252
213253 cat tmp/step-summary.md >> "$GITHUB_STEP_SUMMARY"
214254
255+ job_url="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
256+ {
257+ echo "<!-- phpstan-issue-bot -->"
258+ echo
259+ if [[ "$exit_code" == "2" ]]; then
260+ echo "Issue bot detected changes — [view run]($job_url):"
261+ echo
262+ cat tmp/step-summary.md
263+ else
264+ echo ":white_check_mark: No changes detected by issue bot in the [latest run]($job_url)."
265+ fi
266+ } > tmp/pr-comment.md
267+
268+ echo "exit_code=$exit_code" >> "$GITHUB_OUTPUT"
269+
215270 if [[ "$exit_code" == "2" ]]; then
216- echo "::notice file=.github/workflows/issue-bot.yml,line=3 ::Issue bot detected open issues which are affected by this pull request - see https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID"
217- exit 0
271+ echo "::notice file=.github/workflows/issue-bot.yml,line=3 ::Issue bot detected open issues which are affected by this pull request - see $job_url"
218272 fi
219273
220- exit $exit_code
274+ # Always exit 0 for the PR pathway so the pr-comment-finalize job still receives outputs/artifacts.
275+ exit 0
221276
222277 - name : " Upload step summary"
223278 if : github.event_name == 'pull_request'
@@ -226,6 +281,13 @@ jobs:
226281 name : step-summary
227282 path : issue-bot/tmp/step-summary.md
228283
284+ - name : " Upload PR comment body"
285+ if : github.event_name == 'pull_request'
286+ uses : actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
287+ with :
288+ name : pr-comment
289+ path : issue-bot/tmp/pr-comment.md
290+
229291 - name : " Evaluate results - push"
230292 working-directory : " issue-bot"
231293 if : " github.repository_owner == 'phpstan' && github.ref == 'refs/heads/2.2.x'"
@@ -244,3 +306,46 @@ jobs:
244306 fi
245307
246308 exit $exit_code
309+
310+ pr-comment-finalize :
311+ name : " Post/update PR comment"
312+ needs : evaluate
313+ if : github.event_name == 'pull_request' && needs.evaluate.result == 'success'
314+ runs-on : " ubuntu-latest"
315+ permissions :
316+ pull-requests : write
317+
318+ steps :
319+ - name : Harden the runner (Audit all outbound calls)
320+ uses : step-security/harden-runner@5ef0c079ce82195b2a36a210272d6b661572d83e # v2.14.2
321+ with :
322+ egress-policy : audit
323+
324+ - name : " Download PR comment body"
325+ uses : actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
326+ with :
327+ name : pr-comment
328+
329+ - name : " Find PR comment"
330+ id : find-comment
331+ uses : peter-evans/find-comment@3eae4d37986fb5a8592848f6a574fdf654e61f9e # v3.1.0
332+ with :
333+ issue-number : ${{ github.event.pull_request.number }}
334+ body-includes : " <!-- phpstan-issue-bot -->"
335+
336+ - name : " Post/update PR comment (changes)"
337+ if : needs.evaluate.outputs.pr-evaluate-exit-code == '2'
338+ uses : peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0
339+ with :
340+ comment-id : ${{ steps.find-comment.outputs.comment-id }}
341+ issue-number : ${{ github.event.pull_request.number }}
342+ edit-mode : replace
343+ body-path : pr-comment.md
344+
345+ - name : " Update PR comment (no changes, only if exists)"
346+ if : needs.evaluate.outputs.pr-evaluate-exit-code == '0' && steps.find-comment.outputs.comment-id != ''
347+ uses : peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0
348+ with :
349+ comment-id : ${{ steps.find-comment.outputs.comment-id }}
350+ edit-mode : replace
351+ body-path : pr-comment.md
0 commit comments