Skip to content

Commit

Permalink
Merge branch 'TheEvilRoot-feature/detailed_summary'
Browse files Browse the repository at this point in the history
  • Loading branch information
mikepenz committed Aug 19, 2022
2 parents e723b7d + 262569a commit 4a63872
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 22 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,15 @@ jobs:
| `suite_regex` | Optional. Regular expression for the named test suites. E.g. `Test*` |
| `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.. |
| `require_tests` | Optional. Fail if no test are found. |
| `check_retries` | Optional. If a testcase is retried, ignore the original failure. |
| `check_title_template` | Optional. Template to configure the title format. Placeholders: {{FILE_NAME}}, {{SUITE_NAME}}, {{TEST_NAME}}. |
| `summary` | Optional. Additional text to summary output |
| `update_check` | Optional. Uses an alternative API to update checks, use for cases with more than 50 annotations. |
| `annotate_only` | Optional. Will only annotate the results on the files, won't create a check run. |
| `transformers` | Optional. Array of `Transformer`s offering the ability to adjust the fileName. Defaults to: `[{"searchValue":"::","replaceValue":"/"}]` |
| `detailed_summary` | Optional. Include table with all test results in the summary. Defaults to `false`. |
| `annotate_notice` | Optional. Annotate passed test results along with warning/failed ones. Defaults to `true`. |

### Action outputs

Expand Down
8 changes: 8 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ inputs:
description: 'Provide a regex pattern and target pattern'
required: false
default: '[]'
detailed_summary:
description: 'Include table with all test results in summary'
required: false
default: false
annotate_notice:
description: 'Annotate passed tests along with warning and failed ones'
required: false
default: true
runs:
using: 'node16'
main: 'dist/index.js'
42 changes: 32 additions & 10 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.

41 changes: 33 additions & 8 deletions src/annotator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ export async function annotateTestResult(
token: string,
headSha: string,
annotateOnly: boolean,
updateCheck: boolean
updateCheck: boolean,
annotateNotice: boolean
): Promise<void> {
const annotations = testResult.annotations.filter(
annotation => annotateNotice || annotation.annotation_level !== 'notice'
)
const foundResults = testResult.totalCount > 0 || testResult.skipped > 0

let title = 'No test results found!'
Expand All @@ -23,7 +27,7 @@ export async function annotateTestResult(

const octokit = github.getOctokit(token)
if (annotateOnly) {
for (const annotation of testResult.annotations) {
for (const annotation of annotations) {
const properties: core.AnnotationProperties = {
title: annotation.title,
file: annotation.path,
Expand All @@ -36,7 +40,7 @@ export async function annotateTestResult(
core.error(annotation.message, properties)
} else if (annotation.annotation_level === 'warning') {
core.warning(annotation.message, properties)
} else {
} else if (annotateNotice) {
core.notice(annotation.message, properties)
}
}
Expand All @@ -54,9 +58,9 @@ export async function annotateTestResult(

const check_run_id = checks.data.check_runs[0].id

core.info(`ℹ️ - ${testResult.checkName} - Updating checks ${testResult.annotations.length}`)
for (let i = 0; i < testResult.annotations.length; i = i + 50) {
const sliced = testResult.annotations.slice(i, i + 50)
core.info(`ℹ️ - ${testResult.checkName} - Updating checks ${annotations.length}`)
for (let i = 0; i < annotations.length; i = i + 50) {
const sliced = annotations.slice(i, i + 50)

const updateCheckRequest = {
...github.context.repo,
Expand All @@ -82,7 +86,7 @@ export async function annotateTestResult(
output: {
title,
summary: testResult.summary,
annotations: testResult.annotations.slice(0, 50)
annotations: annotations.slice(0, 50)
}
}

Expand All @@ -94,7 +98,7 @@ export async function annotateTestResult(
}
}

export async function attachSummary(testResults: TestResult[]): Promise<void> {
export async function attachSummary(testResults: TestResult[], detailedSummary: boolean): Promise<void> {
const table: SummaryTableRow[] = [
[
{data: '', header: true},
Expand All @@ -105,6 +109,14 @@ export async function attachSummary(testResults: TestResult[]): Promise<void> {
]
]

const detailsTable: SummaryTableRow[] = [
[
{data: '', header: true},
{data: 'Test', header: true},
{data: 'Result', header: true}
]
]

for (const testResult of testResults) {
table.push([
`${testResult.checkName}`,
Expand All @@ -113,7 +125,20 @@ export async function attachSummary(testResults: TestResult[]): Promise<void> {
`${testResult.skipped} skipped`,
`${testResult.failed} failed`
])

if (detailedSummary) {
for (const annotation of testResult.annotations) {
detailsTable.push([
`${testResult.checkName}`,
`${annotation.title}`,
`${annotation.annotation_level === 'notice' ? '✅ pass' : `❌ ${annotation.annotation_level}`}`
])
}
}
}

await core.summary.addTable(table).write()
if (detailedSummary) {
await core.summary.addTable(detailsTable).write()
}
}
6 changes: 4 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export async function run(): Promise<void> {
const requireTests = core.getInput('require_tests') === 'true'
const includePassed = core.getInput('include_passed') === 'true'
const checkRetries = core.getInput('check_retries') === 'true'
const annotateNotice = core.getInput('annotate_notice') === 'true'
const detailedSummary = core.getInput('detailed_summary') === 'true'

const reportPaths = core.getMultilineInput('report_paths')
const summary = core.getMultilineInput('summary')
Expand Down Expand Up @@ -96,7 +98,7 @@ export async function run(): Promise<void> {

try {
for (const testResult of testResults) {
annotateTestResult(testResult, token, headSha, annotateOnly, updateCheck)
annotateTestResult(testResult, token, headSha, annotateOnly, updateCheck, annotateNotice)
}
} catch (error) {
core.error(`❌ Failed to create checks using the provided token. (${error})`)
Expand All @@ -106,7 +108,7 @@ export async function run(): Promise<void> {
}

try {
attachSummary(testResults)
attachSummary(testResults, detailedSummary)
} catch (error) {
core.error(`❌ Failed to set the summary using the provided token. (${error})`)
}
Expand Down

0 comments on commit 4a63872

Please sign in to comment.