name: CI

on:
  push:
    branches:
      - dev
  pull_request:
    branches:
      - dev

permissions:
  contents: read

jobs:
  build-web:
    name: Build Web
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Setup Node
        uses: actions/setup-node@v4
        with:
          node-version: 20

      - name: Setup pnpm
        uses: pnpm/action-setup@v4
        with:
          version: 10.27.0

      - name: Install dependencies
        run: pnpm install --frozen-lockfile

      - name: Build web
        run: pnpm --filter @different-ai/openwork-web build

  build-den:
    name: Build Den service
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Setup Node
        uses: actions/setup-node@v4
        with:
          node-version: 20

      - name: Setup pnpm
        uses: pnpm/action-setup@v4
        with:
          version: 10.27.0

      - name: Install dependencies
        run: pnpm install --frozen-lockfile

      - name: Build den service
        run: pnpm --filter @openwork/den build

  build-orchestrator-binary:
    name: Build openwork orchestrator binary
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Setup Node
        uses: actions/setup-node@v4
        with:
          node-version: 20

      - name: Setup pnpm
        uses: pnpm/action-setup@v4
        with:
          version: 10.27.0

      - name: Setup Bun
        uses: oven-sh/setup-bun@v1
        with:
          bun-version: 1.3.9

      - name: Install dependencies
        run: pnpm install --frozen-lockfile

      - name: Typecheck openwork-orchestrator
        run: pnpm --filter openwork-orchestrator typecheck

      - name: Build openwork orchestrator binary
        run: pnpm --filter openwork-orchestrator build:bin

      - name: Validate compiled binary
        run: |
          ./packages/orchestrator/dist/bin/openwork --version
          ./packages/orchestrator/dist/bin/openwork --help >/dev/null
