name: TypeScript

on:
  push:
    branches: [main]
    paths:
      - "apps/**"
      - "lib/apps/fabro-spa/**"
      - "lib/packages/**"
      - "package.json"
      - "bun.lock"
      - ".gitattributes"
      - "scripts/**"
      - ".github/workflows/typescript.yml"
      - ".github/workflows/nightly.yml"
  pull_request:
    branches: [main]
    paths:
      - "apps/**"
      - "lib/apps/fabro-spa/**"
      - "lib/packages/**"
      - "package.json"
      - "bun.lock"
      - ".gitattributes"
      - "scripts/**"
      - ".github/workflows/typescript.yml"
      - ".github/workflows/nightly.yml"
  workflow_dispatch:

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

permissions: {}

jobs:
  typecheck:
    name: Typecheck
    runs-on: ubuntu-24.04-x86-32-cores
    permissions:
      contents: read
    steps:
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
        with:
          persist-credentials: false
      - uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
        with:
          bun-version: 1.3.14
      - run: bun install --frozen-lockfile
      - run: cd apps/fabro-web && bun run typecheck
      - run: cd lib/packages/fabro-api-client && bun run typecheck

  test:
    name: Test
    runs-on: ubuntu-24.04-x86-32-cores
    permissions:
      contents: read
    steps:
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
        with:
          persist-credentials: false
      - uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
        with:
          bun-version: 1.3.14
      - run: bun install --frozen-lockfile
      - run: cd apps/fabro-web && bun run test

  build:
    name: Build
    runs-on: ubuntu-24.04-x86-32-cores
    permissions:
      contents: read
    steps:
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
        with:
          persist-credentials: false
      - uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
        with:
          bun-version: 1.3.14
      - run: bun install --frozen-lockfile
      - uses: dtolnay/rust-toolchain@631a55b12751854ce901bb631d5902ceb48146f7 # stable
        with:
          toolchain: 1.97.1
      - run: cargo --locked dev build -- --locked -p fabro-cli --release
      - run: wc -c < target/release/fabro
