From 297c6fe50482b1986a709eb7966112558b2cc59f Mon Sep 17 00:00:00 2001 From: Julian Date: Sat, 5 Feb 2022 03:09:39 +0100 Subject: [PATCH] wip --- src/input-providers/artifact-provider.ts | 18 ++++++++++++++---- src/input-providers/input-provider.ts | 7 +++++-- src/input-providers/local-file-provider.ts | 7 ++++++- src/main.ts | 17 +++++++++-------- 4 files changed, 34 insertions(+), 15 deletions(-) diff --git a/src/input-providers/artifact-provider.ts b/src/input-providers/artifact-provider.ts index 81f5c48..90e34f6 100644 --- a/src/input-providers/artifact-provider.ts +++ b/src/input-providers/artifact-provider.ts @@ -49,7 +49,8 @@ export class ArtifactProvider implements InputProvider { async load(): Promise { const result: ReportInput = { - artifactFilePaths: [] + artifactFilePaths: [], + reports : {} } const resp = await this.octokit.rest.actions.listWorkflowRunArtifacts({ @@ -68,6 +69,15 @@ export class ArtifactProvider implements InputProvider { return result } + const versionArtifact = resp.data.artifacts.find(a => a.name == "version.txt"); + + if(versionArtifact) { + await downloadArtifact(this.octokit, versionArtifact.id, "version.txt", this.token); + result.versionArtifactPath = "version.txt"; + } else { + core.warning(`Could not find version.txt artifact among these artifacts: ${resp.data.artifacts.map(a => a.name).join(", ")}`); + } + for (const art of artifacts) { const fileName = `${art.name}.zip` result.artifactFilePaths.push(fileName) @@ -92,10 +102,10 @@ export class ArtifactProvider implements InputProvider { files.push({file, content}) core.info(`Read ${file}: ${content.length} chars`) } - if (result[reportName]) { - result[reportName].push(...files) + if (result.reports[reportName]) { + result.reports[reportName].push(...files) } else { - result[reportName] = files + result.reports[reportName] = files } } finally { core.endGroup() diff --git a/src/input-providers/input-provider.ts b/src/input-providers/input-provider.ts index 919ae78..03c9a88 100644 --- a/src/input-providers/input-provider.ts +++ b/src/input-providers/input-provider.ts @@ -1,6 +1,9 @@ export interface ReportInput { - artifactFilePaths: string[] - [reportName: string]: any[] + artifactFilePaths: string[], + versionArtifactPath?: string, + reports : { + [reportName: string]: FileContent[] + } } export interface FileContent { diff --git a/src/input-providers/local-file-provider.ts b/src/input-providers/local-file-provider.ts index 4d9446d..f64c39b 100644 --- a/src/input-providers/local-file-provider.ts +++ b/src/input-providers/local-file-provider.ts @@ -19,7 +19,12 @@ export class LocalFileProvider implements InputProvider { } } - return {[this.name]: result, artifactFilePaths: []} + return { + artifactFilePaths: [], + reports : { + [this.name]: result + } + } } async listTrackedFiles(): Promise { diff --git a/src/main.ts b/src/main.ts index 8af285c..10bf947 100644 --- a/src/main.ts +++ b/src/main.ts @@ -116,25 +116,26 @@ class TestReporter { const results: TestRunResult[] = [] const input = await inputProvider.load() + let version : string | null = null; + + if(input.versionArtifactPath) { + version = fs.readFileSync(input.versionArtifactPath).toString(); + core.info(`Using EVA version ${version}`) + } + for (const a of input.artifactFilePaths) { - const stats = fs.statSync(a) - const fileSizeInBytes = stats.size const readStream = fs.createReadStream(a) try { const post = bent(this.resultsEndpoint, 'POST', {}, 200); - await post(`TestResults?Secret=${this.resultsEndpointSecret}`, readStream); + await post(`TestResults?Secret=${this.resultsEndpointSecret}${version ? "&EVAVersion=" + version : ''}`, readStream); core.info(`Uploaded TRX files: ${a}`) } catch (ex){ core.warning(`Could not upload file ${a}: ${ex}`) } } - for (const [reportName, files] of Object.entries(input)) { - - if(reportName === 'artifactFilePaths') { - continue; - } + for (const [reportName, files] of Object.entries(input.reports)) { try { core.startGroup(`Creating test report ${reportName}`)