forked from luk-schweizer/jest-code-coverage-badge-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.js
44 lines (34 loc) · 1.55 KB
/
action.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
43
44
const core = require('@actions/core');
const exec = require('@actions/exec');
const keyValueAsService = require('./keyValueAsService');
const coverage = require('./coverage');
const badge = require('./badge');
module.exports.run = async () => {
const testCommand = core.getInput('test-command');
await exec.exec(testCommand);
const coverageType = getCoverageType();
const coveragePercentage = await coverage.percentage('./coverage/clover.xml', coverageType);
const schema = getCoverageSchema(coveragePercentage);
const kvaasKeyUrl = await getKeyValueAsServiceUrl();
await keyValueAsService.setKeyValue(kvaasKeyUrl, schema);
core.setOutput('BADGE_URL', encodeURI(`https://img.shields.io/endpoint?url=${kvaasKeyUrl}`));
};
const getCoverageType = () => {
const coverageType = core.getInput('coverage-type');
if (!coverage.isValidType(coverageType)) throw new Error('Input coverage-type is not recognized');
return coverageType;
};
const getKeyValueAsServiceUrl = async () => {
const kvaasKeyUrl = core.getInput('kvaas-key-url');
if (!kvaasKeyUrl) {
return await keyValueAsService.createNewUrl();
}
if (!keyValueAsService.isUrlValid(kvaasKeyUrl)) throw new Error('Input kvaas-key-url is not valid');
return kvaasKeyUrl;
};
const getCoverageSchema = (coveragePercentage) => {
const colorConfiguration = JSON.parse(core.getInput('badge-color-configuration'));
const label = core.getInput('badge-label');
const showJestLogo = core.getInput('badge-logo');
return badge.schema(coveragePercentage, label, colorConfiguration, showJestLogo);
};