Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
55 lines (45 loc) · 1.81 KB
/
Copy pathindex.js
File metadata and controls
55 lines (45 loc) · 1.81 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
import * as core from '@actions/core';
import process from 'process';
import { check, update } from './actions.js';
import { fail } from './core.js';
import { parseCoverages } from './coverage.js';
import fs from 'fs';
import path from '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();