-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
84 lines (70 loc) · 2.97 KB
/
index.js
File metadata and controls
84 lines (70 loc) · 2.97 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
const core = require('@actions/core');
const https = require('https');
const GRADER_API = 'https://grade.grabshot.dev/api/grade';
function fetchJSON(url) {
return new Promise((resolve, reject) => {
https.get(url, { timeout: 60000 }, (res) => {
let data = '';
res.on('data', d => data += d);
res.on('end', () => {
try { resolve(JSON.parse(data)); }
catch { reject(new Error('Invalid response from grader API')); }
});
}).on('error', reject);
});
}
async function run() {
try {
const url = core.getInput('url', { required: true });
const threshold = parseInt(core.getInput('threshold') || '0', 10);
const categories = (core.getInput('categories') || 'meta,security,performance').split(',').map(s => s.trim());
core.info(`Auditing ${url}...`);
const grade = await fetchJSON(`${GRADER_API}?url=${encodeURIComponent(url)}`);
const overall = grade.overall || 0;
const meta = grade.scores?.meta || 0;
const security = grade.scores?.security || 0;
const perf = grade.scores?.performance || 0;
const allIssues = [
...(categories.includes('meta') ? (grade.details?.metaIssues || []) : []),
...(categories.includes('security') ? (grade.details?.securityIssues || []) : []),
...(categories.includes('performance') ? (grade.details?.perfIssues || []) : []),
];
const domain = new URL(url).hostname;
const reportUrl = `https://grade.grabshot.dev/report/${domain}`;
// Set outputs
core.setOutput('overall', overall.toString());
core.setOutput('meta', meta.toString());
core.setOutput('security', security.toString());
core.setOutput('performance', perf.toString());
core.setOutput('issues', JSON.stringify(allIssues));
core.setOutput('report-url', reportUrl);
// Summary
const icon = overall >= 80 ? '✅' : overall >= 60 ? '⚠️' : '❌';
core.info('');
core.info(`${icon} Overall Score: ${overall}/100`);
core.info(` SEO & Meta: ${meta}/100`);
core.info(` Security: ${security}/100`);
core.info(` Performance: ${perf}/100`);
if (allIssues.length > 0) {
core.info('');
core.info('Issues found:');
allIssues.forEach(issue => core.info(` - ${issue}`));
}
core.info('');
core.info(`Full report: ${reportUrl}`);
// Write job summary
await core.summary
.addHeading(`Website Audit: ${domain}`)
.addRaw(`| Category | Score |\n|---|---|\n| Overall | **${overall}**/100 ${icon} |\n| SEO & Meta | ${meta}/100 |\n| Security | ${security}/100 |\n| Performance | ${perf}/100 |\n`)
.addRaw(allIssues.length > 0 ? `\n**Issues:**\n${allIssues.map(i => `- ${i}`).join('\n')}\n` : '\n✅ No issues found!\n')
.addLink('View Full Report', reportUrl)
.write();
// Threshold check
if (threshold > 0 && overall < threshold) {
core.setFailed(`Score ${overall} is below threshold ${threshold}`);
}
} catch (error) {
core.setFailed(`Audit failed: ${error.message}`);
}
}
run();