-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Explicitly handle cancellation on errors #56
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -109,7 +109,7 @@ class Deployment { | |
const statusUrl = | ||
this.deploymentInfo != null | ||
? this.deploymentInfo['status_url'] | ||
: `${this.githubApiUrl}/repos/${this.repositoryNwo}/pages/deployment/status/${process.env['GITHUB_SHA']}` | ||
: `${this.githubApiUrl}/repos/${this.repositoryNwo}/pages/deployment/status/${this.buildVersion}` | ||
core.setOutput('page_url', this.deploymentInfo != null ? this.deploymentInfo['page_url'] : '') | ||
const timeout = Number(core.getInput('timeout')) | ||
const reportingInterval = Number(core.getInput('reporting_interval')) | ||
|
@@ -168,13 +168,19 @@ class Deployment { | |
if (errorCount >= maxErrorCount) { | ||
core.info('Too many errors, aborting!') | ||
core.setFailed('Failed with status code: ' + res.status) | ||
break | ||
|
||
// Explicitly cancel the deployment | ||
await this.cancel() | ||
return | ||
Comment on lines
+173
to
+174
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is new and I think will not hurt. |
||
} | ||
|
||
// Handle timeout | ||
if (Date.now() - startTime >= timeout) { | ||
core.info('Timeout reached, aborting!') | ||
core.setFailed('Timeout reached, aborting!') | ||
|
||
// Explicitly cancel the deployment | ||
await this.cancel() | ||
return | ||
} | ||
} | ||
|
@@ -185,5 +191,34 @@ class Deployment { | |
} | ||
} | ||
} | ||
|
||
async cancel() { | ||
// Don't attemp to cancel if no deployment was created | ||
if (!this.requestedDeployment) { | ||
return | ||
} | ||
|
||
// Cancel the deployment | ||
try { | ||
const pagesCancelDeployEndpoint = `${this.githubApiUrl}/repos/${this.repositoryNwo}/pages/deployment/cancel/${this.buildVersion}` | ||
await axios.put( | ||
pagesCancelDeployEndpoint, | ||
{}, | ||
{ | ||
headers: { | ||
Accept: 'application/vnd.github.v3+json', | ||
Authorization: `Bearer ${this.githubToken}`, | ||
'Content-type': 'application/json' | ||
} | ||
} | ||
) | ||
core.info(`Deployment cancelled with ${pagesCancelDeployEndpoint}`) | ||
} catch (error) { | ||
core.setFailed(error) | ||
if (error.response && error.response.data) { | ||
core.info(JSON.stringify(error.response.data)) | ||
} | ||
} | ||
} | ||
} | ||
module.exports = { Deployment } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't use other environment variable in this file so normalizing to what's in the context. Did the same for
cancel
below.