forked from JakePartusch/psi-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
33 lines (29 loc) · 1.23 KB
/
index.js
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
const core = require("@actions/core");
const psi = require("psi");
// const requiredMetrics = ["first-contentful-paint", "speed-index", "largest-contentful-paint", "interactive", "total-blocking-time", "cumulative-layout-shift"];
const run = async () => {
try {
const url = core.getInput("url") || "https://seller.blinkit.com";
if (!url) {
core.setFailed("Url is required to run Page Speed Insights.");
return;
}
const key = core.getInput('key');
const threshold = Number(core.getInput("threshold")) || 0;
const strategy = core.getInput("strategy") || "desktop";
// Output a formatted report to the terminal
console.log(`Running Page Speed Insights for ${url}`);
const { data } = await psi(url, {
...(key ? {key} : undefined),
...(key ? undefined : {nokey: "true"}),
strategy,
format: "cli",
threshold
});
// core.setOutput("performance_metrics", data.lighthouseResult.categories.performance.auditRefs.filter(audit => requiredMetrics.includes(audit.id))?.map(audit => ({[audit.id]: audit.weight})));
core.setOutput("performance_score", 100*data.lighthouseResult.categories.performance.score);
} catch (error) {
core.setFailed(error.message);
}
};
run();