Files
upstream-tldraw/internal/scripts/deploy-bemo.ts
upstream-mirror a774ac673a
Some checks failed
Deploy analytics worker / Deploy analytics worker to ${{ (github.ref == 'refs/heads/production' && 'production') || (github.ref == 'refs/heads/main' && 'staging') || 'preview' }} (push) Failing after 1s
i18n upload strings / Upload latest strings (push) Failing after 1s
Deploy bemo / Deploy bemo to ${{ (github.ref == 'refs/heads/bemo-production' && 'production') || (github.ref == 'refs/heads/main' && 'staging') || 'preview' }} (push) Failing after 1s
Deploy grafana resources / ${{ github.event_name == 'push' && 'Deploy grafana resources' || 'Validate grafana resources (dry run)' }} (push) Failing after 0s
End to end tests (dotcom) / Check for relevant changes (push) Failing after 0s
End to end tests (examples) / Check for relevant changes (push) Failing after 0s
End to end tests (mermaid readability) / Check for relevant changes (push) Failing after 1s
End to end tests (perf) / Check for relevant changes (push) Failing after 0s
Publish editor extensions / Publish editor extensions (push) Failing after 1s
Publish SDK packages / Remove the publish-packages label (push) Has been skipped
Checks / Tests & checks (push) Has been cancelled
Checks / Build all projects (push) Has been cancelled
Deploy templates / Deploy templates (push) Has been cancelled
End to end tests (dotcom) / End to end tests (dotcom) (push) Has been cancelled
End to end tests (mermaid readability) / End to end tests (mermaid readability) (push) Has been cancelled
End to end tests (perf) / End to end tests (perf) (push) Has been cancelled
Deploy .com / Deploy dotcom to ${{ (github.ref == 'refs/heads/production' && 'production') || (github.ref == 'refs/heads/main' && 'staging') || 'preview' }} (push) Has been cancelled
End to end tests (examples) / End to end tests (examples) (push) Has been cancelled
Publish SDK packages / Publish SDK packages (push) Has been cancelled
Publish SDK packages / Tell user released version (push) Has been cancelled
Publish SDK packages / Publishes code templates to separate repositories (push) Has been cancelled
Publish SDK packages / Deploys the template demos with the new SDK version (push) Has been cancelled
snapshot of https://github.com/tldraw/tldraw.git (main, 2026-09-23; blobs > 131072B omitted)
2026-09-23 16:12:52 +05:00

124 lines
3.4 KiB
TypeScript

import assert from 'assert'
import { readFileSync } from 'fs'
import path, { join } from 'path'
import toml from 'toml'
import {
createGithubDeployment,
getDeployInfo,
setWranglerPreviewConfig,
wranglerDeploy,
} from './lib/deploy'
import { Discord } from './lib/discord'
import { exec } from './lib/exec'
import { REPO_ROOT } from './lib/file'
import { makeEnv } from './lib/makeEnv'
import { nicelog } from './lib/nicelog'
const workerDir = path.relative(process.cwd(), path.resolve(REPO_ROOT, './apps/bemo-worker'))
// Do not use `process.env` directly in this script. Add your variable to `makeEnv` and use it via
// `env` instead. This makes sure that all required env vars are present.
const env = makeEnv([
'CLOUDFLARE_ACCOUNT_ID',
'CLOUDFLARE_API_TOKEN',
'DISCORD_DEPLOY_WEBHOOK_URL',
'RELEASE_COMMIT_HASH',
'TLDRAW_ENV',
'GH_TOKEN',
'SENTRY_AUTH_TOKEN',
'SENTRY_BEMO_WORKER_DSN',
])
const discord = new Discord({
webhookUrl: env.DISCORD_DEPLOY_WEBHOOK_URL,
shouldNotify: env.TLDRAW_ENV === 'production',
totalSteps: 3,
secretValues: Object.values(env),
})
const { previewId, sha } = getDeployInfo()
async function main() {
assert(
env.TLDRAW_ENV === 'staging' || env.TLDRAW_ENV === 'production' || env.TLDRAW_ENV === 'preview',
'TLDRAW_ENV must be staging or production or preview'
)
await discord.message(`--- **${env.TLDRAW_ENV} bemo deploy pre-flight** ---`)
await discord.step('setting up deploy', async () => {
await exec('yarn', ['lazy', 'prebuild'])
})
await discord.step('cloudflare deploy dry run', async () => {
await deployBemoWorker({ dryRun: true })
})
// --- point of no return! do the deploy for real --- //
await discord.message(`--- **pre-flight complete, starting real bemo deploy** ---`)
// 2. deploy the cloudflare workers:
await discord.step('deploying bemo-worker to cloudflare', async () => {
await deployBemoWorker({ dryRun: false })
})
// the deploy hostname comes from the env's route pattern in wrangler.toml
const routePattern = toml.parse(readFileSync(join(workerDir, 'wrangler.toml')).toString())?.env[
env.TLDRAW_ENV
]?.routes?.[0]?.pattern
if (!routePattern) {
throw new Error('Could not find the route pattern in wrangler.toml')
}
// preview route patterns carry a path glob ("host/*"); the deployment URL wants just the host
const deploymentUrl = `https://${routePattern.split('/')[0]}`
nicelog('Creating deployment for', deploymentUrl)
await createGithubDeployment(env, {
app: 'bemo',
deploymentUrl,
sha,
})
await discord.message(`**Deploy complete!**`)
}
let didUpdateBemoWorker = false
async function deployBemoWorker({ dryRun }: { dryRun: boolean }) {
const workerId = `${previewId ?? env.TLDRAW_ENV}-bemo`
if (previewId && !didUpdateBemoWorker) {
await setWranglerPreviewConfig(workerDir, {
name: workerId,
routeHostname: `${previewId}-demo.tldraw.xyz`,
})
didUpdateBemoWorker = true
}
await wranglerDeploy({
location: workerDir,
dryRun,
env: env.TLDRAW_ENV,
vars: {
WORKER_NAME: workerId,
TLDRAW_ENV: env.TLDRAW_ENV,
SENTRY_DSN: env.SENTRY_BEMO_WORKER_DSN,
},
sentry: {
authToken: env.SENTRY_AUTH_TOKEN,
project: 'bemo-worker',
},
})
}
main().catch(async (err) => {
// don't notify discord on preview builds
if (env.TLDRAW_ENV !== 'preview') {
await discord.message(`${Discord.AT_TEAM_MENTION} Deploy failed: ${err.stack}`, {
always: true,
})
}
console.error(err)
process.exit(1)
})