generated from actions/javascript-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
42 lines (36 loc) · 1.05 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
34
35
36
37
38
39
40
41
42
const fs = require('fs');
const axios = require('axios');
const core = require('@actions/core');
const { context } = require('@actions/github');
const run = async () => {
try {
const repo = context.repo.repo;
const owner = context.repo.owner;
const language = core.getInput('lang');
const dir = './.lighthouseci';
const [file] = fs
.readdirSync(dir)
.filter((f) => f.startsWith('lhr-') && f.endsWith('.json'));
const lhr = JSON.parse(fs.readFileSync(`${dir}/${file}`, 'utf8'));
const { categories } = lhr;
const stats = Object.keys(categories)
.filter((key) => key !== 'pwa')
.reduce((props, key) => {
props[key.replace('-', '')] = categories[key].score;
return props;
}, {});
const report = {
repo,
owner,
language,
...stats,
type: 'challenge-04',
source: 'lighthouse'
};
const server = core.getInput('server');
await axios.post(`${server}/api/entry-tests`, { report });
} catch (error) {
core.setFailed(error.message);
}
};
run();