Skip to content

Commit a7869d3

Browse files
authored
Add working-directory option & build command (#27)
* add workingDirectory option * add build step
1 parent 9ab2ea8 commit a7869d3

File tree

5 files changed

+65
-37
lines changed

5 files changed

+65
-37
lines changed

action.yml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
1-
name: 'Golang Test Annotations'
2-
description: 'Given a test output of go test, the failed tests will be annotated.'
1+
name: "Golang Test Annotations"
2+
description: "Given a test output of go test, the failed tests will be annotated."
33
inputs:
4-
test-results: # Path of the test results
5-
description: 'The path of the go test results'
4+
test-results: # Path of the test results
5+
description: "The path of the go test results"
66
required: true
7-
default: 'test.json'
7+
default: "test.json"
88
package-name:
99
required: false
10-
description: 'Package name override'
10+
description: "Package name override"
11+
default:
12+
working-directory:
13+
description: "The path of the go module"
14+
required: false
1115
default:
1216
runs:
13-
using: 'node16'
14-
main: 'dist/index.js'
17+
using: "node16"
18+
main: "dist/index.js"
1519
branding:
1620
icon: "check"
1721
color: "green"

dist/index.js

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/******/ (() => { // webpackBootstrap
22
/******/ var __webpack_modules__ = ({
33

4-
/***/ 604:
4+
/***/ 351:
55
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
66

77
"use strict";
@@ -28,7 +28,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
2828
Object.defineProperty(exports, "__esModule", ({ value: true }));
2929
exports.issue = exports.issueCommand = void 0;
3030
const os = __importStar(__nccwpck_require__(37));
31-
const utils_1 = __nccwpck_require__(245);
31+
const utils_1 = __nccwpck_require__(278);
3232
/**
3333
* Commands
3434
*
@@ -100,7 +100,7 @@ function escapeProperty(s) {
100100

101101
/***/ }),
102102

103-
/***/ 127:
103+
/***/ 186:
104104
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
105105

106106
"use strict";
@@ -135,12 +135,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
135135
};
136136
Object.defineProperty(exports, "__esModule", ({ value: true }));
137137
exports.getIDToken = exports.getState = exports.saveState = exports.group = exports.endGroup = exports.startGroup = exports.info = exports.notice = exports.warning = exports.error = exports.debug = exports.isDebug = exports.setFailed = exports.setCommandEcho = exports.setOutput = exports.getBooleanInput = exports.getMultilineInput = exports.getInput = exports.addPath = exports.setSecret = exports.exportVariable = exports.ExitCode = void 0;
138-
const command_1 = __nccwpck_require__(604);
139-
const file_command_1 = __nccwpck_require__(352);
140-
const utils_1 = __nccwpck_require__(245);
138+
const command_1 = __nccwpck_require__(351);
139+
const file_command_1 = __nccwpck_require__(717);
140+
const utils_1 = __nccwpck_require__(278);
141141
const os = __importStar(__nccwpck_require__(37));
142142
const path = __importStar(__nccwpck_require__(17));
143-
const oidc_utils_1 = __nccwpck_require__(457);
143+
const oidc_utils_1 = __nccwpck_require__(41);
144144
/**
145145
* The code to exit an action
146146
*/
@@ -419,7 +419,7 @@ exports.getIDToken = getIDToken;
419419

420420
/***/ }),
421421

422-
/***/ 352:
422+
/***/ 717:
423423
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
424424

425425
"use strict";
@@ -450,7 +450,7 @@ exports.issueCommand = void 0;
450450
/* eslint-disable @typescript-eslint/no-explicit-any */
451451
const fs = __importStar(__nccwpck_require__(147));
452452
const os = __importStar(__nccwpck_require__(37));
453-
const utils_1 = __nccwpck_require__(245);
453+
const utils_1 = __nccwpck_require__(278);
454454
function issueCommand(command, message) {
455455
const filePath = process.env[`GITHUB_${command}`];
456456
if (!filePath) {
@@ -468,7 +468,7 @@ exports.issueCommand = issueCommand;
468468

469469
/***/ }),
470470

471-
/***/ 457:
471+
/***/ 41:
472472
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
473473

474474
"use strict";
@@ -484,9 +484,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
484484
};
485485
Object.defineProperty(exports, "__esModule", ({ value: true }));
486486
exports.OidcClient = void 0;
487-
const http_client_1 = __nccwpck_require__(840);
488-
const auth_1 = __nccwpck_require__(421);
489-
const core_1 = __nccwpck_require__(127);
487+
const http_client_1 = __nccwpck_require__(925);
488+
const auth_1 = __nccwpck_require__(702);
489+
const core_1 = __nccwpck_require__(186);
490490
class OidcClient {
491491
static createHttpClient(allowRetry = true, maxRetry = 10) {
492492
const requestOptions = {
@@ -552,7 +552,7 @@ exports.OidcClient = OidcClient;
552552

553553
/***/ }),
554554

555-
/***/ 245:
555+
/***/ 278:
556556
/***/ ((__unused_webpack_module, exports) => {
557557

558558
"use strict";
@@ -599,7 +599,7 @@ exports.toCommandProperties = toCommandProperties;
599599

600600
/***/ }),
601601

602-
/***/ 421:
602+
/***/ 702:
603603
/***/ ((__unused_webpack_module, exports) => {
604604

605605
"use strict";
@@ -665,15 +665,15 @@ exports.PersonalAccessTokenCredentialHandler = PersonalAccessTokenCredentialHand
665665

666666
/***/ }),
667667

668-
/***/ 840:
668+
/***/ 925:
669669
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
670670

671671
"use strict";
672672

673673
Object.defineProperty(exports, "__esModule", ({ value: true }));
674674
const http = __nccwpck_require__(685);
675675
const https = __nccwpck_require__(687);
676-
const pm = __nccwpck_require__(45);
676+
const pm = __nccwpck_require__(443);
677677
let tunnel;
678678
var HttpCodes;
679679
(function (HttpCodes) {
@@ -1092,7 +1092,7 @@ class HttpClient {
10921092
if (useProxy) {
10931093
// If using proxy, need tunnel
10941094
if (!tunnel) {
1095-
tunnel = __nccwpck_require__(265);
1095+
tunnel = __nccwpck_require__(294);
10961096
}
10971097
const agentOptions = {
10981098
maxSockets: maxSockets,
@@ -1210,7 +1210,7 @@ exports.HttpClient = HttpClient;
12101210

12111211
/***/ }),
12121212

1213-
/***/ 45:
1213+
/***/ 443:
12141214
/***/ ((__unused_webpack_module, exports) => {
12151215

12161216
"use strict";
@@ -1275,7 +1275,7 @@ exports.checkBypass = checkBypass;
12751275

12761276
/***/ }),
12771277

1278-
/***/ 631:
1278+
/***/ 752:
12791279
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
12801280

12811281
/*
@@ -1454,15 +1454,15 @@ module.exports = LineByLineReader;
14541454

14551455
/***/ }),
14561456

1457-
/***/ 265:
1457+
/***/ 294:
14581458
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
14591459

1460-
module.exports = __nccwpck_require__(686);
1460+
module.exports = __nccwpck_require__(219);
14611461

14621462

14631463
/***/ }),
14641464

1465-
/***/ 686:
1465+
/***/ 219:
14661466
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
14671467

14681468
"use strict";
@@ -1871,8 +1871,8 @@ module.exports = require("util");
18711871
var __webpack_exports__ = {};
18721872
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
18731873
(() => {
1874-
const core = __nccwpck_require__(127);
1875-
const lineReader = __nccwpck_require__(631);
1874+
const core = __nccwpck_require__(186);
1875+
const lineReader = __nccwpck_require__(752);
18761876
const fs = __nccwpck_require__(147);
18771877

18781878

@@ -1881,6 +1881,7 @@ try {
18811881

18821882
const testResultsPath = core.getInput('test-results');
18831883
const customPackageName = core.getInput('package-name');
1884+
const workingDirectory = core.getInput('working-directory');
18841885

18851886
if (!fs.existsSync(testResultsPath)) {
18861887
core.warning(
@@ -1891,7 +1892,7 @@ try {
18911892

18921893
let obj = {};
18931894
let lr = new lineReader(testResultsPath);
1894-
lr.on('line', function(line) {
1895+
lr.on('line', function (line) {
18951896
const currentLine = JSON.parse(line);
18961897
const testName = currentLine.Test;
18971898
if (typeof testName === "undefined") {
@@ -1915,14 +1916,17 @@ try {
19151916
packageName = currentLine.Package.replace(customPackageName + "/", "")
19161917
}
19171918
}
1919+
if (workingDirectory !== "") {
1920+
packageName = workingDirectory + "/" + packageName
1921+
}
19181922
let newEntry = packageName + "/" + testName;
19191923
if (!obj.hasOwnProperty(newEntry)) {
19201924
obj[newEntry] = output;
19211925
} else {
19221926
obj[newEntry] += output;
19231927
}
19241928
});
1925-
lr.on('end', function() {
1929+
lr.on('end', function () {
19261930
for (const [key, value] of Object.entries(obj)) {
19271931
if (value.includes("FAIL") && value.includes("_test.go")) {
19281932
var result;

index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ try {
88

99
const testResultsPath = core.getInput('test-results');
1010
const customPackageName = core.getInput('package-name');
11+
const workingDirectory = core.getInput('working-directory');
1112

1213
if (!fs.existsSync(testResultsPath)) {
1314
core.warning(
@@ -18,7 +19,7 @@ try {
1819

1920
let obj = {};
2021
let lr = new lineReader(testResultsPath);
21-
lr.on('line', function(line) {
22+
lr.on('line', function (line) {
2223
const currentLine = JSON.parse(line);
2324
const testName = currentLine.Test;
2425
if (typeof testName === "undefined") {
@@ -42,14 +43,17 @@ try {
4243
packageName = currentLine.Package.replace(customPackageName + "/", "")
4344
}
4445
}
46+
if (workingDirectory !== "") {
47+
packageName = workingDirectory + "/" + packageName
48+
}
4549
let newEntry = packageName + "/" + testName;
4650
if (!obj.hasOwnProperty(newEntry)) {
4751
obj[newEntry] = output;
4852
} else {
4953
obj[newEntry] += output;
5054
}
5155
});
52-
lr.on('end', function() {
56+
lr.on('end', function () {
5357
for (const [key, value] of Object.entries(obj)) {
5458
if (value.includes("FAIL") && value.includes("_test.go")) {
5559
var result;

package-lock.json

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"main": "index.js",
66
"scripts": {
77
"run": "node index.js",
8+
"build": "ncc build index.js --license licenses.txt",
89
"test": "echo \"Error: no test specified\" && exit 1"
910
},
1011
"repository": {
@@ -20,6 +21,7 @@
2021
"homepage": "https://github.com/guyarb/golang-test-annoations#readme",
2122
"dependencies": {
2223
"@actions/core": "^1.6.0",
24+
"@vercel/ncc": "^0.36.1",
2325
"line-by-line": "^0.1.6"
2426
}
2527
}

0 commit comments

Comments
 (0)