From 0351b3f45093576c6d0334af000c53bf402097df Mon Sep 17 00:00:00 2001 From: Patrik Husfloen Date: Thu, 8 Jun 2023 14:38:57 +0200 Subject: [PATCH] Added `build-directory` parameter Used to override the working directory for when the source was build under a different path --- action.yml | 3 +++ dist/index.js | 7 ++++++- src/main.ts | 7 ++++++- src/parsers/dotnet-trx/dotnet-trx-parser.ts | 3 ++- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/action.yml b/action.yml index 325e2c4..bcaad45 100644 --- a/action.yml +++ b/action.yml @@ -60,6 +60,9 @@ inputs: working-directory: description: Relative path under $GITHUB_WORKSPACE where the repository was checked out required: false + build-directory: + description: Relative path for the source tree when it was compiled (This can be different that working-directory if, for instance, you build inside a docker container) + required: false only-summary: description: | Allows you to generate only the summary. diff --git a/dist/index.js b/dist/index.js index 78b2f56..8572211 100644 --- a/dist/index.js +++ b/dist/index.js @@ -294,6 +294,7 @@ class TestReporter { this.maxAnnotations = parseInt(core.getInput('max-annotations', { required: true })); this.failOnError = core.getInput('fail-on-error', { required: true }) === 'true'; this.workDirInput = core.getInput('working-directory', { required: false }); + this.buildDirInput = core.getInput('build-directory', { required: false }); this.onlySummary = core.getInput('only-summary', { required: false }) === 'true'; this.token = core.getInput('token', { required: true }); this.context = (0, github_utils_1.getCheckRunContext)(); @@ -327,7 +328,11 @@ class TestReporter { : new local_file_provider_1.LocalFileProvider(this.name, pattern); const parseErrors = this.maxAnnotations > 0; const trackedFiles = parseErrors ? yield inputProvider.listTrackedFiles() : []; - const workDir = this.artifact ? undefined : (0, path_utils_1.normalizeDirPath)(process.cwd(), true); + const workDir = this.buildDirInput + ? (0, path_utils_1.normalizeDirPath)(this.buildDirInput, true) + : this.artifact + ? undefined + : (0, path_utils_1.normalizeDirPath)(process.cwd(), true); if (parseErrors) core.info(`Found ${trackedFiles.length} files tracked by GitHub`); const options = { diff --git a/src/main.ts b/src/main.ts index d0c5a06..3c4bb68 100644 --- a/src/main.ts +++ b/src/main.ts @@ -41,6 +41,7 @@ class TestReporter { readonly maxAnnotations = parseInt(core.getInput('max-annotations', {required: true})) readonly failOnError = core.getInput('fail-on-error', {required: true}) === 'true' readonly workDirInput = core.getInput('working-directory', {required: false}) + readonly buildDirInput = core.getInput('build-directory', {required: false}) readonly onlySummary = core.getInput('only-summary', {required: false}) === 'true' readonly token = core.getInput('token', {required: true}) readonly octokit: InstanceType @@ -92,7 +93,11 @@ class TestReporter { const parseErrors = this.maxAnnotations > 0 const trackedFiles = parseErrors ? await inputProvider.listTrackedFiles() : [] - const workDir = this.artifact ? undefined : normalizeDirPath(process.cwd(), true) + const workDir = this.buildDirInput + ? normalizeDirPath(this.buildDirInput, true) + : this.artifact + ? undefined + : normalizeDirPath(process.cwd(), true) if (parseErrors) core.info(`Found ${trackedFiles.length} files tracked by GitHub`) diff --git a/src/parsers/dotnet-trx/dotnet-trx-parser.ts b/src/parsers/dotnet-trx/dotnet-trx-parser.ts index a81d4a2..1a763d2 100644 --- a/src/parsers/dotnet-trx/dotnet-trx-parser.ts +++ b/src/parsers/dotnet-trx/dotnet-trx-parser.ts @@ -145,6 +145,7 @@ export class DotnetTrxParser implements TestParser { return undefined } + const message = test.error.Message[0] const stackTrace = test.error.StackTrace[0] let path @@ -168,11 +169,11 @@ export class DotnetTrxParser implements TestParser { const lines = stackTrace.split(/\r*\n/) const re = / in (.+):line (\d+)$/ const {trackedFiles} = this.options - for (const str of lines) { const match = str.match(re) if (match !== null) { const [_, fileStr, lineStr] = match + const filePath = normalizeFilePath(fileStr) const workDir = this.getWorkDir(filePath) if (workDir) {