From 40e268905a025c593b5205de939e10031ff1e3ec Mon Sep 17 00:00:00 2001 From: Marcel Gerber Date: Tue, 17 Oct 2023 14:39:48 +0200 Subject: [PATCH] chore: remove netlify deploy code --- baker/DeployUtils.ts | 47 ++-------------------------- baker/Deployer.ts | 1 - baker/SiteBaker.tsx | 47 ---------------------------- baker/deploySiteFromStagingServer.ts | 4 --- 4 files changed, 3 insertions(+), 96 deletions(-) delete mode 100644 baker/deploySiteFromStagingServer.ts diff --git a/baker/DeployUtils.ts b/baker/DeployUtils.ts index 2bfc7102da7..ade88c94fea 100644 --- a/baker/DeployUtils.ts +++ b/baker/DeployUtils.ts @@ -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() @@ -31,7 +30,7 @@ const defaultCommitMessage = async (): Promise => { /** * Initiate a deploy, without any checks. Throws error on failure. */ -const bakeAndDeploy = async ( +const triggerBakeAndDeploy = async ( message?: string, lightningQueue?: DeployChange[] ) => { @@ -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) => { @@ -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() @@ -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 diff --git a/baker/Deployer.ts b/baker/Deployer.ts index 13c9431c577..0edca3cee53 100644 --- a/baker/Deployer.ts +++ b/baker/Deployer.ts @@ -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`, } diff --git a/baker/SiteBaker.tsx b/baker/SiteBaker.tsx index 56914ab94bc..3d8b598ef54 100644 --- a/baker/SiteBaker.tsx +++ b/baker/SiteBaker.tsx @@ -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() diff --git a/baker/deploySiteFromStagingServer.ts b/baker/deploySiteFromStagingServer.ts deleted file mode 100644 index 4e8b111ad4c..00000000000 --- a/baker/deploySiteFromStagingServer.ts +++ /dev/null @@ -1,4 +0,0 @@ -// todo: remove this file - -import { tryDeploy } from "../baker/DeployUtils.js" -tryDeploy()