enforce a max timeout

This commit is contained in:
Greta Parks
2023-05-11 18:39:06 +00:00
parent bacaae7379
commit 054faf7e6d
5 changed files with 229 additions and 26 deletions

28
dist/index.js generated vendored
View File

@@ -10041,6 +10041,8 @@ class Deployment {
this.githubServerUrl = context.githubServerUrl
this.artifactName = context.artifactName
this.isPreview = context.isPreview === true
this.timeout = maxTimeout
this.startTime = null
}
// Ask the runtime for the unsigned artifact URL and deploy to GitHub Pages
@@ -10052,6 +10054,9 @@ class Deployment {
)
}
let timeoutInput = Number(core.getInput('timeout'))
this.timeout = timeoutInput <= 0 ? maxTimeout : Math.min(timeoutInput, maxTimeout)
try {
core.debug(`Actor: ${this.buildActor}`)
core.debug(`Action ID: ${this.actionsId}`)
@@ -10077,6 +10082,7 @@ class Deployment {
id: deployment.id || deployment.status_url?.split('/')?.pop() || this.buildVersion,
pending: true
}
this.startTime = Date.now()
}
core.info(`Created deployment for ${this.buildVersion}, ID: ${this.deploymentInfo?.id}`)
@@ -10125,11 +10131,9 @@ class Deployment {
}
const deploymentId = this.deploymentInfo.id || this.buildVersion
const timeout = Number(core.getInput('timeout'))
const reportingInterval = Number(core.getInput('reporting_interval'))
const maxErrorCount = Number(core.getInput('error_count'))
let startTime = Date.now()
let errorCount = 0
// Time in milliseconds between two deployment status report when status errored, default 0.
@@ -10139,6 +10143,16 @@ 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))
@@ -10195,16 +10209,6 @@ class Deployment {
await this.cancel()
return
}
// Handle timeout
if (Date.now() - startTime >= 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

File diff suppressed because one or more lines are too long