T
TanStack3mo ago
genetic-orange

Github workflow deploy

Does anyone know how to make a Github workflow for deploying to Cloudflare workers? I have followed this but I don't know how to make a proper CI/CD https://tanstack.com/start/latest/docs/framework/react/hosting#cloudflare-workers
Hosting | TanStack Start React Docs
Hosting is the process of deploying your application to the internet so that users can access it. This is a critical part of any web development project, ensuring your application is available to the...
1 Reply
genetic-orange
genetic-orangeOP3mo ago
I was able to successfully create a workflow file: .github/workflows/ci.yml
name: Deploy Worker

on:
push:
branches:
- develop
- main

jobs:
deploy:
runs-on: ubuntu-latest
timeout-minutes: 60
permissions:
contents: read
# Needed if your secrets are stored in different environments in Github
environment: ${{ github.ref == 'refs/heads/main' && 'production' || 'staging' }}

steps:
- uses: oven-sh/setup-bun@v2
with:
bun-version: latest

- name: Clone repository
uses: actions/checkout@v5
with:
# If you have submodules in your repo
submodules: recursive
token: ${{ secrets.PAT_TOKEN }}

- name: Install dependencies
run: bun install

- name: Build
run: bun run build

- name: Deploy
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
# "deploy --env" is for specifying builds with different domains
# See `wrangler.toml` [env.staging] and [env.production]
command: >-
deploy --env ${{ github.ref == 'refs/heads/main' && 'production' || 'staging' }}
name: Deploy Worker

on:
push:
branches:
- develop
- main

jobs:
deploy:
runs-on: ubuntu-latest
timeout-minutes: 60
permissions:
contents: read
# Needed if your secrets are stored in different environments in Github
environment: ${{ github.ref == 'refs/heads/main' && 'production' || 'staging' }}

steps:
- uses: oven-sh/setup-bun@v2
with:
bun-version: latest

- name: Clone repository
uses: actions/checkout@v5
with:
# If you have submodules in your repo
submodules: recursive
token: ${{ secrets.PAT_TOKEN }}

- name: Install dependencies
run: bun install

- name: Build
run: bun run build

- name: Deploy
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
# "deploy --env" is for specifying builds with different domains
# See `wrangler.toml` [env.staging] and [env.production]
command: >-
deploy --env ${{ github.ref == 'refs/heads/main' && 'production' || 'staging' }}
wrangler.toml for Tanstack Start projects
main = "./.output/server/index.mjs"
compatibility_date = "2025-09-16"
compatibility_flags = ["nodejs_compat"]

[assets]
binding = "ASSETS"
directory = "./.output/public"

[env.staging]
name = "my-app-staging"
vars = { NODE_ENV = "staging" }

[env.production]
name = "my-app-production"
vars = { NODE_ENV = "production" }
main = "./.output/server/index.mjs"
compatibility_date = "2025-09-16"
compatibility_flags = ["nodejs_compat"]

[assets]
binding = "ASSETS"
directory = "./.output/public"

[env.staging]
name = "my-app-staging"
vars = { NODE_ENV = "staging" }

[env.production]
name = "my-app-production"
vars = { NODE_ENV = "production" }

Did you find this page helpful?