-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
49 lines (45 loc) · 1.54 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
const core = require('@actions/core');
const path = require('path');
const fs = require('fs');
const util = require('util');
const readFile = util.promisify(fs.readFile);
const file = core.getInput('file');
async function main() {
try {
const contents = await readFile(path.join(file), 'UTF-8');
console.log(contents);
if (file.includes('json')) {
const data = JSON.parse(contents);
Object.keys(data).forEach(key => {
if (key.includes('errorMessage') || key.includes('errorType')) {
console.log(data);
throw 'Error: ' + data.errorMessage;
}
});
} else {
const lines = contents.split('\n');
let lastLine = '';
while (lastLine === '') {
lastLine = lines.pop();
console.log(lastLine);
}
if (lastLine.includes('REPORT')) {
console.log('No errors found, assuming success.');
return;
}
console.log('Last line:' + lastLine);
const data = JSON.parse(lastLine);
Object.keys(data).forEach(key => {
if (key.includes('errorMessage') || key.includes('errorType')) {
console.log(data);
throw 'Error: ' + data.errorMessage;
}
});
}
} catch (e) {
core.setFailed(e.message);
}
};
(async () => {
await main();
})();