snapshot of https://github.com/tldraw/tldraw.git (main, 2026-09-23; blobs > 131072B omitted)
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
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
This commit is contained in:
110
internal/scripts/deploy-analytics.ts
Normal file
110
internal/scripts/deploy-analytics.ts
Normal file
@@ -0,0 +1,110 @@
|
||||
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 { 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/analytics-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',
|
||||
])
|
||||
|
||||
const discord = new Discord({
|
||||
webhookUrl: env.DISCORD_DEPLOY_WEBHOOK_URL,
|
||||
shouldNotify: env.TLDRAW_ENV === 'production',
|
||||
totalSteps: 2,
|
||||
messagePrefix: '[ANALYTICS]',
|
||||
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} analytics worker deploy pre-flight** ---`)
|
||||
|
||||
await discord.step('cloudflare deploy dry run', async () => {
|
||||
await deployAnalyticsWorker({ dryRun: true })
|
||||
})
|
||||
|
||||
// --- point of no return! do the deploy for real --- //
|
||||
|
||||
await discord.message(`--- **pre-flight complete, starting real analytics worker deploy** ---`)
|
||||
|
||||
await discord.step('deploying analytics worker to cloudflare', async () => {
|
||||
await deployAnalyticsWorker({ dryRun: false })
|
||||
})
|
||||
|
||||
// Get the worker name from wrangler.toml
|
||||
const wranglerConfig = toml.parse(readFileSync(join(workerDir, 'wrangler.toml')).toString())
|
||||
const workerName = wranglerConfig?.env?.[env.TLDRAW_ENV]?.name || wranglerConfig?.name
|
||||
if (!workerName) {
|
||||
throw new Error('Could not find worker name in wrangler.toml')
|
||||
}
|
||||
|
||||
// Analytics worker uses default workers.dev domain
|
||||
const deploymentUrl = `https://${workerName}.${env.CLOUDFLARE_ACCOUNT_ID}.workers.dev`
|
||||
|
||||
nicelog('Creating deployment for', deploymentUrl)
|
||||
await createGithubDeployment(env, {
|
||||
app: 'analytics-worker',
|
||||
deploymentUrl,
|
||||
sha,
|
||||
})
|
||||
|
||||
await discord.message(`**Deploy complete!**`)
|
||||
}
|
||||
|
||||
let didUpdateAnalyticsWorker = false
|
||||
async function deployAnalyticsWorker({ dryRun }: { dryRun: boolean }) {
|
||||
const workerId = `${previewId ?? env.TLDRAW_ENV}-tldraw-consent`
|
||||
if (previewId && !didUpdateAnalyticsWorker) {
|
||||
await setWranglerPreviewConfig(workerDir, {
|
||||
name: workerId,
|
||||
routeHostname: `${previewId}-consent.tldraw.xyz`,
|
||||
})
|
||||
didUpdateAnalyticsWorker = true
|
||||
}
|
||||
|
||||
await wranglerDeploy({
|
||||
location: workerDir,
|
||||
dryRun,
|
||||
env: env.TLDRAW_ENV,
|
||||
vars: {
|
||||
WORKER_NAME: workerId,
|
||||
TLDRAW_ENV: env.TLDRAW_ENV,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
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)
|
||||
})
|
||||
Reference in New Issue
Block a user