name: Build

on:
  push:
    branches: [main, dev, media-scanner]
  pull_request:
    branches: [main, dev, media-scanner]

jobs:
  build:
    runs-on: ubuntu-latest
    if: ${{ !contains(github.event.head_commit.message, '[nobuild]') }}
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Use Latest Corepack
        run: |
          npm install -g corepack@latest
          corepack enable && corepack enable pnpm
          pnpm --version

      - name: Install Node.js
        uses: actions/setup-node@v4
        with:
          node-version: 22.13.0
          cache: 'pnpm'

      - name: Install dependencies
        run: pnpm install

      - name: Build server
        run: pnpm turbo typecheck --filter=@tunarr/server

      - name: Build web
        run: pnpm turbo build --filter=@tunarr/web

      - name: Run tests
        run: pnpm turbo test -- run
