forked from guyarb/golang-test-annotations
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
47 lines (44 loc) · 1.48 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
const core = require('@actions/core');
const lineReader = require('line-by-line');
try {
const testResultsPath = core.getInput('test-results');
const customPackageName = core.getInput('package-name');
var obj = new Object();
var lr = new lineReader(testResultsPath);
lr.on('line', function(line) {
const currentLine = JSON.parse(line);
var testName = currentLine.Test;
if (typeof testName === "undefined") {
return;
}
var output = currentLine.Output;
if (typeof output === "undefined") {
return;
}
output = output.replace("\n", "%0A").replace("\r", "%0D")
// Strip github.com/owner/repo package from the path by default
var packageName = currentLine.Package.split("/").slice(3).join("/");
// If custom package is provided, strip custom package name from the path
if (customPackageName != null) {
packageName = currentLine.Package.replace(customPackageName + "/", "")
}
var newEntry = packageName + "/" + testName;
if (!obj.hasOwnProperty(newEntry)) {
obj[newEntry] = output;
} else {
obj[newEntry] += output;
}
});
lr.on('end', function() {
for (const [key, value] of Object.entries(obj)) {
if (value.includes("FAIL") && value.includes("_test.go")) {
const parts = value.split("%0A")[1].trim().split(":");
const file = key.split("/").slice(0, -1).join("/") + "/" + parts[0];
const lineNumber = parts[1];
core.info(`::error file=${file},line=${lineNumber}::${value}`)
}
}
});
} catch (error) {
core.setFailed(error.message);
}