name: Deploy

# Auto-build + deploy the Cloudflare Pages site and signaling Worker on push to
# main (the "git integration / auto build" for codehost.dev). Needs repo
# secrets CLOUDFLARE_API_TOKEN (Workers Scripts:Edit + Pages:Edit) and
# CLOUDFLARE_ACCOUNT_ID.
on:
  push:
    branches: [main]

concurrency:
  group: deploy
  cancel-in-progress: true

jobs:
  deploy:
    runs-on: ubuntu-latest
    env:
      CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
      CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
    steps:
      - uses: actions/checkout@v4
      - uses: oven-sh/setup-bun@v2
      - run: bun install
      - run: bun run build
      - name: Deploy Pages (app + service worker)
        run: bunx wrangler pages deploy dist/public --project-name codehost --branch main --commit-dirty=true
      - name: Deploy signaling Worker
        run: bunx wrangler deploy
        working-directory: worker
