Skip to content

Commit

Permalink
Merge pull request #421 from mikepenz/feature/40
Browse files Browse the repository at this point in the history
Offer ability to update instead of creating a new checkRun
  • Loading branch information
mikepenz authored Nov 21, 2021
2 parents 0972ee4 + 6a3cae3 commit 78ae03b
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 29 deletions.
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ inputs:
description: 'Regular expression for the named test suites'
required: false
default: ''
update_check:
description: 'Defines if the active check should be updated instead'
required: false
default: 'false'
check_name:
description: 'Check name for test reports.'
required: false
Expand Down
40 changes: 29 additions & 11 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.

71 changes: 54 additions & 17 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 updateCheck = core.getInput('update_check') === 'true'
const checkName = core.getInput('check_name')
const commit = core.getInput('commit')
const failOnFailure = core.getInput('fail_on_failure') === 'true'
Expand Down Expand Up @@ -54,34 +55,70 @@ export async function run(): Promise<void> {
foundResults && testResult.annotations.length === 0
? 'success'
: 'failure'
const status: 'completed' = 'completed'
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 with conclusion '${conclusion}' to ${link} (sha: ${head_sha})`
)

const createCheckRequest = {
...github.context.repo,
name: checkName,
head_sha,
status,
conclusion,
output: {
title,
summary,
annotations: testResult.annotations.slice(0, 50)
}
}

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

core.startGroup(`🚀 Publish results`)

try {
const octokit = github.getOctokit(token)
await octokit.rest.checks.create(createCheckRequest)

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,
conclusion,
annotations: sliced
}
}

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

await octokit.rest.checks.update(updateCheckRequest)
}
} 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') {
core.setFailed(
Expand Down

0 comments on commit 78ae03b

Please sign in to comment.