name: Pull Request CI

on:
  pull_request:
    types: [opened, synchronize, reopened, ready_for_review]

permissions:
  contents: read

concurrency:
  group: pr-${{ github.event.pull_request.number }}-ci
  cancel-in-progress: true

env:
  CI: true

jobs:
  build-and-package:
    runs-on: ubuntu-latest
    # Skip for draft PRs; remove this line if you want to run on drafts too
    if: ${{ github.event.pull_request.draft == false }}

    steps:
      - name: Checkout code
        uses: actions/checkout@v4
      
      - name: Setup pnpm
        uses: pnpm/action-setup@v4
        with:
          version: latest

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: 22
          cache: pnpm
          cache-dependency-path: '**/pnpm-lock.yaml'

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

      - name: Run linter
        run: pnpm run lint

      - name: Check formatter
        run: pnpm run check

      - name: Run tests
        run: pnpm run test

      - name: Build web package
        run: pnpm --filter "./packages/web" run build
