Skip to content

Commit 18f78fc

Browse files
fix: Format and Post Plugin Live Check Results
1 parent 65f6f5f commit 18f78fc

2 files changed

Lines changed: 91 additions & 20 deletions

File tree

.github/workflows/plugin-live-check.yml

Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: Plugin Live Check
22

33
on:
4-
pull_request:
4+
pull_request_target:
55
branches: [master]
66
workflow_dispatch:
77
inputs:
@@ -11,27 +11,39 @@ on:
1111
type: string
1212

1313
concurrency:
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+
1719
jobs:
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: |
@@ -55,7 +67,9 @@ jobs:
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

scripts/live-check-plugin.js

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ async function bundlePlugin(pluginPath) {
8484
format: 'cjs',
8585
target: 'node22',
8686
write: false,
87+
logLevel: 'silent',
8788
alias: {
8889
'@libs': path.join(REPO_ROOT, 'src/libs'),
8990
'@': path.join(REPO_ROOT, 'src'),
@@ -317,35 +318,57 @@ async function checkPlugin(pluginPath) {
317318
return result;
318319
}
319320

321+
function escapeMarkdown(value) {
322+
return String(value)
323+
.replaceAll('&', '&')
324+
.replaceAll('<', '&lt;')
325+
.replaceAll('>', '&gt;')
326+
.replaceAll('`', '&#96;')
327+
.replaceAll('|', '\\|')
328+
.replace(/\r?\n/g, '<br>');
329+
}
330+
320331
function printReport(results) {
321332
let hasFail = false;
333+
let hasInconclusive = false;
334+
335+
console.log('## Plugin Live Check');
336+
322337
for (const result of results) {
323-
console.log('\n' + '='.repeat(80));
324-
console.log(result.pluginPath);
325-
console.log('='.repeat(80));
338+
console.log(`\n### \`${escapeMarkdown(result.pluginPath)}\``);
339+
console.log('\n| Check | Result | Details |');
340+
console.log('| --- | --- | --- |');
326341

327342
if (result.loadError) {
328343
hasFail = true;
329-
console.log(` BUNDLE/LOAD FAIL — ${result.loadError}`);
344+
console.log(
345+
`| \`bundle/load\` | ❌ FAIL | ${escapeMarkdown(result.loadError)} |`,
346+
);
330347
continue;
331348
}
332349

333350
for (const step of result.steps) {
334-
const icon =
335-
step.status === 'PASS' ? '✓' : step.status === 'FAIL' ? '✗' : '~';
351+
const resultLabel =
352+
step.status === 'PASS'
353+
? '✅ PASS'
354+
: step.status === 'FAIL'
355+
? '❌ FAIL'
356+
: '⚠️ INCONCLUSIVE';
336357
console.log(
337-
` ${icon} ${step.status.padEnd(12)} ${step.name} ${step.detail}`,
358+
`| \`${escapeMarkdown(step.name)}\` | ${resultLabel} | ${escapeMarkdown(step.detail)} |`,
338359
);
339360
if (step.status === 'FAIL') hasFail = true;
361+
if (step.status === 'INCONCLUSIVE') hasInconclusive = true;
340362
}
341363
}
342-
console.log('\n' + '='.repeat(80));
364+
343365
console.log(
344366
hasFail
345-
? 'RESULT: FAIL (at least one step failed)'
346-
: 'RESULT: OK (no hard failures)',
367+
? '\n**Result: ❌ Failed — at least one check failed.**'
368+
: hasInconclusive
369+
? '\n**Result: ⚠️ Inconclusive — no hard failures.**'
370+
: '\n**Result: ✅ Passed — all checks succeeded.**',
347371
);
348-
console.log('='.repeat(80));
349372
return hasFail;
350373
}
351374

0 commit comments

Comments
 (0)