|
1 | 1 | name: CI |
2 | 2 | permissions: |
3 | 3 | contents: read |
| 4 | + pull-requests: write |
4 | 5 |
|
5 | 6 | on: |
6 | 7 | push: |
@@ -118,13 +119,85 @@ jobs: |
118 | 119 | grafana/plugin-validator-cli -analyzer=metadatavalid /archive.zip |
119 | 120 |
|
120 | 121 | - name: Validate plugin |
| 122 | + id: validate |
121 | 123 | continue-on-error: true |
122 | 124 | 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 |
124 | 127 | shell: bash |
125 | 128 | env: |
126 | 129 | PLUGIN_ARCHIVE: ${{ steps.metadata.outputs.archive }} |
127 | 130 |
|
| 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 | +
|
128 | 201 | - name: Archive Build |
129 | 202 | uses: actions/upload-artifact@v4 |
130 | 203 | with: |
|
0 commit comments