fix: Format and Post Plugin Live Check Results

This commit is contained in:
Rajarshee Chatterjee
2026-08-10 07:59:17 +05:30
parent 65f6f5fbfa
commit 18f78fc3d3
2 changed files with 91 additions and 20 deletions
+57 -9
View File
@@ -1,7 +1,7 @@
name: Plugin Live Check name: Plugin Live Check
on: on:
pull_request: pull_request_target:
branches: [master] branches: [master]
workflow_dispatch: workflow_dispatch:
inputs: inputs:
@@ -11,27 +11,39 @@ on:
type: string type: string
concurrency: concurrency:
group: ${{ github.workflow }}-${{ github.ref }} group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true cancel-in-progress: true
permissions: {}
jobs: jobs:
live-check: live-check:
name: Plugin Live Check name: Plugin Live Check
runs-on: ubuntu-latest runs-on: ubuntu-latest
outputs:
should_comment: ${{ steps.comment-artifact.outputs.should_comment }}
permissions: permissions:
contents: read contents: read
pull-requests: write
steps: steps:
- name: Checkout PR Merge Commit
if: github.event_name == 'pull_request_target'
uses: actions/checkout@v4
with:
ref: refs/pull/${{ github.event.pull_request.number }}/merge
fetch-depth: 0
- name: Checkout Repository - name: Checkout Repository
if: github.event_name == 'workflow_dispatch'
uses: actions/checkout@v4 uses: actions/checkout@v4
with: with:
fetch-depth: 0 fetch-depth: 0
- name: Get Changed Plugin Files - name: Get Changed Plugin Files
id: changed-files id: changed-files
if: github.event_name == 'pull_request' if: github.event_name == 'pull_request_target'
uses: tj-actions/changed-files@v45 uses: tj-actions/changed-files@v45
with: with:
files: | files: |
@@ -55,7 +67,9 @@ jobs:
uses: actions/setup-node@v4 uses: actions/setup-node@v4
with: with:
node-version: '20' node-version: '20'
cache: 'npm' # Avoid writing contributor-controlled caches in the base branch's
# cache scope when running under pull_request_target.
cache: ${{ github.event_name == 'workflow_dispatch' && 'npm' || '' }}
- name: Install Dependencies - name: Install Dependencies
if: steps.targets.outputs.files != '' if: steps.targets.outputs.files != ''
@@ -73,15 +87,49 @@ jobs:
echo "exit_code=$?" >> "$GITHUB_OUTPUT" echo "exit_code=$?" >> "$GITHUB_OUTPUT"
cat live-check-output.txt cat live-check-output.txt
- name: Post PR Comment - name: Prepare PR Comment Artifact
if: github.event_name == 'pull_request' && steps.changed-files.outputs.any_changed == 'true' id: comment-artifact
uses: marocchino/sticky-pull-request-comment@v2 if: always() && github.event_name == 'pull_request_target'
run: |
if [ "${{ steps.changed-files.outputs.any_changed }}" = 'true' ] && [ -f live-check-output.txt ]; then
echo 'should_comment=true' >> "$GITHUB_OUTPUT"
else
echo 'should_comment=false' >> "$GITHUB_OUTPUT"
fi
- name: Upload PR Comment Artifact
if: always() && steps.comment-artifact.outputs.should_comment == 'true'
uses: actions/upload-artifact@v4
with: with:
header: plugin-live-check name: plugin-live-check-comment
path: live-check-output.txt path: live-check-output.txt
retention-days: 1
- name: Fail On Real Errors - name: Fail On Real Errors
if: steps.targets.outputs.files != '' && steps.live-check.outputs.exit_code != '0' if: steps.targets.outputs.files != '' && steps.live-check.outputs.exit_code != '0'
run: | run: |
echo "Live check reported at least one FAIL — see the job log or PR comment above." echo "Live check reported at least one FAIL — see the job log or PR comment above."
exit 1 exit 1
comment:
name: Post PR Comment
needs: live-check
if: always() && github.event_name == 'pull_request_target' && needs.live-check.outputs.should_comment == 'true'
runs-on: ubuntu-latest
permissions:
actions: read
pull-requests: write
steps:
- name: Download PR Comment Artifact
uses: actions/download-artifact@v4
with:
name: plugin-live-check-comment
- name: Post PR Comment
uses: marocchino/sticky-pull-request-comment@v3
with:
number: ${{ github.event.pull_request.number }}
header: plugin-live-check
path: live-check-output.txt
+34 -11
View File
@@ -84,6 +84,7 @@ async function bundlePlugin(pluginPath) {
format: 'cjs', format: 'cjs',
target: 'node22', target: 'node22',
write: false, write: false,
logLevel: 'silent',
alias: { alias: {
'@libs': path.join(REPO_ROOT, 'src/libs'), '@libs': path.join(REPO_ROOT, 'src/libs'),
'@': path.join(REPO_ROOT, 'src'), '@': path.join(REPO_ROOT, 'src'),
@@ -317,35 +318,57 @@ async function checkPlugin(pluginPath) {
return result; return result;
} }
function escapeMarkdown(value) {
return String(value)
.replaceAll('&', '&')
.replaceAll('<', '&lt;')
.replaceAll('>', '&gt;')
.replaceAll('`', '&#96;')
.replaceAll('|', '\\|')
.replace(/\r?\n/g, '<br>');
}
function printReport(results) { function printReport(results) {
let hasFail = false; let hasFail = false;
let hasInconclusive = false;
console.log('## Plugin Live Check');
for (const result of results) { for (const result of results) {
console.log('\n' + '='.repeat(80)); console.log(`\n### \`${escapeMarkdown(result.pluginPath)}\``);
console.log(result.pluginPath); console.log('\n| Check | Result | Details |');
console.log('='.repeat(80)); console.log('| --- | --- | --- |');
if (result.loadError) { if (result.loadError) {
hasFail = true; hasFail = true;
console.log(` BUNDLE/LOAD FAIL — ${result.loadError}`); console.log(
`| \`bundle/load\` | ❌ FAIL | ${escapeMarkdown(result.loadError)} |`,
);
continue; continue;
} }
for (const step of result.steps) { for (const step of result.steps) {
const icon = const resultLabel =
step.status === 'PASS' ? '✓' : step.status === 'FAIL' ? '✗' : '~'; step.status === 'PASS'
? '✅ PASS'
: step.status === 'FAIL'
? '❌ FAIL'
: '⚠️ INCONCLUSIVE';
console.log( console.log(
` ${icon} ${step.status.padEnd(12)} ${step.name} — ${step.detail}`, `| \`${escapeMarkdown(step.name)}\` | ${resultLabel} | ${escapeMarkdown(step.detail)} |`,
); );
if (step.status === 'FAIL') hasFail = true; if (step.status === 'FAIL') hasFail = true;
if (step.status === 'INCONCLUSIVE') hasInconclusive = true;
} }
} }
console.log('\n' + '='.repeat(80));
console.log( console.log(
hasFail hasFail
? 'RESULT: FAIL (at least one step failed)' ? '\n**Result: ❌ Failed — at least one check failed.**'
: 'RESULT: OK (no hard failures)', : hasInconclusive
? '\n**Result: ⚠️ Inconclusive — no hard failures.**'
: '\n**Result: ✅ Passed — all checks succeeded.**',
); );
console.log('='.repeat(80));
return hasFail; return hasFail;
} }