Update Deployment class methods to enforce presence of this.deploymentInfo

This commit is contained in:
James M. Greene
2023-02-22 14:05:35 -06:00
parent cb00670952
commit 4d06ee6166
3 changed files with 35 additions and 31 deletions

32
dist/index.js vendored
View File

@@ -9852,7 +9852,17 @@ class Deployment {
// Poll the deployment endpoint for status // Poll the deployment endpoint for status
async check() { async check() {
const deploymentId = this.deploymentInfo?.id || this.buildVersion // Don't attempt to check status if no deployment was created
if (!this.deploymentInfo) {
core.setFailed(errorStatus.not_found)
return
}
if (this.deploymentInfo.pending !== true) {
core.setFailed(errorStatus.unknown_status)
return
}
const deploymentId = this.deploymentInfo.id || this.buildVersion
const timeout = Number(core.getInput('timeout')) const timeout = Number(core.getInput('timeout'))
const reportingInterval = Number(core.getInput('reporting_interval')) const reportingInterval = Number(core.getInput('reporting_interval'))
const maxErrorCount = Number(core.getInput('error_count')) const maxErrorCount = Number(core.getInput('error_count'))
@@ -9878,25 +9888,19 @@ class Deployment {
if (res.data.status === 'succeed') { if (res.data.status === 'succeed') {
core.info('Reported success!') core.info('Reported success!')
core.setOutput('status', 'succeed') core.setOutput('status', 'succeed')
if (this.deploymentInfo) { this.deploymentInfo.pending = false
this.deploymentInfo.pending = false
}
break break
} else if (res.data.status === 'deployment_failed') { } else if (res.data.status === 'deployment_failed') {
// Fall into permanent error, it may be caused by ongoing incident or malicious deployment content or exhausted automatic retry times. // Fall into permanent error, it may be caused by ongoing incident or malicious deployment content or exhausted automatic retry times.
core.setFailed('Deployment failed, try again later.') core.setFailed('Deployment failed, try again later.')
if (this.deploymentInfo) { this.deploymentInfo.pending = false
this.deploymentInfo.pending = false
}
break break
} else if (res.data.status === 'deployment_content_failed') { } else if (res.data.status === 'deployment_content_failed') {
// The uploaded artifact is invalid. // The uploaded artifact is invalid.
core.setFailed( core.setFailed(
'Artifact could not be deployed. Please ensure the content does not contain any hard links, symlinks and total size is less than 10GB.' 'Artifact could not be deployed. Please ensure the content does not contain any hard links, symlinks and total size is less than 10GB.'
) )
if (this.deploymentInfo) { this.deploymentInfo.pending = false
this.deploymentInfo.pending = false
}
break break
} else if (errorStatus[res.data.status]) { } else if (errorStatus[res.data.status]) {
// A temporary error happened, will query the status again // A temporary error happened, will query the status again
@@ -9946,22 +9950,20 @@ class Deployment {
async cancel() { async cancel() {
// Don't attempt to cancel if no deployment was created // Don't attempt to cancel if no deployment was created
if (!this.deploymentInfo?.pending) { if (!this.deploymentInfo || this.deploymentInfo.pending !== true) {
return return
} }
// Cancel the deployment // Cancel the deployment
try { try {
const deploymentId = this.deploymentInfo?.id || this.buildVersion const deploymentId = this.deploymentInfo.id || this.buildVersion
await cancelPagesDeployment({ await cancelPagesDeployment({
githubToken: this.githubToken, githubToken: this.githubToken,
deploymentId deploymentId
}) })
core.info(`Canceled deployment with ID ${deploymentId}`) core.info(`Canceled deployment with ID ${deploymentId}`)
if (this.deploymentInfo) { this.deploymentInfo.pending = false
this.deploymentInfo.pending = false
}
} catch (error) { } catch (error) {
core.setFailed(error) core.setFailed(error)
if (error.response?.data) { if (error.response?.data) {

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View File

@@ -99,7 +99,17 @@ class Deployment {
// Poll the deployment endpoint for status // Poll the deployment endpoint for status
async check() { async check() {
const deploymentId = this.deploymentInfo?.id || this.buildVersion // Don't attempt to check status if no deployment was created
if (!this.deploymentInfo) {
core.setFailed(errorStatus.not_found)
return
}
if (this.deploymentInfo.pending !== true) {
core.setFailed(errorStatus.unknown_status)
return
}
const deploymentId = this.deploymentInfo.id || this.buildVersion
const timeout = Number(core.getInput('timeout')) const timeout = Number(core.getInput('timeout'))
const reportingInterval = Number(core.getInput('reporting_interval')) const reportingInterval = Number(core.getInput('reporting_interval'))
const maxErrorCount = Number(core.getInput('error_count')) const maxErrorCount = Number(core.getInput('error_count'))
@@ -125,25 +135,19 @@ class Deployment {
if (res.data.status === 'succeed') { if (res.data.status === 'succeed') {
core.info('Reported success!') core.info('Reported success!')
core.setOutput('status', 'succeed') core.setOutput('status', 'succeed')
if (this.deploymentInfo) { this.deploymentInfo.pending = false
this.deploymentInfo.pending = false
}
break break
} else if (res.data.status === 'deployment_failed') { } else if (res.data.status === 'deployment_failed') {
// Fall into permanent error, it may be caused by ongoing incident or malicious deployment content or exhausted automatic retry times. // Fall into permanent error, it may be caused by ongoing incident or malicious deployment content or exhausted automatic retry times.
core.setFailed('Deployment failed, try again later.') core.setFailed('Deployment failed, try again later.')
if (this.deploymentInfo) { this.deploymentInfo.pending = false
this.deploymentInfo.pending = false
}
break break
} else if (res.data.status === 'deployment_content_failed') { } else if (res.data.status === 'deployment_content_failed') {
// The uploaded artifact is invalid. // The uploaded artifact is invalid.
core.setFailed( core.setFailed(
'Artifact could not be deployed. Please ensure the content does not contain any hard links, symlinks and total size is less than 10GB.' 'Artifact could not be deployed. Please ensure the content does not contain any hard links, symlinks and total size is less than 10GB.'
) )
if (this.deploymentInfo) { this.deploymentInfo.pending = false
this.deploymentInfo.pending = false
}
break break
} else if (errorStatus[res.data.status]) { } else if (errorStatus[res.data.status]) {
// A temporary error happened, will query the status again // A temporary error happened, will query the status again
@@ -193,22 +197,20 @@ class Deployment {
async cancel() { async cancel() {
// Don't attempt to cancel if no deployment was created // Don't attempt to cancel if no deployment was created
if (!this.deploymentInfo?.pending) { if (!this.deploymentInfo || this.deploymentInfo.pending !== true) {
return return
} }
// Cancel the deployment // Cancel the deployment
try { try {
const deploymentId = this.deploymentInfo?.id || this.buildVersion const deploymentId = this.deploymentInfo.id || this.buildVersion
await cancelPagesDeployment({ await cancelPagesDeployment({
githubToken: this.githubToken, githubToken: this.githubToken,
deploymentId deploymentId
}) })
core.info(`Canceled deployment with ID ${deploymentId}`) core.info(`Canceled deployment with ID ${deploymentId}`)
if (this.deploymentInfo) { this.deploymentInfo.pending = false
this.deploymentInfo.pending = false
}
} catch (error) { } catch (error) {
core.setFailed(error) core.setFailed(error)
if (error.response?.data) { if (error.response?.data) {