-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
55 lines (45 loc) · 1.82 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
43
44
45
46
47
48
49
50
51
52
53
54
55
const core = require('@actions/core');
const process = require('process');
const { check, update } = require('./actions');
const { fail } = require('./core');
const { parseCoverages } = require('./coverage');
const fs = require('fs');
const path = require('path');
const ACTION = core.getInput('action');
const COVERAGE_BRANCH = core.getInput('coverage-branch');
const WITH_AVERAGE = core.getInput('with-average') === 'true';
const COVERAGE_DIRECTORY = core.getInput('directory');
const COVERAGE_FILES = JSON.parse(core.getInput('files'));
const REPO = `https://${process.env.GITHUB_ACTOR}:${core.getInput('token')}@github.com/${process.env.GITHUB_REPOSITORY}.git`;
const HISTORY_FILENAME = 'coverage-history.json';
const REPORT_MESSAGE_HEADER = 'Issued by Coverage Checker:';
const buildFilesConfig = (directory, filesConfig) => {
if (COVERAGE_DIRECTORY === '') {
return filesConfig;
}
filesConfig = [];
fs.readdirSync(directory).filter(it => path.extname(it) === '.xml').forEach(fileName => {
const name = path.parse(fileName).name;
filesConfig.push({
coverage: directory + fileName,
summary: name + '-coverage-summary.json',
label: name + ' Coverage',
badge: name + '-coverage.svg'
})
})
return filesConfig;
}
const action = async () => {
try {
const coverageFiles = buildFilesConfig(COVERAGE_DIRECTORY, COVERAGE_FILES);
console.log('Parsing clover files...')
const coverages = await parseCoverages(coverageFiles);
await (ACTION === 'update'
? update(coverages, COVERAGE_BRANCH, REPO, HISTORY_FILENAME, coverageFiles)
: check(coverages, COVERAGE_BRANCH, coverageFiles, REPORT_MESSAGE_HEADER, WITH_AVERAGE)
);
} catch (error) {
fail(error.message);
}
};
action();