mirror of
https://github.com/dorny/test-reporter.git
synced 2025-12-15 22:07:09 +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 * as github from '@actions/github'
|
||||
import core from '@actions/core'
|
||||
import github from '@actions/github'
|
||||
import fs from 'fs'
|
||||
import glob from 'fast-glob'
|
||||
import {parseDartJson} from './parsers/dart-json/dart-json-parser'
|
||||
import {parseDotnetTrx} from './parsers/dotnet-trx/dotnet-trx-parser'
|
||||
import {parseJestJunit} from './parsers/jest-junit/jest-junit-parser'
|
||||
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 {getCheckRunSha} from './utils/github-utils'
|
||||
|
||||
|
|
@ -26,6 +28,7 @@ async function main(): Promise<void> {
|
|||
const workDirInput = core.getInput('working-directory', {required: false})
|
||||
|
||||
if (workDirInput) {
|
||||
core.info(`Changing directory to ${workDirInput}`)
|
||||
process.chdir(workDirInput)
|
||||
}
|
||||
|
||||
|
|
@ -44,8 +47,14 @@ async function main(): Promise<void> {
|
|||
}
|
||||
|
||||
const parser = getParser(reporter)
|
||||
const content = getFileContent(path)
|
||||
const result = await parser(content, opts)
|
||||
const files = await getFiles(path)
|
||||
|
||||
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'
|
||||
|
||||
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()
|
||||
|
|
|
|||
|
|
@ -1,24 +1,10 @@
|
|||
import * as fs from 'fs'
|
||||
|
||||
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 {
|
||||
export function normalizeDirPath(path: string, addTrailingSlash: boolean): string {
|
||||
if (!path) {
|
||||
return path
|
||||
}
|
||||
|
||||
path = normalizeFilePath(path)
|
||||
if (trailingSeparator && !path.endsWith('/')) {
|
||||
if (addTrailingSlash && !path.endsWith('/')) {
|
||||
path += '/'
|
||||
}
|
||||
return path
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue