Skip to content

Commit

Permalink
Announce if Heroku appears to be down (github#21762)
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesMGreene authored Sep 27, 2021
1 parent f2adc09 commit deab273
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 9 deletions.
15 changes: 11 additions & 4 deletions .github/workflows/prod-build-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,18 @@ jobs:
const Heroku = require('heroku-client')
const heroku = new Heroku({ token: process.env.HEROKU_API_TOKEN })
const { source_blob: sourceBlob } = await heroku.post('/sources')
const { put_url: uploadUrl, get_url: downloadUrl } = sourceBlob
try {
const { source_blob: sourceBlob } = await heroku.post('/sources')
const { put_url: uploadUrl, get_url: downloadUrl } = sourceBlob
core.setOutput('upload_url', uploadUrl)
core.setOutput('download_url', downloadUrl)
core.setOutput('upload_url', uploadUrl)
core.setOutput('download_url', downloadUrl)
} catch (error) {
if (error.statusCode === 503) {
console.error('💀 Heroku may be down! Please check its Status page: https://status.heroku.com/')
}
throw error
}
# See: https://devcenter.heroku.com/articles/build-and-release-using-the-api#sources-endpoint
- name: Upload to the Heroku build source
Expand Down
15 changes: 11 additions & 4 deletions .github/workflows/staging-deploy-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,18 @@ jobs:
const Heroku = require('heroku-client')
const heroku = new Heroku({ token: process.env.HEROKU_API_TOKEN })
const { source_blob: sourceBlob } = await heroku.post('/sources')
const { put_url: uploadUrl, get_url: downloadUrl } = sourceBlob
try {
const { source_blob: sourceBlob } = await heroku.post('/sources')
const { put_url: uploadUrl, get_url: downloadUrl } = sourceBlob
core.setOutput('upload_url', uploadUrl)
core.setOutput('download_url', downloadUrl)
core.setOutput('upload_url', uploadUrl)
core.setOutput('download_url', downloadUrl)
} catch (error) {
if (error.statusCode === 503) {
console.error('💀 Heroku may be down! Please check its Status page: https://status.heroku.com/')
}
throw error
}
# See: https://devcenter.heroku.com/articles/build-and-release-using-the-api#sources-endpoint
- name: Upload to the Heroku build source
Expand Down
12 changes: 11 additions & 1 deletion script/deployment/create-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ export default async function createApp(pullRequest) {

try {
await heroku.get(`/apps/${appName}`)
} catch (e) {
} catch (error) {
announceIfHerokuIsDown(error)
appExists = false
}

Expand All @@ -52,6 +53,7 @@ export default async function createApp(pullRequest) {

console.log('Heroku App created', newApp)
} catch (error) {
announceIfHerokuIsDown(error)
throw new Error(`Failed to create Heroku App ${appName}. Error: ${error}`)
}

Expand All @@ -68,6 +70,7 @@ export default async function createApp(pullRequest) {
console.log(`Added PR author @${author.login} as a Heroku app collaborator`)
}
} catch (error) {
announceIfHerokuIsDown(error)
// It's fine if this fails, it shouldn't block the app from deploying!
console.warn(`Warning: failed to add PR author as a Heroku app collaborator. Error: ${error}`)
}
Expand All @@ -82,8 +85,15 @@ export default async function createApp(pullRequest) {
body: appConfigVars,
})
} catch (error) {
announceIfHerokuIsDown(error)
throw new Error(`Failed to update Heroku app configuration variables. Error: ${error}`)
}

return appName
}

function announceIfHerokuIsDown(error) {
if (error && error.statusCode === 503) {
console.error('💀 Heroku may be down! Please check its Status page: https://status.heroku.com/')
}
}
12 changes: 12 additions & 0 deletions script/deployment/deploy-to-production.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export default async function deployToProduction({
body: appConfigVars,
})
} catch (error) {
announceIfHerokuIsDown(error)
throw new Error(`Failed to update Heroku app configuration variables. Error: ${error}`)
}

Expand All @@ -158,6 +159,7 @@ export default async function deployToProduction({
},
})
} catch (error) {
announceIfHerokuIsDown(error)
throw new Error(`Failed to create Heroku build. Error: ${error}`)
}

Expand All @@ -183,6 +185,7 @@ export default async function deployToProduction({
continue
}
}
announceIfHerokuIsDown(error)
throw new Error(`Failed to get build status. Error: ${error}`)
}

Expand Down Expand Up @@ -235,6 +238,7 @@ export default async function deployToProduction({
continue
}
}
announceIfHerokuIsDown(error)
throw new Error(`Failed to get release status. Error: ${error}`)
}

Expand Down Expand Up @@ -293,6 +297,7 @@ export default async function deployToProduction({
continue
}
}
announceIfHerokuIsDown(error)
throw new Error(`Failed to find dynos for this release. Error: ${error}`)
}
}
Expand Down Expand Up @@ -323,6 +328,7 @@ export default async function deployToProduction({
`Here are the last ${HEROKU_LOG_LINES_TO_SHOW} lines of the Heroku log:\n\n${logText}`
)
} catch (error) {
announceIfHerokuIsDown(error)
// Don't fail because of this error
console.error(`Failed to retrieve the Heroku logs for the crashed dynos. Error: ${error}`)
}
Expand Down Expand Up @@ -429,3 +435,9 @@ async function getTarballUrl({ octokit, owner, repo, sha }) {
})
return tarballUrl
}

function announceIfHerokuIsDown(error) {
if (error && error.statusCode === 503) {
console.error('💀 Heroku may be down! Please check its Status page: https://status.heroku.com/')
}
}
18 changes: 18 additions & 0 deletions script/deployment/deploy-to-staging.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ export default async function deployToStaging({
try {
await heroku.get(`/apps/${appName}`)
} catch (error) {
announceIfHerokuIsDown(error)
appExists = false
}

Expand All @@ -150,6 +151,7 @@ export default async function deployToStaging({

console.log(`Heroku app '${appName}' deleted for forced rebuild`)
} catch (error) {
announceIfHerokuIsDown(error)
throw new Error(
`Failed to delete Heroku app '${appName}' for forced rebuild. Error: ${error}`
)
Expand Down Expand Up @@ -201,6 +203,7 @@ export default async function deployToStaging({
// This probably will not be available yet
build = appSetup.build
} catch (error) {
announceIfHerokuIsDown(error)
throw new Error(`Failed to create Heroku app '${appName}'. Error: ${error}`)
}

Expand All @@ -217,6 +220,7 @@ export default async function deployToStaging({
console.log(`Added PR author @${author.login} as a Heroku app collaborator`)
}
} catch (error) {
announceIfHerokuIsDown(error)
// It's fine if this fails, it shouldn't block the app from deploying!
console.warn(
`Warning: failed to add PR author as a Heroku app collaborator. Error: ${error}`
Expand All @@ -239,6 +243,7 @@ export default async function deployToStaging({
continue
}
}
announceIfHerokuIsDown(error)
throw new Error(`Failed to get AppSetup status. Error: ${error}`)
}

Expand Down Expand Up @@ -278,6 +283,7 @@ See Heroku logs for more information:\n${logUrl}`
body: appConfigVars,
})
} catch (error) {
announceIfHerokuIsDown(error)
throw new Error(`Failed to update Heroku app configuration variables. Error: ${error}`)
}

Expand All @@ -293,6 +299,7 @@ See Heroku logs for more information:\n${logUrl}`
},
})
} catch (error) {
announceIfHerokuIsDown(error)
throw new Error(`Failed to create Heroku build. Error: ${error}`)
}

Expand All @@ -319,6 +326,7 @@ See Heroku logs for more information:\n${logUrl}`
continue
}
}
announceIfHerokuIsDown(error)
throw new Error(`Failed to get build status. Error: ${error}`)
}

Expand Down Expand Up @@ -371,6 +379,7 @@ See Heroku logs for more information:\n${logUrl}`
continue
}
}
announceIfHerokuIsDown(error)
throw new Error(`Failed to get release status. Error: ${error}`)
}

Expand Down Expand Up @@ -437,6 +446,7 @@ See Heroku logs for more information:\n${logUrl}`
try {
nextRelease = await heroku.get(`/apps/${appName}/releases/${release.version + 1}`)
} catch (error) {
announceIfHerokuIsDown(error)
throw new Error(
`Could not find a secondary release to explain the disappearing dynos. Error: ${error}`
)
Expand Down Expand Up @@ -475,6 +485,7 @@ See Heroku logs for more information:\n${logUrl}`
continue
}
}
announceIfHerokuIsDown(error)
throw new Error(`Failed to find dynos for this release. Error: ${error}`)
}
}
Expand Down Expand Up @@ -505,6 +516,7 @@ See Heroku logs for more information:\n${logUrl}`
`Here are the last ${HEROKU_LOG_LINES_TO_SHOW} lines of the Heroku log:\n\n${logText}`
)
} catch (error) {
announceIfHerokuIsDown(error)
// Don't fail because of this error
console.error(`Failed to retrieve the Heroku logs for the crashed dynos. Error: ${error}`)
}
Expand Down Expand Up @@ -632,3 +644,9 @@ async function getTarballUrl({ octokit, owner, repo, sha }) {
})
return tarballUrl
}

function announceIfHerokuIsDown(error) {
if (error && error.statusCode === 503) {
console.error('💀 Heroku may be down! Please check its Status page: https://status.heroku.com/')
}
}
8 changes: 8 additions & 0 deletions script/deployment/undeploy-from-staging.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export default async function undeployFromStaging({
try {
await heroku.get(`/apps/${appName}`)
} catch (error) {
announceIfHerokuIsDown(error)
appExists = false
}

Expand All @@ -52,6 +53,7 @@ export default async function undeployFromStaging({

console.log(`Heroku app '${appName}' deleted`)
} catch (error) {
announceIfHerokuIsDown(error)
throw new Error(`Failed to delete Heroku app '${appName}'. Error: ${error}`)
}
}
Expand Down Expand Up @@ -127,3 +129,9 @@ export default async function undeployFromStaging({
throw error
}
}

function announceIfHerokuIsDown(error) {
if (error && error.statusCode === 503) {
console.error('💀 Heroku may be down! Please check its Status page: https://status.heroku.com/')
}
}

0 comments on commit deab273

Please sign in to comment.