mirror of
https://github.com/actions/deploy-pages.git
synced 2025-12-08 08:06:15 +00:00
Revert "fix error count lies and clean up tests a bit"
This reverts commit 3e2c26d7d5.
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: 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>
|
<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>
|
||||||
|
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,6 +10143,16 @@ class Deployment {
|
|||||||
|
|
||||||
/*eslint no-constant-condition: ["error", { "checkLoops": false }]*/
|
/*eslint no-constant-condition: ["error", { "checkLoops": false }]*/
|
||||||
while (true) {
|
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
|
// Handle reporting interval
|
||||||
await new Promise(resolve => setTimeout(resolve, reportingInterval + errorReportingInterval))
|
await new Promise(resolve => setTimeout(resolve, reportingInterval + errorReportingInterval))
|
||||||
|
|
||||||
@@ -10191,7 +10201,7 @@ class Deployment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (errorCount > maxErrorCount) {
|
if (errorCount >= maxErrorCount) {
|
||||||
core.error('Too many errors, aborting!')
|
core.error('Too many errors, aborting!')
|
||||||
core.setFailed('Failed with status code: ' + errorStatus)
|
core.setFailed('Failed with status code: ' + errorStatus)
|
||||||
|
|
||||||
@@ -10199,16 +10209,6 @@ class Deployment {
|
|||||||
await this.cancel()
|
await this.cancel()
|
||||||
return
|
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,7 +46,6 @@ describe('Deployment', () => {
|
|||||||
|
|
||||||
describe('#create', () => {
|
describe('#create', () => {
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
nock.cleanAll()
|
|
||||||
// Remove mock for `core.getInput('preview')`
|
// Remove mock for `core.getInput('preview')`
|
||||||
delete process.env.INPUT_PREVIEW
|
delete process.env.INPUT_PREVIEW
|
||||||
})
|
})
|
||||||
@@ -54,8 +53,7 @@ describe('Deployment', () => {
|
|||||||
it('can successfully create a deployment', async () => {
|
it('can successfully create a deployment', async () => {
|
||||||
process.env.GITHUB_SHA = 'valid-build-version'
|
process.env.GITHUB_SHA = 'valid-build-version'
|
||||||
|
|
||||||
// For artifact exchange
|
const artifactExchangeScope = nock(`http://my-url`)
|
||||||
nock(`http://my-url`)
|
|
||||||
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
||||||
.reply(200, {
|
.reply(200, {
|
||||||
value: [
|
value: [
|
||||||
@@ -64,8 +62,7 @@ describe('Deployment', () => {
|
|||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
// for deployment creation
|
const createDeploymentScope = nock('https://api.github.com')
|
||||||
nock('https://api.github.com')
|
|
||||||
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
||||||
artifact_url: 'https://fake-artifact.com&%24expand=SignedContent',
|
artifact_url: 'https://fake-artifact.com&%24expand=SignedContent',
|
||||||
pages_build_version: process.env.GITHUB_SHA,
|
pages_build_version: process.env.GITHUB_SHA,
|
||||||
@@ -86,12 +83,15 @@ describe('Deployment', () => {
|
|||||||
expect(core.info).toHaveBeenLastCalledWith(
|
expect(core.info).toHaveBeenLastCalledWith(
|
||||||
expect.stringMatching(new RegExp(`^Created deployment for ${process.env.GITHUB_SHA}`))
|
expect.stringMatching(new RegExp(`^Created deployment for ${process.env.GITHUB_SHA}`))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
artifactExchangeScope.done()
|
||||||
|
createDeploymentScope.done()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can successfully create a preview deployment', async () => {
|
it('can successfully create a preview deployment', async () => {
|
||||||
process.env.GITHUB_SHA = 'valid-build-version'
|
process.env.GITHUB_SHA = 'valid-build-version'
|
||||||
|
|
||||||
nock(`http://my-url`)
|
const artifactExchangeScope = nock(`http://my-url`)
|
||||||
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
||||||
.reply(200, {
|
.reply(200, {
|
||||||
value: [
|
value: [
|
||||||
@@ -100,7 +100,7 @@ describe('Deployment', () => {
|
|||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
nock('https://api.github.com')
|
const createDeploymentScope = nock('https://api.github.com')
|
||||||
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
||||||
artifact_url: 'https://fake-artifact.com&%24expand=SignedContent',
|
artifact_url: 'https://fake-artifact.com&%24expand=SignedContent',
|
||||||
pages_build_version: process.env.GITHUB_SHA,
|
pages_build_version: process.env.GITHUB_SHA,
|
||||||
@@ -126,11 +126,16 @@ describe('Deployment', () => {
|
|||||||
expect(core.info).toHaveBeenLastCalledWith(
|
expect(core.info).toHaveBeenLastCalledWith(
|
||||||
expect.stringMatching(new RegExp(`^Created deployment for ${process.env.GITHUB_SHA}`))
|
expect.stringMatching(new RegExp(`^Created deployment for ${process.env.GITHUB_SHA}`))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
artifactExchangeScope.done()
|
||||||
|
createDeploymentScope.done()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('reports errors with failed artifact exchange', async () => {
|
it('reports errors with failed artifact exchange', async () => {
|
||||||
process.env.GITHUB_SHA = 'invalid-build-version'
|
process.env.GITHUB_SHA = 'invalid-build-version'
|
||||||
nock(`http://my-url`).get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview').reply(400, {})
|
const artifactExchangeScope = nock(`http://my-url`)
|
||||||
|
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
||||||
|
.reply(400, {})
|
||||||
|
|
||||||
// Create the deployment
|
// Create the deployment
|
||||||
const deployment = new Deployment()
|
const deployment = new Deployment()
|
||||||
@@ -139,15 +144,17 @@ describe('Deployment', () => {
|
|||||||
`Failed to create deployment (status: 400) with build version ${process.env.GITHUB_SHA}. Responded with: Bad Request`
|
`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 () => {
|
it('reports errors with a failed 500 in a deployment', async () => {
|
||||||
process.env.GITHUB_SHA = 'build-version'
|
process.env.GITHUB_SHA = 'build-version'
|
||||||
nock(`http://my-url`)
|
const artifactExchangeScope = nock(`http://my-url`)
|
||||||
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
||||||
.reply(200, { value: [{ url: 'https://invalid-artifact.com', name: 'github-pages' }] })
|
.reply(200, { value: [{ url: 'https://invalid-artifact.com', name: 'github-pages' }] })
|
||||||
|
|
||||||
nock('https://api.github.com')
|
const createDeploymentScope = nock('https://api.github.com')
|
||||||
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
||||||
artifact_url: 'https://invalid-artifact.com&%24expand=SignedContent',
|
artifact_url: 'https://invalid-artifact.com&%24expand=SignedContent',
|
||||||
pages_build_version: process.env.GITHUB_SHA
|
pages_build_version: process.env.GITHUB_SHA
|
||||||
@@ -161,15 +168,18 @@ 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.`
|
`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 () => {
|
it('reports errors with an unexpected 403 during deployment', async () => {
|
||||||
process.env.GITHUB_SHA = 'build-version'
|
process.env.GITHUB_SHA = 'build-version'
|
||||||
nock(`http://my-url`)
|
const artifactExchangeScope = nock(`http://my-url`)
|
||||||
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
||||||
.reply(200, { value: [{ url: 'https://invalid-artifact.com', name: 'github-pages' }] })
|
.reply(200, { value: [{ url: 'https://invalid-artifact.com', name: 'github-pages' }] })
|
||||||
|
|
||||||
nock('https://api.github.com')
|
const createDeploymentScope = nock('https://api.github.com')
|
||||||
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
||||||
artifact_url: 'https://invalid-artifact.com&%24expand=SignedContent',
|
artifact_url: 'https://invalid-artifact.com&%24expand=SignedContent',
|
||||||
pages_build_version: process.env.GITHUB_SHA
|
pages_build_version: process.env.GITHUB_SHA
|
||||||
@@ -183,15 +193,18 @@ describe('Deployment', () => {
|
|||||||
`Failed to create deployment (status: 403) with build version ${process.env.GITHUB_SHA}. Ensure GITHUB_TOKEN has permission "pages: write".`
|
`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 () => {
|
it('reports errors with an unexpected 404 during deployment', async () => {
|
||||||
process.env.GITHUB_SHA = 'build-version'
|
process.env.GITHUB_SHA = 'build-version'
|
||||||
nock(`http://my-url`)
|
const artifactExchangeScope = nock(`http://my-url`)
|
||||||
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
||||||
.reply(200, { value: [{ url: 'https://invalid-artifact.com', name: 'github-pages' }] })
|
.reply(200, { value: [{ url: 'https://invalid-artifact.com', name: 'github-pages' }] })
|
||||||
|
|
||||||
nock('https://api.github.com')
|
const createDeploymentScope = nock('https://api.github.com')
|
||||||
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
||||||
artifact_url: 'https://invalid-artifact.com&%24expand=SignedContent',
|
artifact_url: 'https://invalid-artifact.com&%24expand=SignedContent',
|
||||||
pages_build_version: process.env.GITHUB_SHA
|
pages_build_version: process.env.GITHUB_SHA
|
||||||
@@ -205,15 +218,18 @@ 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`
|
`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 () => {
|
it('reports errors with failed deployments', async () => {
|
||||||
process.env.GITHUB_SHA = 'invalid-build-version'
|
process.env.GITHUB_SHA = 'invalid-build-version'
|
||||||
nock(`http://my-url`)
|
const artifactExchangeScope = nock(`http://my-url`)
|
||||||
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
||||||
.reply(200, { value: [{ url: 'https://invalid-artifact.com', name: 'github-pages' }] })
|
.reply(200, { value: [{ url: 'https://invalid-artifact.com', name: 'github-pages' }] })
|
||||||
|
|
||||||
nock('https://api.github.com')
|
const createDeploymentScope = nock('https://api.github.com')
|
||||||
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
||||||
artifact_url: 'https://invalid-artifact.com&%24expand=SignedContent',
|
artifact_url: 'https://invalid-artifact.com&%24expand=SignedContent',
|
||||||
pages_build_version: process.env.GITHUB_SHA
|
pages_build_version: process.env.GITHUB_SHA
|
||||||
@@ -227,12 +243,15 @@ describe('Deployment', () => {
|
|||||||
`Failed to create deployment (status: 400) with build version ${process.env.GITHUB_SHA}. Responded with: Bad request`
|
`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 () => {
|
it('warns when the timeout is greater than the maximum allowed', async () => {
|
||||||
process.env.GITHUB_SHA = 'valid-build-version'
|
process.env.GITHUB_SHA = 'valid-build-version'
|
||||||
|
|
||||||
nock(`http://my-url`)
|
const artifactExchangeScope = nock(`http://my-url`)
|
||||||
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
||||||
.reply(200, {
|
.reply(200, {
|
||||||
value: [
|
value: [
|
||||||
@@ -241,7 +260,7 @@ describe('Deployment', () => {
|
|||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
nock('https://api.github.com')
|
const createDeploymentScope = nock('https://api.github.com')
|
||||||
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
||||||
artifact_url: 'https://fake-artifact.com&%24expand=SignedContent',
|
artifact_url: 'https://fake-artifact.com&%24expand=SignedContent',
|
||||||
pages_build_version: process.env.GITHUB_SHA,
|
pages_build_version: process.env.GITHUB_SHA,
|
||||||
@@ -273,18 +292,17 @@ describe('Deployment', () => {
|
|||||||
expect(core.warning).toBeCalledWith(
|
expect(core.warning).toBeCalledWith(
|
||||||
`Warning: timeout value is greater than the allowed maximum - timeout set to the maximum of ${maxTimeout} milliseconds.`
|
`Warning: timeout value is greater than the allowed maximum - timeout set to the maximum of ${maxTimeout} milliseconds.`
|
||||||
)
|
)
|
||||||
|
|
||||||
|
artifactExchangeScope.done()
|
||||||
|
createDeploymentScope.done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('#check', () => {
|
describe('#check', () => {
|
||||||
afterEach(() => {
|
|
||||||
nock.cleanAll()
|
|
||||||
})
|
|
||||||
|
|
||||||
it('sets output to success when deployment is successful', async () => {
|
it('sets output to success when deployment is successful', async () => {
|
||||||
process.env.GITHUB_SHA = 'valid-build-version'
|
process.env.GITHUB_SHA = 'valid-build-version'
|
||||||
|
|
||||||
nock(`http://my-url`)
|
const artifactExchangeScope = nock(`http://my-url`)
|
||||||
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
||||||
.reply(200, {
|
.reply(200, {
|
||||||
value: [
|
value: [
|
||||||
@@ -293,7 +311,7 @@ describe('Deployment', () => {
|
|||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
nock('https://api.github.com')
|
const createDeploymentScope = nock('https://api.github.com')
|
||||||
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
||||||
artifact_url: 'https://fake-artifact.com&%24expand=SignedContent',
|
artifact_url: 'https://fake-artifact.com&%24expand=SignedContent',
|
||||||
pages_build_version: process.env.GITHUB_SHA,
|
pages_build_version: process.env.GITHUB_SHA,
|
||||||
@@ -304,8 +322,7 @@ describe('Deployment', () => {
|
|||||||
page_url: 'https://actions.github.io/is-awesome'
|
page_url: 'https://actions.github.io/is-awesome'
|
||||||
})
|
})
|
||||||
|
|
||||||
// for deployment status
|
const deploymentStatusScope = nock('https://api.github.com')
|
||||||
nock('https://api.github.com')
|
|
||||||
.get(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}`)
|
.get(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}`)
|
||||||
.reply(200, {
|
.reply(200, {
|
||||||
status: 'succeed'
|
status: 'succeed'
|
||||||
@@ -320,6 +337,10 @@ describe('Deployment', () => {
|
|||||||
|
|
||||||
expect(core.setOutput).toBeCalledWith('status', 'succeed')
|
expect(core.setOutput).toBeCalledWith('status', 'succeed')
|
||||||
expect(core.info).toHaveBeenLastCalledWith('Reported success!')
|
expect(core.info).toHaveBeenLastCalledWith('Reported success!')
|
||||||
|
|
||||||
|
artifactExchangeScope.done()
|
||||||
|
createDeploymentScope.done()
|
||||||
|
deploymentStatusScope.done()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('fails check when no deployment is found', async () => {
|
it('fails check when no deployment is found', async () => {
|
||||||
@@ -332,7 +353,7 @@ describe('Deployment', () => {
|
|||||||
it('exits early when deployment is not in progress', async () => {
|
it('exits early when deployment is not in progress', async () => {
|
||||||
process.env.GITHUB_SHA = 'valid-build-version'
|
process.env.GITHUB_SHA = 'valid-build-version'
|
||||||
|
|
||||||
nock(`http://my-url`)
|
const artifactExchangeScope = nock(`http://my-url`)
|
||||||
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
||||||
.reply(200, {
|
.reply(200, {
|
||||||
value: [
|
value: [
|
||||||
@@ -341,7 +362,7 @@ describe('Deployment', () => {
|
|||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
nock('https://api.github.com')
|
const createDeploymentScope = nock('https://api.github.com')
|
||||||
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
||||||
artifact_url: 'https://fake-artifact.com&%24expand=SignedContent',
|
artifact_url: 'https://fake-artifact.com&%24expand=SignedContent',
|
||||||
pages_build_version: process.env.GITHUB_SHA,
|
pages_build_version: process.env.GITHUB_SHA,
|
||||||
@@ -359,12 +380,15 @@ describe('Deployment', () => {
|
|||||||
deployment.deploymentInfo.pending = false
|
deployment.deploymentInfo.pending = false
|
||||||
await deployment.check()
|
await deployment.check()
|
||||||
expect(core.setFailed).toBeCalledWith('Unable to get deployment status.')
|
expect(core.setFailed).toBeCalledWith('Unable to get deployment status.')
|
||||||
|
|
||||||
|
artifactExchangeScope.done()
|
||||||
|
createDeploymentScope.done()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('enforces max timeout', async () => {
|
it('enforces max timeout', async () => {
|
||||||
process.env.GITHUB_SHA = 'valid-build-version'
|
process.env.GITHUB_SHA = 'valid-build-version'
|
||||||
|
|
||||||
nock(`http://my-url`)
|
const artifactExchangeScope = nock(`http://my-url`)
|
||||||
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
||||||
.reply(200, {
|
.reply(200, {
|
||||||
value: [
|
value: [
|
||||||
@@ -373,7 +397,7 @@ describe('Deployment', () => {
|
|||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
nock('https://api.github.com')
|
const createDeploymentScope = nock('https://api.github.com')
|
||||||
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
||||||
artifact_url: 'https://fake-artifact.com&%24expand=SignedContent',
|
artifact_url: 'https://fake-artifact.com&%24expand=SignedContent',
|
||||||
pages_build_version: process.env.GITHUB_SHA,
|
pages_build_version: process.env.GITHUB_SHA,
|
||||||
@@ -384,15 +408,7 @@ describe('Deployment', () => {
|
|||||||
page_url: 'https://actions.github.io/is-awesome'
|
page_url: 'https://actions.github.io/is-awesome'
|
||||||
})
|
})
|
||||||
|
|
||||||
nock('https://api.github.com')
|
const cancelDeploymentScope = 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`)
|
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}/cancel`)
|
||||||
.reply(200, {})
|
.reply(200, {})
|
||||||
|
|
||||||
@@ -427,12 +443,16 @@ describe('Deployment', () => {
|
|||||||
expect(deployment.timeout).toEqual(maxTimeout)
|
expect(deployment.timeout).toEqual(maxTimeout)
|
||||||
expect(core.error).toBeCalledWith('Timeout reached, aborting!')
|
expect(core.error).toBeCalledWith('Timeout reached, aborting!')
|
||||||
expect(core.setFailed).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 () => {
|
it('sets timeout to user timeout if user timeout is less than max timeout', async () => {
|
||||||
process.env.GITHUB_SHA = 'valid-build-version'
|
process.env.GITHUB_SHA = 'valid-build-version'
|
||||||
|
|
||||||
nock(`http://my-url`)
|
const artifactExchangeScope = nock(`http://my-url`)
|
||||||
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
||||||
.reply(200, {
|
.reply(200, {
|
||||||
value: [
|
value: [
|
||||||
@@ -441,7 +461,7 @@ describe('Deployment', () => {
|
|||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
nock('https://api.github.com')
|
const createDeploymentScope = nock('https://api.github.com')
|
||||||
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
||||||
artifact_url: 'https://fake-artifact.com&%24expand=SignedContent',
|
artifact_url: 'https://fake-artifact.com&%24expand=SignedContent',
|
||||||
pages_build_version: process.env.GITHUB_SHA,
|
pages_build_version: process.env.GITHUB_SHA,
|
||||||
@@ -452,14 +472,7 @@ describe('Deployment', () => {
|
|||||||
page_url: 'https://actions.github.io/is-awesome'
|
page_url: 'https://actions.github.io/is-awesome'
|
||||||
})
|
})
|
||||||
|
|
||||||
nock('https://api.github.com')
|
const cancelDeploymentScope = 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`)
|
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}/cancel`)
|
||||||
.reply(200, {})
|
.reply(200, {})
|
||||||
|
|
||||||
@@ -494,12 +507,16 @@ describe('Deployment', () => {
|
|||||||
expect(deployment.timeout).toEqual(42)
|
expect(deployment.timeout).toEqual(42)
|
||||||
expect(core.error).toBeCalledWith('Timeout reached, aborting!')
|
expect(core.error).toBeCalledWith('Timeout reached, aborting!')
|
||||||
expect(core.setFailed).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 () => {
|
it('sets output to success when timeout is set but not reached', async () => {
|
||||||
process.env.GITHUB_SHA = 'valid-build-version'
|
process.env.GITHUB_SHA = 'valid-build-version'
|
||||||
|
|
||||||
nock(`http://my-url`)
|
const artifactExchangeScope = nock(`http://my-url`)
|
||||||
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
||||||
.reply(200, {
|
.reply(200, {
|
||||||
value: [
|
value: [
|
||||||
@@ -508,7 +525,7 @@ describe('Deployment', () => {
|
|||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
nock('https://api.github.com')
|
const createDeploymentScope = nock('https://api.github.com')
|
||||||
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
||||||
artifact_url: 'https://fake-artifact.com&%24expand=SignedContent',
|
artifact_url: 'https://fake-artifact.com&%24expand=SignedContent',
|
||||||
pages_build_version: process.env.GITHUB_SHA,
|
pages_build_version: process.env.GITHUB_SHA,
|
||||||
@@ -519,7 +536,7 @@ describe('Deployment', () => {
|
|||||||
page_url: 'https://actions.github.io/is-awesome'
|
page_url: 'https://actions.github.io/is-awesome'
|
||||||
})
|
})
|
||||||
|
|
||||||
nock('https://api.github.com')
|
const deploymentStatusScope = nock('https://api.github.com')
|
||||||
.get(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}`)
|
.get(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}`)
|
||||||
.reply(200, {
|
.reply(200, {
|
||||||
status: 'succeed'
|
status: 'succeed'
|
||||||
@@ -557,18 +574,18 @@ describe('Deployment', () => {
|
|||||||
expect(core.error).not.toBeCalled()
|
expect(core.error).not.toBeCalled()
|
||||||
expect(core.setOutput).toBeCalledWith('status', 'succeed')
|
expect(core.setOutput).toBeCalledWith('status', 'succeed')
|
||||||
expect(core.info).toHaveBeenLastCalledWith('Reported success!')
|
expect(core.info).toHaveBeenLastCalledWith('Reported success!')
|
||||||
|
|
||||||
|
artifactExchangeScope.done()
|
||||||
|
createDeploymentScope.done()
|
||||||
|
deploymentStatusScope.done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('#cancel', () => {
|
describe('#cancel', () => {
|
||||||
afterEach(() => {
|
|
||||||
nock.cleanAll()
|
|
||||||
})
|
|
||||||
|
|
||||||
it('can successfully cancel a deployment', async () => {
|
it('can successfully cancel a deployment', async () => {
|
||||||
process.env.GITHUB_SHA = 'valid-build-version'
|
process.env.GITHUB_SHA = 'valid-build-version'
|
||||||
|
|
||||||
nock(`http://my-url`)
|
const artifactExchangeScope = nock(`http://my-url`)
|
||||||
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
||||||
.reply(200, {
|
.reply(200, {
|
||||||
value: [
|
value: [
|
||||||
@@ -577,7 +594,7 @@ describe('Deployment', () => {
|
|||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
nock('https://api.github.com')
|
const createDeploymentScope = nock('https://api.github.com')
|
||||||
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
||||||
artifact_url: 'https://fake-artifact.com&%24expand=SignedContent',
|
artifact_url: 'https://fake-artifact.com&%24expand=SignedContent',
|
||||||
pages_build_version: process.env.GITHUB_SHA,
|
pages_build_version: process.env.GITHUB_SHA,
|
||||||
@@ -588,7 +605,7 @@ describe('Deployment', () => {
|
|||||||
page_url: 'https://actions.github.io/is-awesome'
|
page_url: 'https://actions.github.io/is-awesome'
|
||||||
})
|
})
|
||||||
|
|
||||||
nock('https://api.github.com')
|
const cancelDeploymentScope = nock('https://api.github.com')
|
||||||
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}/cancel`)
|
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}/cancel`)
|
||||||
.reply(200, {})
|
.reply(200, {})
|
||||||
|
|
||||||
@@ -602,6 +619,10 @@ describe('Deployment', () => {
|
|||||||
await deployment.cancel()
|
await deployment.cancel()
|
||||||
|
|
||||||
expect(core.info).toHaveBeenLastCalledWith(`Canceled deployment with ID ${process.env.GITHUB_SHA}`)
|
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 () => {
|
it('can exit if a pages deployment was not created and none need to be cancelled', async () => {
|
||||||
@@ -620,7 +641,7 @@ describe('Deployment', () => {
|
|||||||
it('catches an error when trying to cancel a deployment', async () => {
|
it('catches an error when trying to cancel a deployment', async () => {
|
||||||
process.env.GITHUB_SHA = 'valid-build-version'
|
process.env.GITHUB_SHA = 'valid-build-version'
|
||||||
|
|
||||||
nock(`http://my-url`)
|
const artifactExchangeScope = nock(`http://my-url`)
|
||||||
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
||||||
.reply(200, {
|
.reply(200, {
|
||||||
value: [
|
value: [
|
||||||
@@ -629,7 +650,7 @@ describe('Deployment', () => {
|
|||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
nock('https://api.github.com')
|
const createDeploymentScope = nock('https://api.github.com')
|
||||||
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, {
|
||||||
artifact_url: 'https://fake-artifact.com&%24expand=SignedContent',
|
artifact_url: 'https://fake-artifact.com&%24expand=SignedContent',
|
||||||
pages_build_version: process.env.GITHUB_SHA,
|
pages_build_version: process.env.GITHUB_SHA,
|
||||||
@@ -641,7 +662,7 @@ describe('Deployment', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// nock will throw an error every time it tries to cancel the deployment
|
// nock will throw an error every time it tries to cancel the deployment
|
||||||
nock('https://api.github.com')
|
const cancelDeploymentScope = nock('https://api.github.com')
|
||||||
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}/cancel`)
|
.post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}/cancel`)
|
||||||
.reply(500, {})
|
.reply(500, {})
|
||||||
|
|
||||||
@@ -655,6 +676,10 @@ describe('Deployment', () => {
|
|||||||
await deployment.cancel()
|
await deployment.cancel()
|
||||||
|
|
||||||
expect(core.error).toHaveBeenCalledWith(`Canceling Pages deployment failed`, expect.anything())
|
expect(core.error).toHaveBeenCalledWith(`Canceling Pages deployment failed`, expect.anything())
|
||||||
|
|
||||||
|
artifactExchangeScope.done()
|
||||||
|
createDeploymentScope.done()
|
||||||
|
cancelDeploymentScope.done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -143,6 +143,16 @@ class Deployment {
|
|||||||
|
|
||||||
/*eslint no-constant-condition: ["error", { "checkLoops": false }]*/
|
/*eslint no-constant-condition: ["error", { "checkLoops": false }]*/
|
||||||
while (true) {
|
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
|
// Handle reporting interval
|
||||||
await new Promise(resolve => setTimeout(resolve, reportingInterval + errorReportingInterval))
|
await new Promise(resolve => setTimeout(resolve, reportingInterval + errorReportingInterval))
|
||||||
|
|
||||||
@@ -191,7 +201,7 @@ class Deployment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (errorCount > maxErrorCount) {
|
if (errorCount >= maxErrorCount) {
|
||||||
core.error('Too many errors, aborting!')
|
core.error('Too many errors, aborting!')
|
||||||
core.setFailed('Failed with status code: ' + errorStatus)
|
core.setFailed('Failed with status code: ' + errorStatus)
|
||||||
|
|
||||||
@@ -199,16 +209,6 @@ class Deployment {
|
|||||||
await this.cancel()
|
await this.cancel()
|
||||||
return
|
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