Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce flag to fail_on_parse_error #1222

Merged
merged 1 commit into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion __tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {parseFile, Transformer} from '../src/testParser'
import {readTransformers} from '../src/utils'

/**
* Copyright 2022 Mike Penz
* Copyright 2024 Mike Penz
*/
jest.setTimeout(30000)

Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ inputs:
description: 'Fail the build in case a test failure occurred.'
required: false
default: 'false'
fail_on_parse_error:
description: 'Fail the build if the test report file can not be parsed.'
required: false
default: 'false'
require_tests:
description: 'Fail if no test are found.'
required: false
Expand Down
11 changes: 7 additions & 4 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export async function run(): Promise<void> {
const checkAnnotations = core.getInput('check_annotations') === 'true'
const commit = core.getInput('commit')
const failOnFailure = core.getInput('fail_on_failure') === 'true'
const failOnParseError = core.getInput('fail_on_parse_error') === 'true'
const requireTests = core.getInput('require_tests') === 'true'
const requirePassedTests = core.getInput('require_passed_tests') === 'true'
const includePassed = core.getInput('include_passed') === 'true'
Expand Down Expand Up @@ -84,7 +85,8 @@ export async function run(): Promise<void> {
transformers,
followSymlink,
annotationsLimit,
truncateStackTraces
truncateStackTraces,
failOnParseError
)
mergedResult.totalCount += testResult.totalCount
mergedResult.skipped += testResult.skipped
Expand Down
10 changes: 7 additions & 3 deletions src/testParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ export async function parseFile(
transformer: Transformer[] = [],
followSymlink = false,
annotationsLimit = -1,
truncateStackTraces = true
truncateStackTraces = true,
failOnParseError = false
): Promise<InternalTestResult> {
core.debug(`Parsing file ${file}`)

Expand All @@ -178,6 +179,7 @@ export async function parseFile(
report = JSON.parse(parser.xml2json(data, {compact: true}))
} catch (error) {
core.error(`⚠️ Failed to parse file (${file}) with error ${error}`)
if (failOnParseError) throw Error(`⚠️ Failed to parse file (${file}) with error ${error}`)
return {
name: '',
totalCount: 0,
Expand Down Expand Up @@ -549,7 +551,8 @@ export async function parseTestReports(
transformer: Transformer[] = [],
followSymlink = false,
annotationsLimit = -1,
truncateStackTraces = true
truncateStackTraces = true,
failOnParseError = false
): Promise<TestResult> {
core.debug(`Process test report for: ${reportPaths} (${checkName})`)
const globber = await glob.create(reportPaths, {followSymbolicLinks: followSymlink})
Expand Down Expand Up @@ -577,7 +580,8 @@ export async function parseTestReports(
transformer,
followSymlink,
annotationsLimit,
truncateStackTraces
truncateStackTraces,
failOnParseError
)
if (c === 0) continue
totalCount += c
Expand Down
Loading