Skip to content

Commit

Permalink
Merge pull request #520 from mikepenz/feature/514
Browse files Browse the repository at this point in the history
Alternative annotation API
  • Loading branch information
mikepenz authored Mar 18, 2022
2 parents 127c778 + 0cefb4d commit 5cd4aff
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 61 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ jobs:
| `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. |

## Sample 🖥️

Expand Down
66 changes: 45 additions & 21 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.

98 changes: 59 additions & 39 deletions 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> {
return
}

const annotateOnly = core.getInput('annotate_only') === 'true'
const updateCheck = core.getInput('update_check') === 'true'
const checkName = core.getInput('check_name')
const commit = core.getInput('commit')
Expand Down Expand Up @@ -87,56 +88,75 @@ export async function run(): Promise<void> {

try {
const octokit = github.getOctokit(token)
if (annotateOnly) {
for (const annotation of testResult.annotations) {
const properties: core.AnnotationProperties = {
title: annotation.title,
file: annotation.path,
startLine: annotation.start_line,
endLine: annotation.end_line,
startColumn: annotation.start_column,
endColumn: annotation.end_column
}
if (annotation.annotation_level === 'failure') {
core.error(annotation.message, properties)
} else if (annotation.annotation_level === 'warning') {
core.warning(annotation.message, properties)
} else {
core.notice(annotation.message, properties)
}
}
} else {
if (updateCheck) {
const checks = await octokit.rest.checks.listForRef({
...github.context.repo,
ref: head_sha,
check_name: github.context.job,
status: 'in_progress',
filter: 'latest'
})

core.debug(JSON.stringify(checks, null, 2))

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

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

const updateCheckRequest = {
...github.context.repo,
check_run_id,
output: {
title,
summary,
annotations: sliced
}
}

if (updateCheck) {
const checks = await octokit.rest.checks.listForRef({
...github.context.repo,
ref: head_sha,
check_name: github.context.job,
status: 'in_progress',
filter: 'latest'
})

core.debug(JSON.stringify(checks, null, 2))

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

core.info(`ℹ️ 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.debug(JSON.stringify(updateCheckRequest, null, 2))

const updateCheckRequest = {
await octokit.rest.checks.update(updateCheckRequest)
}
} else {
const createCheckRequest = {
...github.context.repo,
check_run_id,
name: checkName,
head_sha,
status: 'completed',
conclusion,
output: {
title,
summary,
annotations: sliced
annotations: testResult.annotations.slice(0, 50)
}
}

core.debug(JSON.stringify(updateCheckRequest, null, 2))
core.debug(JSON.stringify(createCheckRequest, null, 2))

await octokit.rest.checks.update(updateCheckRequest)
core.info(`ℹ️ Creating check`)
await octokit.rest.checks.create(createCheckRequest)
}
} else {
const createCheckRequest = {
...github.context.repo,
name: checkName,
head_sha,
status: 'completed',
conclusion,
output: {
title,
summary,
annotations: testResult.annotations.slice(0, 50)
}
}

core.debug(JSON.stringify(createCheckRequest, null, 2))

core.info(`ℹ️ Creating check`)
await octokit.rest.checks.create(createCheckRequest)
}

if (failOnFailure && conclusion === 'failure') {
Expand Down

0 comments on commit 5cd4aff

Please sign in to comment.