Skip to content
Source
Sign inSign up
TanStack/schemas
Open History to see the last commit

deploy.ts

46 lines1.9 KB

1// Deploy the Worker on every push to main. Replaces the Workers Builds
2// connection that died with the repo move (#553).
3//
4// Runs only as a protected run (main needs a branch rule that requires a
5// pull request) in the `production` CI environment. The forge holds
6// CLOUDFLARE_API_TOKEN outside the container; the job sees a placeholder.
7// The Worker's runtime secrets stay where they are (Doppler prd ->
8// `pnpm run secrets:push`); this job does not touch them.
9import { defineWorkflow, manual, push, setup } from '@tanstack-source/ci'
10​
11export default defineWorkflow('deploy', {
12 // manual(): deploy main again with no new commit (`src workflow run deploy`).
13 // A rerun cannot do it: it keeps the trust level of its first attempt.
14 on: [push({ branches: ['main'] }), manual()],
15}).job('deploy', {
16 environment: 'production',
17 secrets: { CLOUDFLARE_API_TOKEN: {} },
18 // Public config. `secrets:build` reads the two VITE_PUBLIC_* names from
19 // Doppler; wrangler reads CLOUDFLARE_ACCOUNT_ID.
20 vars: [
21 'CLOUDFLARE_ACCOUNT_ID',
22 'VITE_PUBLIC_POSTHOG_PROJECT_TOKEN',
23 'VITE_PUBLIC_POSTHOG_HOST',
24 ],
25 egress: [
26 'registry.npmjs.org',
27 'api.cloudflare.com',
28 'registry.cloudflare.com',
29 ],
30 timeoutMinutes: 20,
31 steps: [
32 {
33 // An unset variable is undefined, and a production build with no
34 // PostHog values turns analytics off without an error. The same
35 // check as scripts/build-with-secrets.ts.
36 name: 'Check variables',
37 run: 'for n in CLOUDFLARE_ACCOUNT_ID VITE_PUBLIC_POSTHOG_PROJECT_TOKEN VITE_PUBLIC_POSTHOG_HOST; do [ -n "$(printenv "$n")" ] || { echo "CI variable $n is not set (src variable set $n)" >&2; exit 1; }; done',
38 },
39 setup.node(),
40 setup.pnpm(),
41 { name: 'Install', run: 'pnpm install --frozen-lockfile' },
42 { name: 'Build', run: 'pnpm run build' },
43 // D1 migrations, then wrangler deploy.
44 { name: 'Deploy', run: 'pnpm run deploy:ci' },
45 ],
46})