mirror of
https://github.com/actions/deploy-pages.git
synced 2025-12-08 16:16:16 +00:00
Explicitly handle cancellation on errors
This commit is contained in:
63
dist/index.js
vendored
63
dist/index.js
vendored
@@ -8309,7 +8309,7 @@ class Deployment {
|
|||||||
const statusUrl =
|
const statusUrl =
|
||||||
this.deploymentInfo != null
|
this.deploymentInfo != null
|
||||||
? this.deploymentInfo['status_url']
|
? 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'] : '')
|
core.setOutput('page_url', this.deploymentInfo != null ? this.deploymentInfo['page_url'] : '')
|
||||||
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'))
|
||||||
@@ -8368,13 +8368,19 @@ class Deployment {
|
|||||||
if (errorCount >= maxErrorCount) {
|
if (errorCount >= maxErrorCount) {
|
||||||
core.info('Too many errors, aborting!')
|
core.info('Too many errors, aborting!')
|
||||||
core.setFailed('Failed with status code: ' + res.status)
|
core.setFailed('Failed with status code: ' + res.status)
|
||||||
break
|
|
||||||
|
// Explicitly cancel the deployment
|
||||||
|
await this.cancel()
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle timeout
|
// Handle timeout
|
||||||
if (Date.now() - startTime >= timeout) {
|
if (Date.now() - startTime >= timeout) {
|
||||||
core.info('Timeout reached, aborting!')
|
core.info('Timeout reached, aborting!')
|
||||||
core.setFailed('Timeout reached, aborting!')
|
core.setFailed('Timeout reached, aborting!')
|
||||||
|
|
||||||
|
// Explicitly cancel the deployment
|
||||||
|
await this.cancel()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8385,6 +8391,35 @@ 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 }
|
module.exports = { Deployment }
|
||||||
|
|
||||||
@@ -8624,34 +8659,12 @@ __nccwpck_require__(4307)
|
|||||||
|
|
||||||
const core = __nccwpck_require__(2186)
|
const core = __nccwpck_require__(2186)
|
||||||
// const github = require('@actions/github'); // TODO: Not used until we publish API endpoint to the @action/github package
|
// const github = require('@actions/github'); // TODO: Not used until we publish API endpoint to the @action/github package
|
||||||
const axios = __nccwpck_require__(6545)
|
|
||||||
|
|
||||||
const { Deployment } = __nccwpck_require__(2877)
|
const { Deployment } = __nccwpck_require__(2877)
|
||||||
const deployment = new Deployment()
|
const deployment = new Deployment()
|
||||||
|
|
||||||
// TODO: If the artifact hasn't been created, we can create it and upload to artifact storage ourselves
|
|
||||||
// const tar = require('tar')
|
|
||||||
|
|
||||||
async function cancelHandler(evtOrExitCodeOrError) {
|
async function cancelHandler(evtOrExitCodeOrError) {
|
||||||
try {
|
await deployment.cancel()
|
||||||
if (deployment.requestedDeployment) {
|
|
||||||
const pagesCancelDeployEndpoint = `${deployment.githubApiUrl}/repos/${process.env.GITHUB_REPOSITORY}/pages/deployment/cancel/${process.env.GITHUB_SHA}`
|
|
||||||
await axios.put(
|
|
||||||
pagesCancelDeployEndpoint,
|
|
||||||
{},
|
|
||||||
{
|
|
||||||
headers: {
|
|
||||||
Accept: 'application/vnd.github.v3+json',
|
|
||||||
Authorization: `Bearer ${deployment.githubToken}`,
|
|
||||||
'Content-type': 'application/json'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
core.info(`Deployment cancelled with ${pagesCancelDeployEndpoint}`)
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.log('Deployment cancellation failed', e)
|
|
||||||
}
|
|
||||||
process.exit(isNaN(+evtOrExitCodeOrError) ? 1 : +evtOrExitCodeOrError)
|
process.exit(isNaN(+evtOrExitCodeOrError) ? 1 : +evtOrExitCodeOrError)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
2
dist/index.js.map
vendored
2
dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
39
pre/index.js
39
pre/index.js
@@ -8309,7 +8309,7 @@ class Deployment {
|
|||||||
const statusUrl =
|
const statusUrl =
|
||||||
this.deploymentInfo != null
|
this.deploymentInfo != null
|
||||||
? this.deploymentInfo['status_url']
|
? 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'] : '')
|
core.setOutput('page_url', this.deploymentInfo != null ? this.deploymentInfo['page_url'] : '')
|
||||||
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'))
|
||||||
@@ -8368,13 +8368,19 @@ class Deployment {
|
|||||||
if (errorCount >= maxErrorCount) {
|
if (errorCount >= maxErrorCount) {
|
||||||
core.info('Too many errors, aborting!')
|
core.info('Too many errors, aborting!')
|
||||||
core.setFailed('Failed with status code: ' + res.status)
|
core.setFailed('Failed with status code: ' + res.status)
|
||||||
break
|
|
||||||
|
// Explicitly cancel the deployment
|
||||||
|
await this.cancel()
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle timeout
|
// Handle timeout
|
||||||
if (Date.now() - startTime >= timeout) {
|
if (Date.now() - startTime >= timeout) {
|
||||||
core.info('Timeout reached, aborting!')
|
core.info('Timeout reached, aborting!')
|
||||||
core.setFailed('Timeout reached, aborting!')
|
core.setFailed('Timeout reached, aborting!')
|
||||||
|
|
||||||
|
// Explicitly cancel the deployment
|
||||||
|
await this.cancel()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8385,6 +8391,35 @@ 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 }
|
module.exports = { Deployment }
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -109,7 +109,7 @@ class Deployment {
|
|||||||
const statusUrl =
|
const statusUrl =
|
||||||
this.deploymentInfo != null
|
this.deploymentInfo != null
|
||||||
? this.deploymentInfo['status_url']
|
? 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'] : '')
|
core.setOutput('page_url', this.deploymentInfo != null ? this.deploymentInfo['page_url'] : '')
|
||||||
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'))
|
||||||
@@ -168,13 +168,19 @@ class Deployment {
|
|||||||
if (errorCount >= maxErrorCount) {
|
if (errorCount >= maxErrorCount) {
|
||||||
core.info('Too many errors, aborting!')
|
core.info('Too many errors, aborting!')
|
||||||
core.setFailed('Failed with status code: ' + res.status)
|
core.setFailed('Failed with status code: ' + res.status)
|
||||||
break
|
|
||||||
|
// Explicitly cancel the deployment
|
||||||
|
await this.cancel()
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle timeout
|
// Handle timeout
|
||||||
if (Date.now() - startTime >= timeout) {
|
if (Date.now() - startTime >= timeout) {
|
||||||
core.info('Timeout reached, aborting!')
|
core.info('Timeout reached, aborting!')
|
||||||
core.setFailed('Timeout reached, aborting!')
|
core.setFailed('Timeout reached, aborting!')
|
||||||
|
|
||||||
|
// Explicitly cancel the deployment
|
||||||
|
await this.cancel()
|
||||||
return
|
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 }
|
module.exports = { Deployment }
|
||||||
|
|||||||
24
src/index.js
24
src/index.js
@@ -6,34 +6,12 @@ require('regenerator-runtime/runtime')
|
|||||||
|
|
||||||
const core = require('@actions/core')
|
const core = require('@actions/core')
|
||||||
// const github = require('@actions/github'); // TODO: Not used until we publish API endpoint to the @action/github package
|
// const github = require('@actions/github'); // TODO: Not used until we publish API endpoint to the @action/github package
|
||||||
const axios = require('axios')
|
|
||||||
|
|
||||||
const { Deployment } = require('./deployment')
|
const { Deployment } = require('./deployment')
|
||||||
const deployment = new Deployment()
|
const deployment = new Deployment()
|
||||||
|
|
||||||
// TODO: If the artifact hasn't been created, we can create it and upload to artifact storage ourselves
|
|
||||||
// const tar = require('tar')
|
|
||||||
|
|
||||||
async function cancelHandler(evtOrExitCodeOrError) {
|
async function cancelHandler(evtOrExitCodeOrError) {
|
||||||
try {
|
await deployment.cancel()
|
||||||
if (deployment.requestedDeployment) {
|
|
||||||
const pagesCancelDeployEndpoint = `${deployment.githubApiUrl}/repos/${process.env.GITHUB_REPOSITORY}/pages/deployment/cancel/${process.env.GITHUB_SHA}`
|
|
||||||
await axios.put(
|
|
||||||
pagesCancelDeployEndpoint,
|
|
||||||
{},
|
|
||||||
{
|
|
||||||
headers: {
|
|
||||||
Accept: 'application/vnd.github.v3+json',
|
|
||||||
Authorization: `Bearer ${deployment.githubToken}`,
|
|
||||||
'Content-type': 'application/json'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
core.info(`Deployment cancelled with ${pagesCancelDeployEndpoint}`)
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.log('Deployment cancellation failed', e)
|
|
||||||
}
|
|
||||||
process.exit(isNaN(+evtOrExitCodeOrError) ? 1 : +evtOrExitCodeOrError)
|
process.exit(isNaN(+evtOrExitCodeOrError) ? 1 : +evtOrExitCodeOrError)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user