mirror of
https://github.com/dorny/test-reporter.git
synced 2025-12-16 06:17:10 +01:00
Support path pattern to match test report files
This commit is contained in:
parent
dfddea6f3f
commit
656ede0390
2 changed files with 26 additions and 21 deletions
29
src/main.ts
29
src/main.ts
|
|
@ -1,10 +1,12 @@
|
||||||
import * as core from '@actions/core'
|
import core from '@actions/core'
|
||||||
import * as github from '@actions/github'
|
import github from '@actions/github'
|
||||||
|
import fs from 'fs'
|
||||||
|
import glob from 'fast-glob'
|
||||||
import {parseDartJson} from './parsers/dart-json/dart-json-parser'
|
import {parseDartJson} from './parsers/dart-json/dart-json-parser'
|
||||||
import {parseDotnetTrx} from './parsers/dotnet-trx/dotnet-trx-parser'
|
import {parseDotnetTrx} from './parsers/dotnet-trx/dotnet-trx-parser'
|
||||||
import {parseJestJunit} from './parsers/jest-junit/jest-junit-parser'
|
import {parseJestJunit} from './parsers/jest-junit/jest-junit-parser'
|
||||||
import {ParseOptions, ParseTestResult} from './parsers/parser-types'
|
import {ParseOptions, ParseTestResult} from './parsers/parser-types'
|
||||||
import {getFileContent, normalizeDirPath} from './utils/file-utils'
|
import {normalizeDirPath} from './utils/file-utils'
|
||||||
import {listFiles} from './utils/git'
|
import {listFiles} from './utils/git'
|
||||||
import {getCheckRunSha} from './utils/github-utils'
|
import {getCheckRunSha} from './utils/github-utils'
|
||||||
|
|
||||||
|
|
@ -26,6 +28,7 @@ async function main(): Promise<void> {
|
||||||
const workDirInput = core.getInput('working-directory', {required: false})
|
const workDirInput = core.getInput('working-directory', {required: false})
|
||||||
|
|
||||||
if (workDirInput) {
|
if (workDirInput) {
|
||||||
|
core.info(`Changing directory to ${workDirInput}`)
|
||||||
process.chdir(workDirInput)
|
process.chdir(workDirInput)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -44,8 +47,14 @@ async function main(): Promise<void> {
|
||||||
}
|
}
|
||||||
|
|
||||||
const parser = getParser(reporter)
|
const parser = getParser(reporter)
|
||||||
const content = getFileContent(path)
|
const files = await getFiles(path)
|
||||||
const result = await parser(content, opts)
|
|
||||||
|
if (files.length === 0) {
|
||||||
|
core.setFailed(`No file matches path ${path}`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await parser(files[0].content, opts)
|
||||||
const conclusion = result.success ? 'success' : 'failure'
|
const conclusion = result.success ? 'success' : 'failure'
|
||||||
|
|
||||||
await octokit.checks.create({
|
await octokit.checks.create({
|
||||||
|
|
@ -78,4 +87,14 @@ function getParser(reporter: string): ParseTestResult {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getFiles(pattern: string): Promise<{path: string; content: string}[]> {
|
||||||
|
const paths = await glob(pattern, {dot: true})
|
||||||
|
return Promise.all(
|
||||||
|
paths.map(async path => {
|
||||||
|
const content = await fs.promises.readFile(path, {encoding: 'utf8'})
|
||||||
|
return {path, content}
|
||||||
|
})
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
run()
|
run()
|
||||||
|
|
|
||||||
|
|
@ -1,24 +1,10 @@
|
||||||
import * as fs from 'fs'
|
export function normalizeDirPath(path: string, addTrailingSlash: boolean): string {
|
||||||
|
|
||||||
export function getFileContent(path: string): string {
|
|
||||||
if (!fs.existsSync(path)) {
|
|
||||||
throw new Error(`File '${path}' not found`)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!fs.lstatSync(path).isFile()) {
|
|
||||||
throw new Error(`'${path}' is not a file`)
|
|
||||||
}
|
|
||||||
|
|
||||||
return fs.readFileSync(path, {encoding: 'utf8'})
|
|
||||||
}
|
|
||||||
|
|
||||||
export function normalizeDirPath(path: string, trailingSeparator: boolean): string {
|
|
||||||
if (!path) {
|
if (!path) {
|
||||||
return path
|
return path
|
||||||
}
|
}
|
||||||
|
|
||||||
path = normalizeFilePath(path)
|
path = normalizeFilePath(path)
|
||||||
if (trailingSeparator && !path.endsWith('/')) {
|
if (addTrailingSlash && !path.endsWith('/')) {
|
||||||
path += '/'
|
path += '/'
|
||||||
}
|
}
|
||||||
return path
|
return path
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue