Skip to content

Commit

Permalink
fix: fail on error (#14)
Browse files Browse the repository at this point in the history
It'd be nice if this could be caught with CI, but I'm not sure how to
do that without having a failing status check show up, which would be
visually distracting.
  • Loading branch information
ericnorris authored Oct 18, 2021
1 parent 2351f08 commit 0ba7ae2
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@ import * as core from '@actions/core'
import * as github from '@actions/github'
import {RestEndpointMethodTypes} from '@octokit/plugin-rest-endpoint-methods'

// eslint-disable-next-line import/no-unresolved, sort-imports
// eslint-disable-next-line import/no-unresolved,sort-imports
import {PullRequestEvent} from '@octokit/webhooks-types'


type Status = RestEndpointMethodTypes['repos']['getCombinedStatusForRef']['response']['data']['statuses'][0]
type CheckRun = RestEndpointMethodTypes['checks']['listForRef']['response']['data']['check_runs'][0]
type Octokit = ReturnType<typeof github.getOctokit>

async function wait(seconds: number): Promise<void> {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
return new Promise<void>((resolve, reject) => {
return new Promise<void>(resolve => {
setTimeout(resolve, seconds * 1000)
})
}
Expand Down Expand Up @@ -142,26 +140,29 @@ async function loop(
const failedStatuses = completedStatuses
.filter(isStatusFailed)
.map(status => status.context)

const failedCheckRuns = completedCheckRuns
.filter(isCheckRunFailed)
.map(run => run.name)

if (failedStatuses.length || failedCheckRuns.length) {
core.error(
if (failedStatuses.length) {
core.setFailed(
`The following statuses have failed: [${failedStatuses.join(', ')}].`
)
core.error(
}

if (failedCheckRuns.length) {
core.setFailed(
`The following check runs have failed: [${failedCheckRuns.join(', ')}].`
)

return
}

core.info('All statuses and check runs have completed successfully.')
core.info('All statuses and check runs have completed.')

return
} while (elapsedSeconds < timeoutSeconds)

core.error(`Action timed out after ${timeoutSeconds} seconds.`)
core.setFailed(`Action timed out after ${timeoutSeconds} seconds.`)
}

async function combinedStatusLoopIteration(
Expand Down Expand Up @@ -257,8 +258,8 @@ async function checkRunLoopIteration(
try {
// eslint-disable-next-line github/no-then
main().catch(err => {
core.error(err)
core.setFailed(err)
})
} catch (err) {
core.error(String(err))
core.setFailed(String(err))
}

0 comments on commit 0ba7ae2

Please sign in to comment.