Skip to content

Commit

Permalink
Merge pull request #14 from mikepenz/feature/require_tests
Browse files Browse the repository at this point in the history
Fail on missing test cases
  • Loading branch information
mikepenz authored Jan 18, 2021
2 parents 9d4d344 + 225b6d8 commit b01678f
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 12 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Based on action for [Surefire Reports by ScaCap](https://github.com/ScaCap/actio
| `check_name` | Optional. Check name to use when creating a check run. The default is `Test Report`. |
| `commit` | Optional. The commit SHA to update the status. This is useful when you run it with `workflow_run`. |
| `fail_on_failure` | Optional. Fail the build in case of a test failure. |
| `require_tests` | Optional. Fail if no test are found.. |

### Example usage

Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ inputs:
description: 'Fail the build in case a test failure occurred.'
required: false
default: 'false'
require_tests:
description: 'Fail if no test are found.'
required: false
default: 'false'
runs:
using: 'node12'
main: 'dist/index.js'
15 changes: 10 additions & 5 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.

18 changes: 13 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export async function run(): Promise<void> {
const checkName = core.getInput('check_name')
const commit = core.getInput('commit')
const failOnFailure = core.getInput('fail_on_failure') === 'true'
const requireTests = core.getInput('require_tests') === 'true'

core.endGroup()
core.startGroup(`📦 Process test results`)
Expand All @@ -25,7 +26,12 @@ export async function run(): Promise<void> {
const title = foundResults
? `${testResult.count} tests run, ${testResult.skipped} skipped, ${testResult.annotations.length} failed.`
: 'No test results found!'
core.info(`Result: ${title}`)
core.info(`ℹ️ ${title}`)

if (!foundResults && requireTests) {
core.setFailed('❌ No test results found')
return
}

const pullRequest = github.context.payload.pull_request
const link = (pullRequest && pullRequest.html_url) || github.context.ref
Expand All @@ -37,7 +43,7 @@ export async function run(): Promise<void> {
const head_sha =
commit || (pullRequest && pullRequest.head.sha) || github.context.sha
core.info(
`Posting status '${status}' with conclusion '${conclusion}' to ${link} (sha: ${head_sha})`
`ℹ️ Posting status '${status}' with conclusion '${conclusion}' to ${link} (sha: ${head_sha})`
)

const createCheckRequest = {
Expand Down Expand Up @@ -66,13 +72,15 @@ export async function run(): Promise<void> {

if (failOnFailure && conclusion === 'failure') {
core.setFailed(
`Tests reported ${testResult.annotations.length} failures`
`Tests reported ${testResult.annotations.length} failures`
)
}
} catch (error) {
core.error(`Failed to create checks using the provided token. (${error})`)
core.error(
`❌ Failed to create checks using the provided token. (${error})`
)
core.warning(
`This usually indicates insufficient permissions. More details: https://github.com/mikepenz/action-junit-report/issues/32`
`⚠️ This usually indicates insufficient permissions. More details: https://github.com/mikepenz/action-junit-report/issues/32`
)
}

Expand Down
4 changes: 3 additions & 1 deletion src/testParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ export async function resolveFileAndLine(

return {fileName, line: parseInt(line)}
} catch (error) {
core.warning(`⚠️ Failed to resolve file and line for ${file} and ${className}`)
core.warning(
`⚠️ Failed to resolve file and line for ${file} and ${className}`
)
return {fileName, line: 1}
}
}
Expand Down

0 comments on commit b01678f

Please sign in to comment.