This commit is contained in:
Julian 2022-02-05 03:09:39 +01:00 committed by A. J. Kaptijn
parent a3b45a8dbd
commit 297c6fe504
4 changed files with 34 additions and 15 deletions

View file

@ -49,7 +49,8 @@ export class ArtifactProvider implements InputProvider {
async load(): Promise<ReportInput> { async load(): Promise<ReportInput> {
const result: ReportInput = { const result: ReportInput = {
artifactFilePaths: [] artifactFilePaths: [],
reports : {}
} }
const resp = await this.octokit.rest.actions.listWorkflowRunArtifacts({ const resp = await this.octokit.rest.actions.listWorkflowRunArtifacts({
@ -68,6 +69,15 @@ export class ArtifactProvider implements InputProvider {
return result 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) { for (const art of artifacts) {
const fileName = `${art.name}.zip` const fileName = `${art.name}.zip`
result.artifactFilePaths.push(fileName) result.artifactFilePaths.push(fileName)
@ -92,10 +102,10 @@ export class ArtifactProvider implements InputProvider {
files.push({file, content}) files.push({file, content})
core.info(`Read ${file}: ${content.length} chars`) core.info(`Read ${file}: ${content.length} chars`)
} }
if (result[reportName]) { if (result.reports[reportName]) {
result[reportName].push(...files) result.reports[reportName].push(...files)
} else { } else {
result[reportName] = files result.reports[reportName] = files
} }
} finally { } finally {
core.endGroup() core.endGroup()

View file

@ -1,6 +1,9 @@
export interface ReportInput { export interface ReportInput {
artifactFilePaths: string[] artifactFilePaths: string[],
[reportName: string]: any[] versionArtifactPath?: string,
reports : {
[reportName: string]: FileContent[]
}
} }
export interface FileContent { export interface FileContent {

View file

@ -19,7 +19,12 @@ export class LocalFileProvider implements InputProvider {
} }
} }
return {[this.name]: result, artifactFilePaths: []} return {
artifactFilePaths: [],
reports : {
[this.name]: result
}
}
} }
async listTrackedFiles(): Promise<string[]> { async listTrackedFiles(): Promise<string[]> {

View file

@ -116,25 +116,26 @@ class TestReporter {
const results: TestRunResult[] = [] const results: TestRunResult[] = []
const input = await inputProvider.load() 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) { for (const a of input.artifactFilePaths) {
const stats = fs.statSync(a)
const fileSizeInBytes = stats.size
const readStream = fs.createReadStream(a) const readStream = fs.createReadStream(a)
try { try {
const post = bent(this.resultsEndpoint, 'POST', {}, 200); 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}`) core.info(`Uploaded TRX files: ${a}`)
} catch (ex){ } catch (ex){
core.warning(`Could not upload file ${a}: ${ex}`) core.warning(`Could not upload file ${a}: ${ex}`)
} }
} }
for (const [reportName, files] of Object.entries(input)) { for (const [reportName, files] of Object.entries(input.reports)) {
if(reportName === 'artifactFilePaths') {
continue;
}
try { try {
core.startGroup(`Creating test report ${reportName}`) core.startGroup(`Creating test report ${reportName}`)