mirror of
https://github.com/actions/deploy-pages.git
synced 2026-03-28 00:44:55 +00:00
Compare commits
5 Commits
v2.0.4
...
error-coun
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c7b5c1034e | ||
|
|
b4d15f6490 | ||
|
|
c883148031 | ||
|
|
b1a18fc1bd | ||
|
|
a378718509 |
@@ -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: 79.72%"><title>Coverage: 79.72%</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">79.72%</text><text x="885" y="140" transform="scale(.1)" fill="#fff" textLength="430">79.72%</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: 80.18%"><title>Coverage: 80.18%</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="#dfb317"/><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">80.18%</text><text x="885" y="140" transform="scale(.1)" fill="#fff" textLength="430">80.18%</text></g></svg>
|
||||
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
32
dist/index.js
generated
vendored
32
dist/index.js
generated
vendored
@@ -10080,21 +10080,32 @@ class Deployment {
|
||||
this.isPreview = context.isPreview === true
|
||||
this.timeout = MAX_TIMEOUT
|
||||
this.startTime = null
|
||||
this.maxErrorCount = null
|
||||
}
|
||||
|
||||
setOptionalUserInput() {
|
||||
const timeoutInput = Number(core.getInput('timeout'))
|
||||
if (timeoutInput > MAX_TIMEOUT) {
|
||||
core.warning(
|
||||
`Warning: timeout value is greater than the allowed maximum - timeout set to the maximum of ${MAX_TIMEOUT} milliseconds.`
|
||||
)
|
||||
}
|
||||
this.timeout = !timeoutInput || timeoutInput <= 0 ? MAX_TIMEOUT : Math.min(timeoutInput, MAX_TIMEOUT)
|
||||
|
||||
const maxErrorCountInput = Number(core.getInput('error_count'))
|
||||
if (!maxErrorCountInput || maxErrorCountInput <= 0) {
|
||||
core.warning('Invalid error_count value will be ignored. Please ensure the value is a positive integer.')
|
||||
} else {
|
||||
this.maxErrorCount = maxErrorCountInput
|
||||
}
|
||||
}
|
||||
|
||||
// Ask the runtime for the unsigned artifact URL and deploy to GitHub Pages
|
||||
// by creating a deployment with that artifact
|
||||
async create(idToken) {
|
||||
if (Number(core.getInput('timeout')) > MAX_TIMEOUT) {
|
||||
core.warning(
|
||||
`Warning: timeout value is greater than the allowed maximum - timeout set to the maximum of ${MAX_TIMEOUT} milliseconds.`
|
||||
)
|
||||
}
|
||||
|
||||
const timeoutInput = Number(core.getInput('timeout'))
|
||||
this.timeout = !timeoutInput || timeoutInput <= 0 ? MAX_TIMEOUT : Math.min(timeoutInput, MAX_TIMEOUT)
|
||||
|
||||
try {
|
||||
this.setOptionalUserInput()
|
||||
|
||||
core.debug(`Actor: ${this.buildActor}`)
|
||||
core.debug(`Action ID: ${this.actionsId}`)
|
||||
core.debug(`Actions Workflow Run ID: ${this.workflowRun}`)
|
||||
@@ -10180,7 +10191,6 @@ class Deployment {
|
||||
|
||||
const deploymentId = this.deploymentInfo.id || this.buildVersion
|
||||
const reportingInterval = Number(core.getInput('reporting_interval'))
|
||||
const maxErrorCount = Number(core.getInput('error_count'))
|
||||
|
||||
let errorCount = 0
|
||||
|
||||
@@ -10239,7 +10249,7 @@ class Deployment {
|
||||
}
|
||||
}
|
||||
|
||||
if (errorCount >= maxErrorCount) {
|
||||
if (errorCount >= this.maxErrorCount) {
|
||||
core.error('Too many errors, aborting!')
|
||||
core.setFailed('Failed with status code: ' + errorStatus)
|
||||
|
||||
|
||||
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
@@ -44,6 +44,101 @@ describe('Deployment', () => {
|
||||
jest.spyOn(core, 'debug').mockImplementation(jest.fn())
|
||||
})
|
||||
|
||||
describe('#setOptionalUserInput', () => {
|
||||
it('warns when the timeout is greater than the maximum allowed', async () => {
|
||||
jest.spyOn(core, 'getInput').mockImplementation(param => {
|
||||
switch (param) {
|
||||
case 'timeout':
|
||||
return MAX_TIMEOUT + 1
|
||||
default:
|
||||
return process.env[`INPUT_${param.toUpperCase()}`] || ''
|
||||
}
|
||||
})
|
||||
|
||||
const deployment = new Deployment()
|
||||
deployment.setOptionalUserInput()
|
||||
|
||||
expect(deployment.timeout).toBe(MAX_TIMEOUT)
|
||||
expect(core.warning).toBeCalledWith(
|
||||
`Warning: timeout value is greater than the allowed maximum - timeout set to the maximum of ${MAX_TIMEOUT} milliseconds.`
|
||||
)
|
||||
})
|
||||
|
||||
it('sets the error_count input when valid', async () => {
|
||||
jest.spyOn(core, 'getInput').mockImplementation(param => {
|
||||
switch (param) {
|
||||
case 'error_count':
|
||||
return '1'
|
||||
default:
|
||||
return process.env[`INPUT_${param.toUpperCase()}`] || ''
|
||||
}
|
||||
})
|
||||
|
||||
// Create the deployment
|
||||
const deployment = new Deployment()
|
||||
deployment.setOptionalUserInput()
|
||||
|
||||
expect(deployment.maxErrorCount).toBe(1)
|
||||
})
|
||||
|
||||
it('sets the error_count input to null if zero and warns user', async () => {
|
||||
jest.spyOn(core, 'getInput').mockImplementation(param => {
|
||||
switch (param) {
|
||||
case 'error_count':
|
||||
return '0'
|
||||
default:
|
||||
return process.env[`INPUT_${param.toUpperCase()}`] || ''
|
||||
}
|
||||
})
|
||||
|
||||
const deployment = new Deployment()
|
||||
deployment.setOptionalUserInput()
|
||||
|
||||
expect(deployment.maxErrorCount).toBe(null)
|
||||
expect(core.warning).toHaveBeenCalledWith(
|
||||
'Invalid error_count value will be ignored. Please ensure the value is a positive integer.'
|
||||
)
|
||||
})
|
||||
|
||||
it('sets the error_count input to null if negative and warns user', async () => {
|
||||
jest.spyOn(core, 'getInput').mockImplementation(param => {
|
||||
switch (param) {
|
||||
case 'error_count':
|
||||
return '-1'
|
||||
default:
|
||||
return process.env[`INPUT_${param.toUpperCase()}`] || ''
|
||||
}
|
||||
})
|
||||
|
||||
const deployment = new Deployment()
|
||||
deployment.setOptionalUserInput()
|
||||
|
||||
expect(deployment.maxErrorCount).toBe(null)
|
||||
expect(core.warning).toHaveBeenCalledWith(
|
||||
'Invalid error_count value will be ignored. Please ensure the value is a positive integer.'
|
||||
)
|
||||
})
|
||||
|
||||
it('sets the error_count input to null if not a number and warns user', async () => {
|
||||
jest.spyOn(core, 'getInput').mockImplementation(param => {
|
||||
switch (param) {
|
||||
case 'error_count':
|
||||
return 'not a number'
|
||||
default:
|
||||
return process.env[`INPUT_${param.toUpperCase()}`] || ''
|
||||
}
|
||||
})
|
||||
|
||||
const deployment = new Deployment()
|
||||
deployment.setOptionalUserInput()
|
||||
|
||||
expect(deployment.maxErrorCount).toBe(null)
|
||||
expect(core.warning).toHaveBeenCalledWith(
|
||||
'Invalid error_count value will be ignored. Please ensure the value is a positive integer.'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('#create', () => {
|
||||
afterEach(() => {
|
||||
// Remove mock for `core.getInput('preview')`
|
||||
@@ -88,6 +183,42 @@ describe('Deployment', () => {
|
||||
createDeploymentScope.done()
|
||||
})
|
||||
|
||||
it('invokes #setOptionalUserInput', async () => {
|
||||
process.env.GITHUB_SHA = 'valid-build-version'
|
||||
|
||||
const artifactExchangeScope = nock(`http://my-url`)
|
||||
.get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview')
|
||||
.reply(200, {
|
||||
value: [
|
||||
{ url: 'https://another-artifact.com', name: 'another-artifact' },
|
||||
{ url: 'https://fake-artifact.com', name: 'github-pages' }
|
||||
]
|
||||
})
|
||||
|
||||
const createDeploymentScope = 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,
|
||||
oidc_token: fakeJwt
|
||||
})
|
||||
.reply(200, {
|
||||
status_url: `https://api.github.com/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}`,
|
||||
page_url: 'https://actions.github.io/is-awesome'
|
||||
})
|
||||
|
||||
core.getIDToken = jest.fn().mockResolvedValue(fakeJwt)
|
||||
|
||||
// Create the deployment
|
||||
const deployment = new Deployment()
|
||||
deployment.setOptionalUserInput = jest.fn()
|
||||
await deployment.create(fakeJwt)
|
||||
|
||||
expect(deployment.setOptionalUserInput).toHaveBeenCalled()
|
||||
|
||||
artifactExchangeScope.done()
|
||||
createDeploymentScope.done()
|
||||
})
|
||||
|
||||
it('can successfully create a preview deployment', async () => {
|
||||
process.env.GITHUB_SHA = 'valid-build-version'
|
||||
|
||||
@@ -587,7 +718,6 @@ describe('Deployment', () => {
|
||||
|
||||
core.getIDToken = jest.fn().mockResolvedValue(fakeJwt)
|
||||
|
||||
// Set timeout to great than max
|
||||
jest.spyOn(core, 'getInput').mockImplementation(param => {
|
||||
switch (param) {
|
||||
case 'artifact_name':
|
||||
|
||||
@@ -45,21 +45,32 @@ class Deployment {
|
||||
this.isPreview = context.isPreview === true
|
||||
this.timeout = MAX_TIMEOUT
|
||||
this.startTime = null
|
||||
this.maxErrorCount = null
|
||||
}
|
||||
|
||||
setOptionalUserInput() {
|
||||
const timeoutInput = Number(core.getInput('timeout'))
|
||||
if (timeoutInput > MAX_TIMEOUT) {
|
||||
core.warning(
|
||||
`Warning: timeout value is greater than the allowed maximum - timeout set to the maximum of ${MAX_TIMEOUT} milliseconds.`
|
||||
)
|
||||
}
|
||||
this.timeout = !timeoutInput || timeoutInput <= 0 ? MAX_TIMEOUT : Math.min(timeoutInput, MAX_TIMEOUT)
|
||||
|
||||
const maxErrorCountInput = Number(core.getInput('error_count'))
|
||||
if (!maxErrorCountInput || maxErrorCountInput <= 0) {
|
||||
core.warning('Invalid error_count value will be ignored. Please ensure the value is a positive integer.')
|
||||
} else {
|
||||
this.maxErrorCount = maxErrorCountInput
|
||||
}
|
||||
}
|
||||
|
||||
// Ask the runtime for the unsigned artifact URL and deploy to GitHub Pages
|
||||
// by creating a deployment with that artifact
|
||||
async create(idToken) {
|
||||
if (Number(core.getInput('timeout')) > MAX_TIMEOUT) {
|
||||
core.warning(
|
||||
`Warning: timeout value is greater than the allowed maximum - timeout set to the maximum of ${MAX_TIMEOUT} milliseconds.`
|
||||
)
|
||||
}
|
||||
|
||||
const timeoutInput = Number(core.getInput('timeout'))
|
||||
this.timeout = !timeoutInput || timeoutInput <= 0 ? MAX_TIMEOUT : Math.min(timeoutInput, MAX_TIMEOUT)
|
||||
|
||||
try {
|
||||
this.setOptionalUserInput()
|
||||
|
||||
core.debug(`Actor: ${this.buildActor}`)
|
||||
core.debug(`Action ID: ${this.actionsId}`)
|
||||
core.debug(`Actions Workflow Run ID: ${this.workflowRun}`)
|
||||
@@ -145,7 +156,6 @@ class Deployment {
|
||||
|
||||
const deploymentId = this.deploymentInfo.id || this.buildVersion
|
||||
const reportingInterval = Number(core.getInput('reporting_interval'))
|
||||
const maxErrorCount = Number(core.getInput('error_count'))
|
||||
|
||||
let errorCount = 0
|
||||
|
||||
@@ -204,7 +214,7 @@ class Deployment {
|
||||
}
|
||||
}
|
||||
|
||||
if (errorCount >= maxErrorCount) {
|
||||
if (errorCount >= this.maxErrorCount) {
|
||||
core.error('Too many errors, aborting!')
|
||||
core.setFailed('Failed with status code: ' + errorStatus)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user