mirror of
https://github.com/actions/deploy-pages.git
synced 2025-12-08 08:06:15 +00:00
fix error count lies and clean up tests a bit
This commit is contained in:
@@ -1 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="116" height="20" role="img" aria-label="Coverage: 76.32%"><title>Coverage: 76.32%</title><linearGradient id="s" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="r"><rect width="116" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#r)"><rect width="63" height="20" fill="#555"/><rect x="63" width="53" height="20" fill="#e05d44"/><rect width="116" height="20" fill="url(#s)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="325" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="530">Coverage</text><text x="325" y="140" transform="scale(.1)" fill="#fff" textLength="530">Coverage</text><text aria-hidden="true" x="885" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="430">76.32%</text><text x="885" y="140" transform="scale(.1)" fill="#fff" textLength="430">76.32%</text></g></svg>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="116" height="20" role="img" aria-label="Coverage: 78.74%"><title>Coverage: 78.74%</title><linearGradient id="s" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="r"><rect width="116" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#r)"><rect width="63" height="20" fill="#555"/><rect x="63" width="53" height="20" fill="#e05d44"/><rect width="116" height="20" fill="url(#s)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="325" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="530">Coverage</text><text x="325" y="140" transform="scale(.1)" fill="#fff" textLength="530">Coverage</text><text aria-hidden="true" x="885" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="430">78.74%</text><text x="885" y="140" transform="scale(.1)" fill="#fff" textLength="430">78.74%</text></g></svg>
|
||||
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
22
dist/index.js
generated
vendored
22
dist/index.js
generated
vendored
@@ -10143,16 +10143,6 @@ class Deployment {
|
||||
|
||||
/*eslint no-constant-condition: ["error", { "checkLoops": false }]*/
|
||||
while (true) {
|
||||
// Handle timeout
|
||||
if (Date.now() - this.startTime >= this.timeout) {
|
||||
core.error('Timeout reached, aborting!')
|
||||
core.setFailed('Timeout reached, aborting!')
|
||||
|
||||
// Explicitly cancel the deployment
|
||||
await this.cancel()
|
||||
return
|
||||
}
|
||||
|
||||
// Handle reporting interval
|
||||
await new Promise(resolve => setTimeout(resolve, reportingInterval + errorReportingInterval))
|
||||
|
||||
@@ -10201,7 +10191,7 @@ class Deployment {
|
||||
}
|
||||
}
|
||||
|
||||
if (errorCount >= maxErrorCount) {
|
||||
if (errorCount > maxErrorCount) {
|
||||
core.error('Too many errors, aborting!')
|
||||
core.setFailed('Failed with status code: ' + errorStatus)
|
||||
|
||||
@@ -10209,6 +10199,16 @@ class Deployment {
|
||||
await this.cancel()
|
||||
return
|
||||
}
|
||||
|
||||
// Handle timeout
|
||||
if (Date.now() - this.startTime >= this.timeout) {
|
||||
core.error('Timeout reached, aborting!')
|
||||
core.setFailed('Timeout reached, aborting!')
|
||||
|
||||
// Explicitly cancel the deployment
|
||||
await this.cancel()
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
@@ -46,6 +46,7 @@ describe('Deployment', () => {
|
||||
|
||||
describe('#create', () => {
|
||||
afterEach(() => {
|
||||
nock.cleanAll()
|
||||
// Remove mock for `core.getInput('preview')`
|
||||
delete process.env.INPUT_PREVIEW
|
||||
})
|
||||
@@ -53,7 +54,8 @@ describe('Deployment', () => {
|
||||
it('can successfully create a deployment', async () => {
|
||||
process.env.GITHUB_SHA = 'valid-build-version'
|
||||
|
||||
const artifactExchangeScope = nock(`http://my-url`)
|
||||
// For artifact exchange
|
||||
nock(`http://my-url`)
|
||||
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
||||
.reply(200, {
|
||||
value: [
|
||||
@@ -62,7 +64,8 @@ describe('Deployment', () => {
|
||||
]
|
||||
})
|
||||
|
||||
const createDeploymentScope = nock('https://api.github.com')
|
||||
// for deployment creation
|
||||
nock('https://api.github.com')
|
||||
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
||||
artifact_url: 'https://fake-artifact.com&%24expand=SignedContent',
|
||||
pages_build_version: process.env.GITHUB_SHA,
|
||||
@@ -83,15 +86,12 @@ describe('Deployment', () => {
|
||||
expect(core.info).toHaveBeenLastCalledWith(
|
||||
expect.stringMatching(new RegExp(`^Created deployment for ${process.env.GITHUB_SHA}`))
|
||||
)
|
||||
|
||||
artifactExchangeScope.done()
|
||||
createDeploymentScope.done()
|
||||
})
|
||||
|
||||
it('can successfully create a preview deployment', async () => {
|
||||
process.env.GITHUB_SHA = 'valid-build-version'
|
||||
|
||||
const artifactExchangeScope = nock(`http://my-url`)
|
||||
nock(`http://my-url`)
|
||||
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
||||
.reply(200, {
|
||||
value: [
|
||||
@@ -100,7 +100,7 @@ describe('Deployment', () => {
|
||||
]
|
||||
})
|
||||
|
||||
const createDeploymentScope = nock('https://api.github.com')
|
||||
nock('https://api.github.com')
|
||||
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
||||
artifact_url: 'https://fake-artifact.com&%24expand=SignedContent',
|
||||
pages_build_version: process.env.GITHUB_SHA,
|
||||
@@ -126,16 +126,11 @@ describe('Deployment', () => {
|
||||
expect(core.info).toHaveBeenLastCalledWith(
|
||||
expect.stringMatching(new RegExp(`^Created deployment for ${process.env.GITHUB_SHA}`))
|
||||
)
|
||||
|
||||
artifactExchangeScope.done()
|
||||
createDeploymentScope.done()
|
||||
})
|
||||
|
||||
it('reports errors with failed artifact exchange', async () => {
|
||||
process.env.GITHUB_SHA = 'invalid-build-version'
|
||||
const artifactExchangeScope = nock(`http://my-url`)
|
||||
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
||||
.reply(400, {})
|
||||
nock(`http://my-url`).get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview').reply(400, {})
|
||||
|
||||
// Create the deployment
|
||||
const deployment = new Deployment()
|
||||
@@ -144,17 +139,15 @@ describe('Deployment', () => {
|
||||
`Failed to create deployment (status: 400) with build version ${process.env.GITHUB_SHA}. Responded with: Bad Request`
|
||||
)
|
||||
)
|
||||
|
||||
artifactExchangeScope.done()
|
||||
})
|
||||
|
||||
it('reports errors with a failed 500 in a deployment', async () => {
|
||||
process.env.GITHUB_SHA = 'build-version'
|
||||
const artifactExchangeScope = nock(`http://my-url`)
|
||||
nock(`http://my-url`)
|
||||
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
||||
.reply(200, { value: [{ url: 'https://invalid-artifact.com', name: 'github-pages' }] })
|
||||
|
||||
const createDeploymentScope = nock('https://api.github.com')
|
||||
nock('https://api.github.com')
|
||||
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
||||
artifact_url: 'https://invalid-artifact.com&%24expand=SignedContent',
|
||||
pages_build_version: process.env.GITHUB_SHA
|
||||
@@ -168,18 +161,15 @@ describe('Deployment', () => {
|
||||
`Failed to create deployment (status: 500) with build version ${process.env.GITHUB_SHA}. Server error, is githubstatus.com reporting a Pages outage? Please re-run the deployment at a later time.`
|
||||
)
|
||||
)
|
||||
|
||||
artifactExchangeScope.done()
|
||||
createDeploymentScope.done()
|
||||
})
|
||||
|
||||
it('reports errors with an unexpected 403 during deployment', async () => {
|
||||
process.env.GITHUB_SHA = 'build-version'
|
||||
const artifactExchangeScope = nock(`http://my-url`)
|
||||
nock(`http://my-url`)
|
||||
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
||||
.reply(200, { value: [{ url: 'https://invalid-artifact.com', name: 'github-pages' }] })
|
||||
|
||||
const createDeploymentScope = nock('https://api.github.com')
|
||||
nock('https://api.github.com')
|
||||
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
||||
artifact_url: 'https://invalid-artifact.com&%24expand=SignedContent',
|
||||
pages_build_version: process.env.GITHUB_SHA
|
||||
@@ -193,18 +183,15 @@ describe('Deployment', () => {
|
||||
`Failed to create deployment (status: 403) with build version ${process.env.GITHUB_SHA}. Ensure GITHUB_TOKEN has permission "pages: write".`
|
||||
)
|
||||
)
|
||||
|
||||
artifactExchangeScope.done()
|
||||
createDeploymentScope.done()
|
||||
})
|
||||
|
||||
it('reports errors with an unexpected 404 during deployment', async () => {
|
||||
process.env.GITHUB_SHA = 'build-version'
|
||||
const artifactExchangeScope = nock(`http://my-url`)
|
||||
nock(`http://my-url`)
|
||||
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
||||
.reply(200, { value: [{ url: 'https://invalid-artifact.com', name: 'github-pages' }] })
|
||||
|
||||
const createDeploymentScope = nock('https://api.github.com')
|
||||
nock('https://api.github.com')
|
||||
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
||||
artifact_url: 'https://invalid-artifact.com&%24expand=SignedContent',
|
||||
pages_build_version: process.env.GITHUB_SHA
|
||||
@@ -218,18 +205,15 @@ describe('Deployment', () => {
|
||||
`Failed to create deployment (status: 404) with build version ${process.env.GITHUB_SHA}. Ensure GitHub Pages has been enabled: https://github.com/actions/is-awesome/settings/pages`
|
||||
)
|
||||
)
|
||||
|
||||
artifactExchangeScope.done()
|
||||
createDeploymentScope.done()
|
||||
})
|
||||
|
||||
it('reports errors with failed deployments', async () => {
|
||||
process.env.GITHUB_SHA = 'invalid-build-version'
|
||||
const artifactExchangeScope = nock(`http://my-url`)
|
||||
nock(`http://my-url`)
|
||||
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
||||
.reply(200, { value: [{ url: 'https://invalid-artifact.com', name: 'github-pages' }] })
|
||||
|
||||
const createDeploymentScope = nock('https://api.github.com')
|
||||
nock('https://api.github.com')
|
||||
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
||||
artifact_url: 'https://invalid-artifact.com&%24expand=SignedContent',
|
||||
pages_build_version: process.env.GITHUB_SHA
|
||||
@@ -243,15 +227,12 @@ describe('Deployment', () => {
|
||||
`Failed to create deployment (status: 400) with build version ${process.env.GITHUB_SHA}. Responded with: Bad request`
|
||||
)
|
||||
)
|
||||
|
||||
artifactExchangeScope.done()
|
||||
createDeploymentScope.done()
|
||||
})
|
||||
|
||||
it('warns when the timeout is greater than the maximum allowed', async () => {
|
||||
process.env.GITHUB_SHA = 'valid-build-version'
|
||||
|
||||
const artifactExchangeScope = nock(`http://my-url`)
|
||||
nock(`http://my-url`)
|
||||
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
||||
.reply(200, {
|
||||
value: [
|
||||
@@ -260,7 +241,7 @@ describe('Deployment', () => {
|
||||
]
|
||||
})
|
||||
|
||||
const createDeploymentScope = nock('https://api.github.com')
|
||||
nock('https://api.github.com')
|
||||
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
||||
artifact_url: 'https://fake-artifact.com&%24expand=SignedContent',
|
||||
pages_build_version: process.env.GITHUB_SHA,
|
||||
@@ -292,17 +273,18 @@ describe('Deployment', () => {
|
||||
expect(core.warning).toBeCalledWith(
|
||||
`Warning: timeout value is greater than the allowed maximum - timeout set to the maximum of ${maxTimeout} milliseconds.`
|
||||
)
|
||||
|
||||
artifactExchangeScope.done()
|
||||
createDeploymentScope.done()
|
||||
})
|
||||
})
|
||||
|
||||
describe('#check', () => {
|
||||
afterEach(() => {
|
||||
nock.cleanAll()
|
||||
})
|
||||
|
||||
it('sets output to success when deployment is successful', async () => {
|
||||
process.env.GITHUB_SHA = 'valid-build-version'
|
||||
|
||||
const artifactExchangeScope = nock(`http://my-url`)
|
||||
nock(`http://my-url`)
|
||||
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
||||
.reply(200, {
|
||||
value: [
|
||||
@@ -311,7 +293,7 @@ describe('Deployment', () => {
|
||||
]
|
||||
})
|
||||
|
||||
const createDeploymentScope = nock('https://api.github.com')
|
||||
nock('https://api.github.com')
|
||||
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
||||
artifact_url: 'https://fake-artifact.com&%24expand=SignedContent',
|
||||
pages_build_version: process.env.GITHUB_SHA,
|
||||
@@ -322,7 +304,8 @@ describe('Deployment', () => {
|
||||
page_url: 'https://actions.github.io/is-awesome'
|
||||
})
|
||||
|
||||
const deploymentStatusScope = nock('https://api.github.com')
|
||||
// for deployment status
|
||||
nock('https://api.github.com')
|
||||
.get(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}`)
|
||||
.reply(200, {
|
||||
status: 'succeed'
|
||||
@@ -337,10 +320,6 @@ describe('Deployment', () => {
|
||||
|
||||
expect(core.setOutput).toBeCalledWith('status', 'succeed')
|
||||
expect(core.info).toHaveBeenLastCalledWith('Reported success!')
|
||||
|
||||
artifactExchangeScope.done()
|
||||
createDeploymentScope.done()
|
||||
deploymentStatusScope.done()
|
||||
})
|
||||
|
||||
it('fails check when no deployment is found', async () => {
|
||||
@@ -353,7 +332,7 @@ describe('Deployment', () => {
|
||||
it('exits early when deployment is not in progress', async () => {
|
||||
process.env.GITHUB_SHA = 'valid-build-version'
|
||||
|
||||
const artifactExchangeScope = nock(`http://my-url`)
|
||||
nock(`http://my-url`)
|
||||
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
||||
.reply(200, {
|
||||
value: [
|
||||
@@ -362,7 +341,7 @@ describe('Deployment', () => {
|
||||
]
|
||||
})
|
||||
|
||||
const createDeploymentScope = nock('https://api.github.com')
|
||||
nock('https://api.github.com')
|
||||
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
||||
artifact_url: 'https://fake-artifact.com&%24expand=SignedContent',
|
||||
pages_build_version: process.env.GITHUB_SHA,
|
||||
@@ -380,15 +359,12 @@ describe('Deployment', () => {
|
||||
deployment.deploymentInfo.pending = false
|
||||
await deployment.check()
|
||||
expect(core.setFailed).toBeCalledWith('Unable to get deployment status.')
|
||||
|
||||
artifactExchangeScope.done()
|
||||
createDeploymentScope.done()
|
||||
})
|
||||
|
||||
it('enforces max timeout', async () => {
|
||||
process.env.GITHUB_SHA = 'valid-build-version'
|
||||
|
||||
const artifactExchangeScope = nock(`http://my-url`)
|
||||
nock(`http://my-url`)
|
||||
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
||||
.reply(200, {
|
||||
value: [
|
||||
@@ -397,7 +373,7 @@ describe('Deployment', () => {
|
||||
]
|
||||
})
|
||||
|
||||
const createDeploymentScope = nock('https://api.github.com')
|
||||
nock('https://api.github.com')
|
||||
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
||||
artifact_url: 'https://fake-artifact.com&%24expand=SignedContent',
|
||||
pages_build_version: process.env.GITHUB_SHA,
|
||||
@@ -408,7 +384,15 @@ describe('Deployment', () => {
|
||||
page_url: 'https://actions.github.io/is-awesome'
|
||||
})
|
||||
|
||||
const cancelDeploymentScope = nock('https://api.github.com')
|
||||
nock('https://api.github.com')
|
||||
.persist()
|
||||
.get(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}`)
|
||||
.reply(200, {
|
||||
status: 'in_progress'
|
||||
})
|
||||
|
||||
// for cancel deployment
|
||||
nock('https://api.github.com')
|
||||
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}/cancel`)
|
||||
.reply(200, {})
|
||||
|
||||
@@ -443,16 +427,12 @@ describe('Deployment', () => {
|
||||
expect(deployment.timeout).toEqual(maxTimeout)
|
||||
expect(core.error).toBeCalledWith('Timeout reached, aborting!')
|
||||
expect(core.setFailed).toBeCalledWith('Timeout reached, aborting!')
|
||||
|
||||
artifactExchangeScope.done()
|
||||
createDeploymentScope.done()
|
||||
cancelDeploymentScope.done()
|
||||
})
|
||||
|
||||
it('sets timeout to user timeout if user timeout is less than max timeout', async () => {
|
||||
process.env.GITHUB_SHA = 'valid-build-version'
|
||||
|
||||
const artifactExchangeScope = nock(`http://my-url`)
|
||||
nock(`http://my-url`)
|
||||
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
||||
.reply(200, {
|
||||
value: [
|
||||
@@ -461,7 +441,7 @@ describe('Deployment', () => {
|
||||
]
|
||||
})
|
||||
|
||||
const createDeploymentScope = nock('https://api.github.com')
|
||||
nock('https://api.github.com')
|
||||
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
||||
artifact_url: 'https://fake-artifact.com&%24expand=SignedContent',
|
||||
pages_build_version: process.env.GITHUB_SHA,
|
||||
@@ -472,7 +452,14 @@ describe('Deployment', () => {
|
||||
page_url: 'https://actions.github.io/is-awesome'
|
||||
})
|
||||
|
||||
const cancelDeploymentScope = nock('https://api.github.com')
|
||||
nock('https://api.github.com')
|
||||
.persist()
|
||||
.get(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}`)
|
||||
.reply(200, {
|
||||
status: 'in_progress'
|
||||
})
|
||||
|
||||
nock('https://api.github.com')
|
||||
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}/cancel`)
|
||||
.reply(200, {})
|
||||
|
||||
@@ -507,16 +494,12 @@ describe('Deployment', () => {
|
||||
expect(deployment.timeout).toEqual(42)
|
||||
expect(core.error).toBeCalledWith('Timeout reached, aborting!')
|
||||
expect(core.setFailed).toBeCalledWith('Timeout reached, aborting!')
|
||||
|
||||
artifactExchangeScope.done()
|
||||
createDeploymentScope.done()
|
||||
cancelDeploymentScope.done()
|
||||
})
|
||||
|
||||
it('sets output to success when timeout is set but not reached', async () => {
|
||||
process.env.GITHUB_SHA = 'valid-build-version'
|
||||
|
||||
const artifactExchangeScope = nock(`http://my-url`)
|
||||
nock(`http://my-url`)
|
||||
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
||||
.reply(200, {
|
||||
value: [
|
||||
@@ -525,7 +508,7 @@ describe('Deployment', () => {
|
||||
]
|
||||
})
|
||||
|
||||
const createDeploymentScope = nock('https://api.github.com')
|
||||
nock('https://api.github.com')
|
||||
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
||||
artifact_url: 'https://fake-artifact.com&%24expand=SignedContent',
|
||||
pages_build_version: process.env.GITHUB_SHA,
|
||||
@@ -536,7 +519,7 @@ describe('Deployment', () => {
|
||||
page_url: 'https://actions.github.io/is-awesome'
|
||||
})
|
||||
|
||||
const deploymentStatusScope = nock('https://api.github.com')
|
||||
nock('https://api.github.com')
|
||||
.get(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}`)
|
||||
.reply(200, {
|
||||
status: 'succeed'
|
||||
@@ -574,18 +557,18 @@ describe('Deployment', () => {
|
||||
expect(core.error).not.toBeCalled()
|
||||
expect(core.setOutput).toBeCalledWith('status', 'succeed')
|
||||
expect(core.info).toHaveBeenLastCalledWith('Reported success!')
|
||||
|
||||
artifactExchangeScope.done()
|
||||
createDeploymentScope.done()
|
||||
deploymentStatusScope.done()
|
||||
})
|
||||
})
|
||||
|
||||
describe('#cancel', () => {
|
||||
afterEach(() => {
|
||||
nock.cleanAll()
|
||||
})
|
||||
|
||||
it('can successfully cancel a deployment', async () => {
|
||||
process.env.GITHUB_SHA = 'valid-build-version'
|
||||
|
||||
const artifactExchangeScope = nock(`http://my-url`)
|
||||
nock(`http://my-url`)
|
||||
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
||||
.reply(200, {
|
||||
value: [
|
||||
@@ -594,7 +577,7 @@ describe('Deployment', () => {
|
||||
]
|
||||
})
|
||||
|
||||
const createDeploymentScope = nock('https://api.github.com')
|
||||
nock('https://api.github.com')
|
||||
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
||||
artifact_url: 'https://fake-artifact.com&%24expand=SignedContent',
|
||||
pages_build_version: process.env.GITHUB_SHA,
|
||||
@@ -605,7 +588,7 @@ describe('Deployment', () => {
|
||||
page_url: 'https://actions.github.io/is-awesome'
|
||||
})
|
||||
|
||||
const cancelDeploymentScope = nock('https://api.github.com')
|
||||
nock('https://api.github.com')
|
||||
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}/cancel`)
|
||||
.reply(200, {})
|
||||
|
||||
@@ -619,10 +602,6 @@ describe('Deployment', () => {
|
||||
await deployment.cancel()
|
||||
|
||||
expect(core.info).toHaveBeenLastCalledWith(`Canceled deployment with ID ${process.env.GITHUB_SHA}`)
|
||||
|
||||
artifactExchangeScope.done()
|
||||
createDeploymentScope.done()
|
||||
cancelDeploymentScope.done()
|
||||
})
|
||||
|
||||
it('can exit if a pages deployment was not created and none need to be cancelled', async () => {
|
||||
@@ -641,7 +620,7 @@ describe('Deployment', () => {
|
||||
it('catches an error when trying to cancel a deployment', async () => {
|
||||
process.env.GITHUB_SHA = 'valid-build-version'
|
||||
|
||||
const artifactExchangeScope = nock(`http://my-url`)
|
||||
nock(`http://my-url`)
|
||||
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
||||
.reply(200, {
|
||||
value: [
|
||||
@@ -650,7 +629,7 @@ describe('Deployment', () => {
|
||||
]
|
||||
})
|
||||
|
||||
const createDeploymentScope = nock('https://api.github.com')
|
||||
nock('https://api.github.com')
|
||||
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
||||
artifact_url: 'https://fake-artifact.com&%24expand=SignedContent',
|
||||
pages_build_version: process.env.GITHUB_SHA,
|
||||
@@ -662,7 +641,7 @@ describe('Deployment', () => {
|
||||
})
|
||||
|
||||
// nock will throw an error every time it tries to cancel the deployment
|
||||
const cancelDeploymentScope = nock('https://api.github.com')
|
||||
nock('https://api.github.com')
|
||||
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}/cancel`)
|
||||
.reply(500, {})
|
||||
|
||||
@@ -676,10 +655,6 @@ describe('Deployment', () => {
|
||||
await deployment.cancel()
|
||||
|
||||
expect(core.error).toHaveBeenCalledWith(`Canceling Pages deployment failed`, expect.anything())
|
||||
|
||||
artifactExchangeScope.done()
|
||||
createDeploymentScope.done()
|
||||
cancelDeploymentScope.done()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -143,16 +143,6 @@ class Deployment {
|
||||
|
||||
/*eslint no-constant-condition: ["error", { "checkLoops": false }]*/
|
||||
while (true) {
|
||||
// Handle timeout
|
||||
if (Date.now() - this.startTime >= this.timeout) {
|
||||
core.error('Timeout reached, aborting!')
|
||||
core.setFailed('Timeout reached, aborting!')
|
||||
|
||||
// Explicitly cancel the deployment
|
||||
await this.cancel()
|
||||
return
|
||||
}
|
||||
|
||||
// Handle reporting interval
|
||||
await new Promise(resolve => setTimeout(resolve, reportingInterval + errorReportingInterval))
|
||||
|
||||
@@ -201,7 +191,7 @@ class Deployment {
|
||||
}
|
||||
}
|
||||
|
||||
if (errorCount >= maxErrorCount) {
|
||||
if (errorCount > maxErrorCount) {
|
||||
core.error('Too many errors, aborting!')
|
||||
core.setFailed('Failed with status code: ' + errorStatus)
|
||||
|
||||
@@ -209,6 +199,16 @@ class Deployment {
|
||||
await this.cancel()
|
||||
return
|
||||
}
|
||||
|
||||
// Handle timeout
|
||||
if (Date.now() - this.startTime >= this.timeout) {
|
||||
core.error('Timeout reached, aborting!')
|
||||
core.setFailed('Timeout reached, aborting!')
|
||||
|
||||
// Explicitly cancel the deployment
|
||||
await this.cancel()
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user