Skip to content

Commit

Permalink
Merge pull request #1 from zentered/fix/abort-poll
Browse files Browse the repository at this point in the history
fix(polling): abort when build fails
  • Loading branch information
PatrickHeneise authored Jul 8, 2021
2 parents 0b02932 + 95fd6e1 commit 832c448
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ jobs:
uses: github/[email protected]
env:
LINTER_RULES_PATH: /
FILTER_REGEX_EXCLUDE: (.*dist\/.*)|(.husky\/.*)
JAVASCRIPT_ES_CONFIG_FILE: .eslintrc.json
VALIDATE_ALL_CODEBASE: true
VALIDATE_JAVASCRIPT_STANDARD: false
DEFAULT_BRANCH: main
IGNORE_GENERATED_FILES: true
- run: npm test
6 changes: 6 additions & 0 deletions cloudflare-statuscheck.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ export default async function waitForDeployment(
if (!build) {
core.error(data)
core.setFailed('no build with this ID found.')
throw new Error('No build id. Abort.')
}

if (build.latest_stage.status === 'failure') {
core.setFailed(`${build.latest_stage.name}: ${build.latest_stage.status}`)
throw new Error('Build failed. Abort.')
}

return (
Expand Down
6 changes: 6 additions & 0 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.

30 changes: 29 additions & 1 deletion test/cloudflare-statuscheck.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import axios from 'axios'

jest.mock('@actions/core', () => {
return {
info: jest.fn()
info: jest.fn(),
setFailed: jest.fn()
}
})
jest.mock('axios')
Expand Down Expand Up @@ -58,3 +59,30 @@ test('waitForDeployment() should wait until a deployment is successful', async (
expect(firstCheck).toEqual(false)
expect(secondCheck).toEqual(true)
})

test('waitForDeployment() should abort when a build has failed', async () => {
axios.get.mockResolvedValueOnce({
data: {
result: [
{
id: '123abc',
environment: 'preview',
latest_stage: {
name: 'build',
status: 'failure'
}
}
]
}
})

await expect(
checkDeploymentStatus(
'123xyz',
'zentered',
'[email protected]',
'cf-project',
'123abc'
)
).rejects.toThrow('Build failed. Abort.')
})

0 comments on commit 832c448

Please sign in to comment.