mirror of
https://github.com/dorny/test-reporter.git
synced 2025-12-17 14:57:09 +01:00
wip
This commit is contained in:
parent
25189ba00b
commit
f310e06af7
6 changed files with 78 additions and 6 deletions
|
|
@ -48,7 +48,9 @@ export class ArtifactProvider implements InputProvider {
|
|||
}
|
||||
|
||||
async load(): Promise<ReportInput> {
|
||||
const result: ReportInput = {}
|
||||
const result: ReportInput = {
|
||||
artifactFilePaths: []
|
||||
}
|
||||
|
||||
const resp = await this.octokit.rest.actions.listWorkflowRunArtifacts({
|
||||
...github.context.repo,
|
||||
|
|
@ -57,17 +59,18 @@ export class ArtifactProvider implements InputProvider {
|
|||
|
||||
if (resp.data.artifacts.length === 0) {
|
||||
core.warning(`No artifacts found in run ${this.runId}`)
|
||||
return {}
|
||||
return result
|
||||
}
|
||||
|
||||
const artifacts = resp.data.artifacts.filter(a => this.artifactNameMatch(a.name))
|
||||
if (artifacts.length === 0) {
|
||||
core.warning(`No artifact matches ${this.artifact}`)
|
||||
return {}
|
||||
return result
|
||||
}
|
||||
|
||||
for (const art of artifacts) {
|
||||
const fileName = `${art.name}.zip`
|
||||
result.artifactFilePaths.push(fileName)
|
||||
await downloadArtifact(this.octokit, art.id, fileName, this.token)
|
||||
core.startGroup(`Reading archive ${fileName}`)
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
export interface ReportInput {
|
||||
[reportName: string]: FileContent[]
|
||||
artifactFilePaths: string[]
|
||||
[reportName: string]: any[]
|
||||
}
|
||||
|
||||
export interface FileContent {
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ export class LocalFileProvider implements InputProvider {
|
|||
}
|
||||
}
|
||||
|
||||
return {[this.name]: result}
|
||||
return {[this.name]: result, artifactFilePaths: []}
|
||||
}
|
||||
|
||||
async listTrackedFiles(): Promise<string[]> {
|
||||
|
|
|
|||
20
src/main.ts
20
src/main.ts
|
|
@ -20,6 +20,9 @@ import {SwiftXunitParser} from './parsers/swift-xunit/swift-xunit-parser'
|
|||
import {normalizeDirPath, normalizeFilePath} from './utils/path-utils'
|
||||
import {getCheckRunContext} from './utils/github-utils'
|
||||
import {IncomingWebhook} from '@slack/webhook'
|
||||
import fs from 'fs'
|
||||
//import fetch from 'node-fetch'
|
||||
import bent from 'bent'
|
||||
|
||||
async function main(): Promise<void> {
|
||||
try {
|
||||
|
|
@ -46,6 +49,8 @@ class TestReporter {
|
|||
readonly onlySummary = core.getInput('only-summary', {required: false}) === 'true'
|
||||
readonly token = core.getInput('token', {required: true})
|
||||
readonly slackWebhook = core.getInput('slack-url', {required: false})
|
||||
readonly resultsEndpoint = core.getInput('test-results-endpoint', {required: true})
|
||||
readonly resultsEndpointSecret = core.getInput('test-results-endpoint-secret', {required: true})
|
||||
readonly octokit: InstanceType<typeof GitHub>
|
||||
readonly context = getCheckRunContext()
|
||||
|
||||
|
|
@ -110,6 +115,21 @@ class TestReporter {
|
|||
|
||||
const results: TestRunResult[] = []
|
||||
const input = await inputProvider.load()
|
||||
|
||||
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', null, 200);
|
||||
await post(`TestResults?Secret=${this.resultsEndpointSecret}`, 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)) {
|
||||
try {
|
||||
core.startGroup(`Creating test report ${reportName}`)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue