Skip to content

Commit

Permalink
Add working-directory option & build command (#27)
Browse files Browse the repository at this point in the history
* add workingDirectory option

* add build step
  • Loading branch information
Nivl authored Jul 21, 2023
1 parent 9ab2ea8 commit a7869d3
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 37 deletions.
20 changes: 12 additions & 8 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
name: 'Golang Test Annotations'
description: 'Given a test output of go test, the failed tests will be annotated.'
name: "Golang Test Annotations"
description: "Given a test output of go test, the failed tests will be annotated."
inputs:
test-results: # Path of the test results
description: 'The path of the go test results'
test-results: # Path of the test results
description: "The path of the go test results"
required: true
default: 'test.json'
default: "test.json"
package-name:
required: false
description: 'Package name override'
description: "Package name override"
default:
working-directory:
description: "The path of the go module"
required: false
default:
runs:
using: 'node16'
main: 'dist/index.js'
using: "node16"
main: "dist/index.js"
branding:
icon: "check"
color: "green"
58 changes: 31 additions & 27 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/******/ (() => { // webpackBootstrap
/******/ var __webpack_modules__ = ({

/***/ 604:
/***/ 351:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {

"use strict";
Expand All @@ -28,7 +28,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.issue = exports.issueCommand = void 0;
const os = __importStar(__nccwpck_require__(37));
const utils_1 = __nccwpck_require__(245);
const utils_1 = __nccwpck_require__(278);
/**
* Commands
*
Expand Down Expand Up @@ -100,7 +100,7 @@ function escapeProperty(s) {

/***/ }),

/***/ 127:
/***/ 186:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {

"use strict";
Expand Down Expand Up @@ -135,12 +135,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
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;
const command_1 = __nccwpck_require__(604);
const file_command_1 = __nccwpck_require__(352);
const utils_1 = __nccwpck_require__(245);
const command_1 = __nccwpck_require__(351);
const file_command_1 = __nccwpck_require__(717);
const utils_1 = __nccwpck_require__(278);
const os = __importStar(__nccwpck_require__(37));
const path = __importStar(__nccwpck_require__(17));
const oidc_utils_1 = __nccwpck_require__(457);
const oidc_utils_1 = __nccwpck_require__(41);
/**
* The code to exit an action
*/
Expand Down Expand Up @@ -419,7 +419,7 @@ exports.getIDToken = getIDToken;

/***/ }),

/***/ 352:
/***/ 717:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {

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

/***/ }),

/***/ 457:
/***/ 41:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {

"use strict";
Expand All @@ -484,9 +484,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.OidcClient = void 0;
const http_client_1 = __nccwpck_require__(840);
const auth_1 = __nccwpck_require__(421);
const core_1 = __nccwpck_require__(127);
const http_client_1 = __nccwpck_require__(925);
const auth_1 = __nccwpck_require__(702);
const core_1 = __nccwpck_require__(186);
class OidcClient {
static createHttpClient(allowRetry = true, maxRetry = 10) {
const requestOptions = {
Expand Down Expand Up @@ -552,7 +552,7 @@ exports.OidcClient = OidcClient;

/***/ }),

/***/ 245:
/***/ 278:
/***/ ((__unused_webpack_module, exports) => {

"use strict";
Expand Down Expand Up @@ -599,7 +599,7 @@ exports.toCommandProperties = toCommandProperties;

/***/ }),

/***/ 421:
/***/ 702:
/***/ ((__unused_webpack_module, exports) => {

"use strict";
Expand Down Expand Up @@ -665,15 +665,15 @@ exports.PersonalAccessTokenCredentialHandler = PersonalAccessTokenCredentialHand

/***/ }),

/***/ 840:
/***/ 925:
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {

"use strict";

Object.defineProperty(exports, "__esModule", ({ value: true }));
const http = __nccwpck_require__(685);
const https = __nccwpck_require__(687);
const pm = __nccwpck_require__(45);
const pm = __nccwpck_require__(443);
let tunnel;
var HttpCodes;
(function (HttpCodes) {
Expand Down Expand Up @@ -1092,7 +1092,7 @@ class HttpClient {
if (useProxy) {
// If using proxy, need tunnel
if (!tunnel) {
tunnel = __nccwpck_require__(265);
tunnel = __nccwpck_require__(294);
}
const agentOptions = {
maxSockets: maxSockets,
Expand Down Expand Up @@ -1210,7 +1210,7 @@ exports.HttpClient = HttpClient;

/***/ }),

/***/ 45:
/***/ 443:
/***/ ((__unused_webpack_module, exports) => {

"use strict";
Expand Down Expand Up @@ -1275,7 +1275,7 @@ exports.checkBypass = checkBypass;

/***/ }),

/***/ 631:
/***/ 752:
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {

/*
Expand Down Expand Up @@ -1454,15 +1454,15 @@ module.exports = LineByLineReader;

/***/ }),

/***/ 265:
/***/ 294:
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {

module.exports = __nccwpck_require__(686);
module.exports = __nccwpck_require__(219);


/***/ }),

/***/ 686:
/***/ 219:
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {

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


Expand All @@ -1881,6 +1881,7 @@ try {

const testResultsPath = core.getInput('test-results');
const customPackageName = core.getInput('package-name');
const workingDirectory = core.getInput('working-directory');

if (!fs.existsSync(testResultsPath)) {
core.warning(
Expand All @@ -1891,7 +1892,7 @@ try {

let obj = {};
let lr = new lineReader(testResultsPath);
lr.on('line', function(line) {
lr.on('line', function (line) {
const currentLine = JSON.parse(line);
const testName = currentLine.Test;
if (typeof testName === "undefined") {
Expand All @@ -1915,14 +1916,17 @@ try {
packageName = currentLine.Package.replace(customPackageName + "/", "")
}
}
if (workingDirectory !== "") {
packageName = workingDirectory + "/" + packageName
}
let newEntry = packageName + "/" + testName;
if (!obj.hasOwnProperty(newEntry)) {
obj[newEntry] = output;
} else {
obj[newEntry] += output;
}
});
lr.on('end', function() {
lr.on('end', function () {
for (const [key, value] of Object.entries(obj)) {
if (value.includes("FAIL") && value.includes("_test.go")) {
var result;
Expand Down
8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ try {

const testResultsPath = core.getInput('test-results');
const customPackageName = core.getInput('package-name');
const workingDirectory = core.getInput('working-directory');

if (!fs.existsSync(testResultsPath)) {
core.warning(
Expand All @@ -18,7 +19,7 @@ try {

let obj = {};
let lr = new lineReader(testResultsPath);
lr.on('line', function(line) {
lr.on('line', function (line) {
const currentLine = JSON.parse(line);
const testName = currentLine.Test;
if (typeof testName === "undefined") {
Expand All @@ -42,14 +43,17 @@ try {
packageName = currentLine.Package.replace(customPackageName + "/", "")
}
}
if (workingDirectory !== "") {
packageName = workingDirectory + "/" + packageName
}
let newEntry = packageName + "/" + testName;
if (!obj.hasOwnProperty(newEntry)) {
obj[newEntry] = output;
} else {
obj[newEntry] += output;
}
});
lr.on('end', function() {
lr.on('end', function () {
for (const [key, value] of Object.entries(obj)) {
if (value.includes("FAIL") && value.includes("_test.go")) {
var result;
Expand Down
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"main": "index.js",
"scripts": {
"run": "node index.js",
"build": "ncc build index.js --license licenses.txt",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
Expand All @@ -20,6 +21,7 @@
"homepage": "https://github.com/guyarb/golang-test-annoations#readme",
"dependencies": {
"@actions/core": "^1.6.0",
"@vercel/ncc": "^0.36.1",
"line-by-line": "^0.1.6"
}
}

0 comments on commit a7869d3

Please sign in to comment.