-
Notifications
You must be signed in to change notification settings - Fork 4.1k
245 lines (215 loc) · 8.77 KB
/
skill-check-comment.yml
File metadata and controls
245 lines (215 loc) · 8.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
name: Skill Validator — PR Comment
# Posts results from the "Skill Validator — PR Gate" workflow.
# Runs with write permissions but never checks out PR code,
# so it is safe for fork PRs.
on:
workflow_run:
workflows: ["Skill Validator — PR Gate"]
types: [completed]
permissions:
issues: write
pull-requests: write
actions: read # needed to download artifacts
jobs:
comment:
runs-on: ubuntu-latest
if: github.event.workflow_run.event == 'pull_request'
steps:
- name: Download results artifact
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: skill-validator-results
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ github.token }}
- name: Post PR comment with results
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7.1.0
with:
script: |
const fs = require('fs');
const managedLabels = {
'skill-check-warning': {
color: 'FBCA04',
description: 'Skill validator reported warnings'
},
'skill-check-error': {
color: 'B60205',
description: 'Skill validator reported errors'
}
};
async function ensureLabel(name, { color, description }) {
try {
await github.rest.issues.createLabel({
owner: context.repo.owner,
repo: context.repo.repo,
name,
color,
description
});
} catch (error) {
if (error.status !== 422) {
throw error;
}
}
}
async function syncManagedLabels(issueNumber, desiredLabels) {
await Promise.all(
Object.entries(managedLabels).map(([name, config]) => ensureLabel(name, config))
);
const currentLabels = await github.paginate(github.rest.issues.listLabelsOnIssue, {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
per_page: 100
});
const currentManagedLabels = currentLabels
.map((label) => label.name)
.filter((name) => Object.prototype.hasOwnProperty.call(managedLabels, name));
const labelsToAdd = [...desiredLabels].filter((name) => !currentManagedLabels.includes(name));
const labelsToRemove = currentManagedLabels.filter((name) => !desiredLabels.has(name));
if (labelsToAdd.length > 0) {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
labels: labelsToAdd
});
}
for (const name of labelsToRemove) {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
name
});
}
console.log(`Managed skill check labels: ${[...desiredLabels].sort().join(', ') || 'none'}`);
}
const prNumber = parseInt(fs.readFileSync('pr-number.txt', 'utf8').trim(), 10);
const total = parseInt(fs.readFileSync('total.txt', 'utf8').trim(), 10);
const exitCode = fs.readFileSync('exit-code.txt', 'utf8').trim();
const skillCount = parseInt(fs.readFileSync('skill-count.txt', 'utf8').trim(), 10);
const agentCount = parseInt(fs.readFileSync('agent-count.txt', 'utf8').trim(), 10);
const totalChecked = skillCount + agentCount;
const marker = '<!-- skill-validator-results -->';
const rawOutput = fs.existsSync('sv-output.txt')
? fs.readFileSync('sv-output.txt', 'utf8')
: '';
const output = rawOutput.replace(/\x1b\[[0-9;]*m/g, '').trim();
const errorCount = (output.match(/❌/g) || []).length;
const warningCount = (output.match(/⚠/g) || []).length;
const advisoryCount = (output.match(/ℹ/g) || []).length;
const desiredLabels = new Set();
if (warningCount > 0) {
desiredLabels.add('skill-check-warning');
}
if (exitCode !== '0' || errorCount > 0) {
desiredLabels.add('skill-check-error');
}
await syncManagedLabels(prNumber, desiredLabels);
if (total === 0) {
console.log('No skills/agents were checked — skipping comment.');
return;
}
let verdict = '✅ All checks passed';
if (exitCode !== '0' || errorCount > 0) {
verdict = '⛔ Findings need attention';
} else if (warningCount > 0 || advisoryCount > 0) {
verdict = '⚠️ Warnings or advisories found';
}
const highlightedLines = output
.split('\n')
.map(line => line.trim())
.filter(Boolean)
.filter(line => !line.startsWith('###'))
.filter(line => /^[❌⚠ℹ]/.test(line));
const summaryLines = highlightedLines.length > 0
? highlightedLines.slice(0, 10)
: output
.split('\n')
.map(line => line.trim())
.filter(Boolean)
.filter(line => !line.startsWith('###'))
.slice(0, 10);
const scopeTable = [
'| Scope | Checked |',
'|---|---:|',
`| Skills | ${skillCount} |`,
`| Agents | ${agentCount} |`,
`| Total | ${totalChecked} |`,
];
const severityTable = [
'| Severity | Count |',
'|---|---:|',
`| ❌ Errors | ${errorCount} |`,
`| ⚠️ Warnings | ${warningCount} |`,
`| ℹ️ Advisories | ${advisoryCount} |`,
];
const findingsTable = summaryLines.length === 0
? ['_No findings were emitted by the validator._']
: [
'| Level | Finding |',
'|---|---|',
...summaryLines.map(line => {
const level = line.startsWith('❌')
? '❌'
: line.startsWith('⚠')
? '⚠️'
: line.startsWith('ℹ')
? 'ℹ️'
: (exitCode !== '0' ? '⛔' : 'ℹ️');
const text = line.replace(/^[❌⚠ℹ️\s]+/, '').replace(/\|/g, '\\|');
return `| ${level} | ${text} |`;
}),
];
const body = [
marker,
'## 🔍 Skill Validator Results',
'',
`**${verdict}**`,
'',
...scopeTable,
'',
...severityTable,
'',
'### Summary',
'',
...findingsTable,
'',
'<details>',
'<summary>Full validator output</summary>',
'',
'```text',
output || 'No validator output captured.',
'```',
'',
'</details>',
'',
exitCode !== '0'
? '> **Note:** The validator returned a non-zero exit code. Please review the findings above before merge.'
: '',
].filter(Boolean).join('\n');
// Find existing comment with our marker
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
per_page: 100,
});
const existing = comments.find(c => c.body.includes(marker));
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});
console.log(`Updated existing comment ${existing.id}`);
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body,
});
console.log('Created new PR comment');
}