Skip to content

Commit 20e3fa4

Browse files
Chore: add PR comment on plugin validation fail (#55)
1 parent ad16df8 commit 20e3fa4

1 file changed

Lines changed: 74 additions & 1 deletion

File tree

.github/workflows/ci.yml

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name: CI
22
permissions:
33
contents: read
4+
pull-requests: write
45

56
on:
67
push:
@@ -118,13 +119,85 @@ jobs:
118119
grafana/plugin-validator-cli -analyzer=metadatavalid /archive.zip
119120
120121
- name: Validate plugin
122+
id: validate
121123
continue-on-error: true
122124
run: |
123-
npx -y @grafana/plugin-validator@latest -sourceCodeUri file://./ $PLUGIN_ARCHIVE
125+
set -o pipefail
126+
npx -y @grafana/plugin-validator@latest -sourceCodeUri file://./ $PLUGIN_ARCHIVE 2>&1 | tee validate-output.txt
124127
shell: bash
125128
env:
126129
PLUGIN_ARCHIVE: ${{ steps.metadata.outputs.archive }}
127130

131+
- name: Post validation results as PR comment
132+
if: steps.validate.outcome == 'failure' && github.event_name == 'pull_request'
133+
uses: actions/github-script@v7
134+
with:
135+
script: |
136+
const fs = require('fs');
137+
const raw = fs.readFileSync('validate-output.txt', 'utf8');
138+
const filtered = raw
139+
.split('\n')
140+
.filter(l => /^(error|warning|detail|recommendation):/.test(l))
141+
.join('\n');
142+
143+
const body = [
144+
'## :warning: Plugin Validation Failed',
145+
'',
146+
'Validation issues were found. These **will not block merging** but must be resolved before publishing to the Grafana plugin catalog.',
147+
'',
148+
'<details>',
149+
'<summary>Validation output</summary>',
150+
'',
151+
'```',
152+
filtered,
153+
'```',
154+
'',
155+
'</details>',
156+
].join('\n');
157+
158+
const { data: comments } = await github.rest.issues.listComments({
159+
owner: context.repo.owner,
160+
repo: context.repo.repo,
161+
issue_number: context.issue.number,
162+
});
163+
164+
const existing = comments.find(c => c.body.includes('Plugin Validation Failed'));
165+
if (existing) {
166+
await github.rest.issues.updateComment({
167+
owner: context.repo.owner,
168+
repo: context.repo.repo,
169+
comment_id: existing.id,
170+
body,
171+
});
172+
} else {
173+
await github.rest.issues.createComment({
174+
owner: context.repo.owner,
175+
repo: context.repo.repo,
176+
issue_number: context.issue.number,
177+
body,
178+
});
179+
}
180+
181+
- name: Write validation summary
182+
if: steps.validate.outcome == 'failure'
183+
shell: bash
184+
run: |
185+
filtered=$(grep -E '^(error|warning|detail|recommendation):' validate-output.txt || true)
186+
{
187+
echo "## :warning: Plugin Validation Failed"
188+
echo ""
189+
echo "Validation issues were found. These will not block merging but must be resolved before publishing to the Grafana plugin catalog."
190+
echo ""
191+
echo "<details>"
192+
echo "<summary>Validation output</summary>"
193+
echo ""
194+
echo '```'
195+
echo "$filtered"
196+
echo '```'
197+
echo ""
198+
echo "</details>"
199+
} >> "$GITHUB_STEP_SUMMARY"
200+
128201
- name: Archive Build
129202
uses: actions/upload-artifact@v4
130203
with:

0 commit comments

Comments
 (0)