11name : Plugin Live Check
22
33on :
4- pull_request :
4+ pull_request_target :
55 branches : [master]
66 workflow_dispatch :
77 inputs :
1111 type : string
1212
1313concurrency :
14- group : ${{ github.workflow }}-${{ github.ref }}
14+ group : ${{ github.workflow }}-${{ github.event.pull_request.number || github. ref }}
1515 cancel-in-progress : true
1616
17+ permissions : {}
18+
1719jobs :
1820 live-check :
1921 name : Plugin Live Check
2022 runs-on : ubuntu-latest
2123
24+ outputs :
25+ should_comment : ${{ steps.comment-artifact.outputs.should_comment }}
26+
2227 permissions :
2328 contents : read
24- pull-requests : write
2529
2630 steps :
31+ - name : Checkout PR Merge Commit
32+ if : github.event_name == 'pull_request_target'
33+ uses : actions/checkout@v4
34+ with :
35+ ref : refs/pull/${{ github.event.pull_request.number }}/merge
36+ fetch-depth : 0
37+
2738 - name : Checkout Repository
39+ if : github.event_name == 'workflow_dispatch'
2840 uses : actions/checkout@v4
2941 with :
3042 fetch-depth : 0
3143
3244 - name : Get Changed Plugin Files
3345 id : changed-files
34- if : github.event_name == 'pull_request '
46+ if : github.event_name == 'pull_request_target '
3547 uses : tj-actions/changed-files@v45
3648 with :
3749 files : |
5567 uses : actions/setup-node@v4
5668 with :
5769 node-version : ' 20'
58- cache : ' npm'
70+ # Avoid writing contributor-controlled caches in the base branch's
71+ # cache scope when running under pull_request_target.
72+ cache : ${{ github.event_name == 'workflow_dispatch' && 'npm' || '' }}
5973
6074 - name : Install Dependencies
6175 if : steps.targets.outputs.files != ''
@@ -73,15 +87,49 @@ jobs:
7387 echo "exit_code=$?" >> "$GITHUB_OUTPUT"
7488 cat live-check-output.txt
7589
76- - name : Post PR Comment
77- if : github.event_name == 'pull_request' && steps.changed-files.outputs.any_changed == 'true'
78- uses : marocchino/sticky-pull-request-comment@v2
90+ - name : Prepare PR Comment Artifact
91+ id : comment-artifact
92+ if : always() && github.event_name == 'pull_request_target'
93+ run : |
94+ if [ "${{ steps.changed-files.outputs.any_changed }}" = 'true' ] && [ -f live-check-output.txt ]; then
95+ echo 'should_comment=true' >> "$GITHUB_OUTPUT"
96+ else
97+ echo 'should_comment=false' >> "$GITHUB_OUTPUT"
98+ fi
99+
100+ - name : Upload PR Comment Artifact
101+ if : always() && steps.comment-artifact.outputs.should_comment == 'true'
102+ uses : actions/upload-artifact@v4
79103 with :
80- header : plugin-live-check
104+ name : plugin-live-check-comment
81105 path : live-check-output.txt
106+ retention-days : 1
82107
83108 - name : Fail On Real Errors
84109 if : steps.targets.outputs.files != '' && steps.live-check.outputs.exit_code != '0'
85110 run : |
86111 echo "Live check reported at least one FAIL — see the job log or PR comment above."
87112 exit 1
113+
114+ comment :
115+ name : Post PR Comment
116+ needs : live-check
117+ if : always() && github.event_name == 'pull_request_target' && needs.live-check.outputs.should_comment == 'true'
118+ runs-on : ubuntu-latest
119+
120+ permissions :
121+ actions : read
122+ pull-requests : write
123+
124+ steps :
125+ - name : Download PR Comment Artifact
126+ uses : actions/download-artifact@v4
127+ with :
128+ name : plugin-live-check-comment
129+
130+ - name : Post PR Comment
131+ uses : marocchino/sticky-pull-request-comment@v3
132+ with :
133+ number : ${{ github.event.pull_request.number }}
134+ header : plugin-live-check
135+ path : live-check-output.txt
0 commit comments