-
Notifications
You must be signed in to change notification settings - Fork 157
/
Copy pathindex.js
35 lines (29 loc) · 1.04 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
const core = require("@actions/core");
const { execSync } = require("child_process");
const { GitHub, context } = require("@actions/github");
const main = async () => {
const repoName = context.repo.repo;
const repoOwner = context.repo.owner;
const githubToken = core.getInput("github-token");
const testCommand = core.getInput("test-command") || "npx jest";
const prNumber = context.payload.number;
const githubClient = new GitHub(githubToken);
const codeCoverage = execSync(testCommand).toString();
let coveragePercentage = execSync(
"npx coverage-percentage ./coverage/lcov.info --lcov"
).toString();
coveragePercentage = parseFloat(coveragePercentage).toFixed(2);
const commentBody = `<p>Total Coverage: <code>${coveragePercentage}</code></p>
<details><summary>Coverage report</summary>
<p>
<pre>${codeCoverage}</pre>
</p>
</details>`;
await githubClient.issues.createComment({
repo: repoName,
owner: repoOwner,
body: commentBody,
issue_number: prNumber,
});
};
main().catch(err => core.setFailed(err.message));