Skip to content

Commit

Permalink
chore: remove netlify deploy code
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelgerber committed Oct 17, 2023
1 parent f0de185 commit 40e2689
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 96 deletions.
47 changes: 3 additions & 44 deletions baker/DeployUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import {
BAKED_BASE_URL,
BUILDKITE_API_ACCESS_TOKEN,
} from "../settings/serverSettings.js"
import { DeployChange, OwidGdocPublished } from "@ourworldindata/utils"
import { Gdoc } from "../db/model/Gdoc/Gdoc.js"
import { DeployChange } from "@ourworldindata/utils"

const deployQueueServer = new DeployQueueServer()

Expand All @@ -31,7 +30,7 @@ const defaultCommitMessage = async (): Promise<string> => {
/**
* Initiate a deploy, without any checks. Throws error on failure.
*/
const bakeAndDeploy = async (
const triggerBakeAndDeploy = async (
message?: string,
lightningQueue?: DeployChange[]
) => {
Expand All @@ -53,25 +52,6 @@ const bakeAndDeploy = async (
buildkite.runFullBuild(message).catch(logErrorAndMaybeSendToBugsnag)
}
}

const baker = new SiteBaker(BAKED_SITE_DIR, BAKED_BASE_URL)
try {
if (lightningQueue?.length) {
for (const change of lightningQueue) {
const gdoc = (await Gdoc.findOneByOrFail({
published: true,
slug: change.slug,
})) as OwidGdocPublished
await baker.bakeGDocPost(gdoc)
}
} else {
await baker.bakeAll()
}
await baker.deployToNetlifyAndPushToGitPush(message)
} catch (err) {
logErrorAndMaybeSendToBugsnag(err)
throw err
}
}

export const bake = async (bakeSteps?: BakeStepConfig) => {
Expand All @@ -87,27 +67,6 @@ export const bake = async (bakeSteps?: BakeStepConfig) => {
}
}

/**
* Try to initiate a deploy and then terminate the baker, allowing a clean exit.
* Used in CLI.
*/
export const tryDeploy = async (
message?: string,
email?: string,
name?: string
) => {
message = message ?? (await defaultCommitMessage())
const baker = new SiteBaker(BAKED_SITE_DIR, BAKED_BASE_URL)

try {
await baker.deployToNetlifyAndPushToGitPush(message, email, name)
} catch (err) {
logErrorAndMaybeSendToBugsnag(err)
} finally {
baker.endDbConnections()
}
}

const generateCommitMsg = (queueItems: DeployChange[]) => {
const date: string = new Date().toISOString()

Expand Down Expand Up @@ -160,7 +119,7 @@ export const deployIfQueueIsNotEmpty = async () => {
const message = generateCommitMsg(parsedQueue)
console.log(`Deploying site...\n---\n${message}\n---`)
try {
await bakeAndDeploy(
await triggerBakeAndDeploy(
message,
// If every DeployChange is a lightning change, then we can do a
// lightning deploy. In the future, we might want to separate
Expand Down
1 change: 0 additions & 1 deletion baker/Deployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ yarn testPrettierAll`
restartAdminServer: `pm2 restart ${target}`,
stopDeployQueueServer: `pm2 stop ${target}-deploy-queue`,
bakeSiteOnStagingServer: `cd ${finalTargetDir} && node --enable-source-maps --unhandled-rejections=strict itsJustJavascript/baker/bakeSiteOnStagingServer.js ${cliBakeSteps}`,
deployToNetlify: `cd ${finalTargetDir} && node --enable-source-maps --unhandled-rejections=strict itsJustJavascript/baker/deploySiteFromStagingServer.js "${gitEmail}" "${gitName}"`,
restartQueue: `pm2 start ${target}-deploy-queue`,
}

Expand Down
47 changes: 0 additions & 47 deletions baker/SiteBaker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -705,53 +705,6 @@ export class SiteBaker {
console.log(msg || outPath)
}

private async execAndLogAnyErrorsToSlack(cmd: string) {
console.log(cmd)
try {
return await execWrapper(cmd)
} catch (error) {
// Log error to Bugsnag, but do not throw error
return logErrorAndMaybeSendToBugsnag(error)
}
}

async deployToNetlifyAndPushToGitPush(
commitMsg: string,
authorEmail?: string,
authorName?: string
) {
const progressBar = new ProgressBar(
"DeployToNetlify [:bar] :current/:total :elapseds :name\n",
{
total: 3,
}
)
progressBar.tick({ name: "✅ ready to deploy" })

// Ensure there is a git repo in there
await this.execAndLogAnyErrorsToSlack(
`cd ${this.bakedSiteDir} && git init`
)

progressBar.tick({ name: "✅ ensured git repo" })

// Prettify HTML source for easier debugging
// Target root level HTML files only (entries and posts) for performance
// reasons.
// TODO: check again --only-changed
// await this.execWrapper(`cd ${BAKED_SITE_DIR} && ${BASE_DIR}/node_modules/.bin/prettier --write "./*.html"`)

if (authorEmail && authorName && commitMsg)
await this.execAndLogAnyErrorsToSlack(
`cd ${this.bakedSiteDir} && git add -A . && git commit --allow-empty --author='${authorName} <${authorEmail}>' -a -m '${commitMsg}' && git push origin master`
)
else
await this.execAndLogAnyErrorsToSlack(
`cd ${this.bakedSiteDir} && git add -A . && git commit --allow-empty -a -m '${commitMsg}' && git push origin master`
)
progressBar.tick({ name: "✅ committed and pushed to github" })
}

endDbConnections() {
wpdb.singleton.end()
db.closeTypeOrmAndKnexConnections()
Expand Down
4 changes: 0 additions & 4 deletions baker/deploySiteFromStagingServer.ts

This file was deleted.

0 comments on commit 40e2689

Please sign in to comment.