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

Offer ability to update instead of creating a new checkRun #421

Merged
merged 8 commits into from
Nov 21, 2021
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
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)
Comment on lines +85 to +86

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌


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