-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrender-comment.cjs
More file actions
78 lines (70 loc) · 2.6 KB
/
Copy pathrender-comment.cjs
File metadata and controls
78 lines (70 loc) · 2.6 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
#!/usr/bin/env node
/**
* Small glue between the aeo-audit CLI and the GitHub Action. It does NOT compute
* any verdict — that is owned by `aeo-audit compare` (typed + vitest-tested). It
* only:
* --extract-score <report.json> → prints the report's headline score
* --extract-outputs <compare.json> → prints `key=value` lines for $GITHUB_OUTPUT
*
* Plain CommonJS with zero dependencies so it runs on any runner without an install.
*/
'use strict'
const fs = require('node:fs')
function die(message) {
process.stderr.write(`render-comment: ${message}\n`)
process.exit(1)
}
function readJson(path) {
let raw
try {
raw = fs.readFileSync(path, 'utf-8')
} catch {
die(`could not read ${path}`)
}
try {
return JSON.parse(raw)
} catch {
die(`invalid JSON in ${path}`)
}
}
/** A single line, safe to write as `key=value` into $GITHUB_OUTPUT. */
function oneLine(value) {
return String(value).replace(/\r?\n/g, ' ').trim()
}
const mode = process.argv[2]
const file = process.argv[3]
if (!mode || !file) die('usage: render-comment.cjs <--extract-score|--extract-outputs> <file>')
if (mode === '--extract-score') {
const report = readJson(file)
const score = typeof report.aggregateScore === 'number' ? report.aggregateScore : report.overallScore
process.stdout.write(`${score ?? ''}`)
process.exit(0)
}
if (mode === '--extract-outputs') {
const r = readJson(file)
const gatingDefects = Array.isArray(r.newDefects)
? r.newDefects.filter((d) => d && d.kind !== 'new-page')
: []
const newCritical = gatingDefects.filter((d) => d.severity === 'critical').length
const regressedFactorIds = Array.isArray(r.regressedFactors)
? [...new Set(r.regressedFactors.map((f) => f.id))].join(',')
: ''
const lines = [
`result=${oneLine(r.result ?? '')}`,
`verdict=${oneLine(r.verdict ?? '')}`,
`score=${oneLine(r.currentScore ?? '')}`,
`baseline_score=${oneLine(r.baselineScore ?? '')}`,
`delta=${oneLine(r.overall ? r.overall.delta : '')}`,
`regression_count=${oneLine(r.regressionCount ?? 0)}`,
`regressed_factors=${oneLine(regressedFactorIds)}`,
`new_critical=${oneLine(newCritical)}`,
`dropped_pages=${oneLine(Array.isArray(r.droppedPages) ? r.droppedPages.length : 0)}`,
`removed_pages=${oneLine(Array.isArray(r.removedPages) ? r.removedPages.length : 0)}`,
`schema_drift=${oneLine(r.schemaDrift ?? 'none')}`,
`engine_drift=${oneLine(r.engineDrift ?? 'unknown')}`,
`fail_reason=${oneLine((r.failReasons ?? []).join(' | '))}`,
]
process.stdout.write(lines.join('\n') + '\n')
process.exit(0)
}
die(`unknown mode ${mode}`)