From b102acab380da2f21f1b25f8d6d7ae1d0c4b971d Mon Sep 17 00:00:00 2001 From: Isaac Lambat Date: Mon, 4 Apr 2022 19:31:54 +0100 Subject: [PATCH] Log lines now don't affect annotations --- dist/index.js | 13 +++++++++---- index.js | 13 +++++++++---- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/dist/index.js b/dist/index.js index 802cd30..d7133ef 100644 --- a/dist/index.js +++ b/dist/index.js @@ -10,6 +10,8 @@ const lineReader = __webpack_require__(631); const fs = __webpack_require__(747); try { + const regex = /(\w+_test.go:\d+:)/g; // Extracts file name and line where test failures occurred + const testResultsPath = core.getInput('test-results'); const customPackageName = core.getInput('package-name'); @@ -56,10 +58,13 @@ try { 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}`) + const result = regex.exec(value); + if (result != null) { + const parts = result[0].split(":"); + const file = parts[0] + const lineNumber = parts[1]; + core.info(`::error file=${file},line=${lineNumber}::${value}`) + } } } }); diff --git a/index.js b/index.js index f1933e9..d4239e9 100644 --- a/index.js +++ b/index.js @@ -3,6 +3,8 @@ const lineReader = require('line-by-line'); const fs = require('fs'); try { + const regex = /(\w+_test.go:\d+:)/g; // Extracts file name and line where test failures occurred + const testResultsPath = core.getInput('test-results'); const customPackageName = core.getInput('package-name'); @@ -49,10 +51,13 @@ try { 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}`) + const result = regex.exec(value); + if (result != null) { + const parts = result[0].split(":"); + const file = parts[0] + const lineNumber = parts[1]; + core.info(`::error file=${file},line=${lineNumber}::${value}`) + } } } });