forked from romeovs/lcov-reporter-action
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcli.js
More file actions
67 lines (63 loc) · 1.78 KB
/
cli.js
File metadata and controls
67 lines (63 loc) · 1.78 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
import process from "process";
import fs from "fs";
import path from "path";
import { diff, diffForMonorepo } from "./comment";
import { getLcovArray, readLcov } from "./monorepo";
import { checkCoverage } from "./check";
import { createBadges } from "./badge";
const addPackageName = (x) => ({
...x,
...{ packageName: x.dir.split("/").slice(-2)[0] },
});
const main = async () => {
const file = process.argv[2];
const beforeFile = process.argv[3];
const prefix = `${path.dirname(path.dirname(path.resolve(file)))}/`;
const options = {
repository: "example/foo",
commit: "f9d42291812ed03bb197e48050ac38ac6befe4e5",
prefix,
head: "feat/test",
base: "master",
maxLines: "10",
};
if (fs.statSync(file).isDirectory()) {
const lcovArrayForMonorepo = (
await getLcovArray(file, "lcov.info")
).map(addPackageName);
console.log(
diffForMonorepo(
lcovArrayForMonorepo,
await getLcovArray(file, "lcov-base"),
options,
),
);
createBadges("./badges", lcovArrayForMonorepo, {});
console.log(checkCoverage(90, lcovArrayForMonorepo));
} else {
const lcov = await readLcov(file);
console.log(
diff(lcov, beforeFile && (await readLcov(beforeFile)), options),
);
createBadges(
"./build",
{
packageName: "root",
lcov,
},
{},
);
console.log(
checkCoverage(90, [
{
packageName: "root",
lcov,
},
]),
);
}
};
main().catch((err) => {
console.log(err);
process.exit(1);
});