Skip to content

Commit

Permalink
- update current run instead of creating a new one
Browse files Browse the repository at this point in the history
   - FIX #40
  • Loading branch information
mikepenz committed Nov 21, 2021
1 parent 0972ee4 commit f2f2c00
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 27 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ jobs:
uses: ./
if: endsWith(github.ref, 'main') == false
with:
check_name: Example JUnit Test Report
update_check: true
report_paths: '**/surefire-reports/TEST-*.xml'
summary: '<table><thead><tr><th> Application (src/applications) </th></tr></thead><tbody><tr><td> test </td></tr></tbody></table>'
- name: Test PyTest test import
uses: ./
if: endsWith(github.ref, 'main') == false
with:
check_name: Example Pytest Report
update_check: true
report_paths: test_results/python/report.xml
- name: Install NPM
run: |
Expand Down
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
37 changes: 28 additions & 9 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.

61 changes: 46 additions & 15 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')
const checkName = core.getInput('check_name')
const commit = core.getInput('commit')
const failOnFailure = core.getInput('fail_on_failure') === 'true'
Expand Down Expand Up @@ -61,27 +62,57 @@ export async function run(): Promise<void> {
`ℹ️ Posting status '${status}' 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 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))
await octokit.rest.checks.create(createCheckRequest)
} else {
const ref = head_sha
const check_name = github.context.job
const filter = 'latest'

const checks = await octokit.rest.checks.listForRef({
...github.context.repo,
ref,
check_name,
filter
})

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

const updateCheckRequest = {
...github.context.repo,
check_run_id,
output: {
title,
summary,
annotations: testResult.annotations.slice(0, 50)
}
}

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

await octokit.rest.checks.update(updateCheckRequest)
}

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

0 comments on commit f2f2c00

Please sign in to comment.